Skip to content

fix(handler): add synthetic logger stacktrace#152

Open
hpouillot wants to merge 10 commits into
mainfrom
hp/synthetic-logger-stacktrace-main
Open

fix(handler): add synthetic logger stacktrace#152
hpouillot wants to merge 10 commits into
mainfrom
hp/synthetic-logger-stacktrace-main

Conversation

@hpouillot

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Plain Logger messages do not have exception stacktraces, but Logger metadata includes source location information. This adds a synthetic single-frame stacktrace from Logger metadata so error tracking can point plain log messages back to their file, line, and function.

💚 How did you test it?

  • mix test

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with pi/coding-agent assistance. The change reuses Logger event metadata (file, line, and mfa) to create a synthetic raw stacktrace frame only when a real exception stacktrace is absent, and keeps source context enrichment compatible with the current main branch.

@hpouillot hpouillot self-assigned this Jun 26, 2026
@hpouillot hpouillot requested review from a team, ablaszkiewicz and cat-ph June 26, 2026 15:55
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-06-26 17:32:10 UTC
Duration: 107374ms

⚠️ Some Tests Failed

42/45 tests passed, 3 failed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 609ms
Format Validation.Event Has Uuid 610ms
Format Validation.Event Has Lib Properties 610ms
Format Validation.Distinct Id Is String 610ms
Format Validation.Token Is Present 610ms
Format Validation.Custom Properties Preserved 610ms
Format Validation.Event Has Timestamp 610ms
Retry Behavior.Retries On 503 5615ms
Retry Behavior.Does Not Retry On 400 2613ms
Retry Behavior.Does Not Retry On 401 2612ms
Retry Behavior.Respects Retry After Header 5616ms
Retry Behavior.Implements Backoff 15626ms
Retry Behavior.Retries On 500 5616ms
Retry Behavior.Retries On 502 5611ms
Retry Behavior.Retries On 504 5616ms
Retry Behavior.Max Retries Respected 15626ms
Deduplication.Generates Unique Uuids 622ms
Deduplication.Preserves Uuid On Retry 5615ms
Deduplication.Preserves Uuid And Timestamp On Retry 10621ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5617ms
Deduplication.No Duplicate Events In Batch 615ms
Deduplication.Different Events Have Different Uuids 612ms
Compression.Sends Gzip When Enabled 610ms
Batch Format.Uses Proper Batch Structure 610ms
Batch Format.Flush With No Events Sends Nothing 607ms
Batch Format.Multiple Events Batched Together 615ms
Error Handling.Does Not Retry On 403 2612ms
Error Handling.Does Not Retry On 413 2612ms
Error Handling.Retries On 408 5611ms

Feature_Flags Tests

⚠️ 13/16 tests passed, 3 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 9ms
Request Payload.Flags Request Uses V2 Query Param 6ms
Request Payload.Flags Request Hits Flags Path Not Decide 7ms
Request Payload.Flags Request Omits Authorization Header 7ms
Request Payload.Token In Flags Body Matches Init 7ms
Request Payload.Groups Round Trip 6ms
Request Payload.Groups Default To Empty Object 7ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 6ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 7ms
Request Payload.Disable Geoip Omitted Defaults To False 7ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 6ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 609ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 11ms
Request Lifecycle.Mock Response Value Is Returned To Caller 7ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 610ms

Failures

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['groups', 'api_key', 'distinct_id', 'flag_keys_to_evaluate', 'group_properties', 'person_properties']

request_lifecycle.mock_response_value_is_returned_to_caller

Last action result missing field 'value'. Keys: ['error', 'success']

side_effect_events.get_feature_flag_captures_feature_flag_called_event

Expected 1 events with name '$feature_flag_called', got 0

@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "refactor(handler): use case for syntheti..." | Re-trigger Greptile

Comment thread lib/posthog/handler.ex Outdated
Comment thread test/posthog/handler_test.exs
Comment thread lib/posthog/handler.ex Outdated
Comment thread test/posthog/handler_test.exs Outdated
@hpouillot

Copy link
Copy Markdown
Contributor Author

Updated the code your suggestion @martosaur, thanks for the review !

@hpouillot hpouillot marked this pull request as ready for review June 26, 2026 17:26
@hpouillot hpouillot requested a review from a team as a code owner June 26, 2026 17:26
"$exception_list": [
%{
type: "Error with metadata",
type: "Logger.error",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to Logger.#{level} here, because the error message could be dynamic and cause undergrouping as we always use the exception type in fp.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, that's a whole different topic to be honest. Perhaps it's be best to keep this PR focused on synthetic stacktrace and not change error type logic here?

@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "fix(handler): avoid unused reporter help..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants