Skip to content

fix(handler): add synthetic logger stacktrace#152

Merged
hpouillot merged 12 commits into
mainfrom
hp/synthetic-logger-stacktrace-main
Jul 2, 2026
Merged

fix(handler): add synthetic logger stacktrace#152
hpouillot merged 12 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-07-02 08:45:44 UTC
Duration: 116440ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 610ms
Format Validation.Event Has Uuid 611ms
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 2613ms
Retry Behavior.Respects Retry After Header 5613ms
Retry Behavior.Implements Backoff 15625ms
Retry Behavior.Retries On 500 5612ms
Retry Behavior.Retries On 502 5615ms
Retry Behavior.Retries On 504 5610ms
Retry Behavior.Max Retries Respected 15624ms
Deduplication.Generates Unique Uuids 619ms
Deduplication.Preserves Uuid On Retry 5614ms
Deduplication.Preserves Uuid And Timestamp On Retry 10620ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5618ms
Deduplication.No Duplicate Events In Batch 616ms
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 2614ms
Error Handling.Does Not Retry On 413 2612ms
Error Handling.Retries On 408 5616ms

Feature_Flags Tests

16/16 tests passed

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

@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
Comment thread test/posthog/handler_test.exs Outdated
"$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?

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.

Sure, I don't mind splitting the PR. Just to understand, do you capture a lot of exception without crash_reason?

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.

Exceptions specifically usually have it, but error level logs usually don't, and they are pretty common

@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

@marandaneto

Copy link
Copy Markdown
Member

@PostHog/team-error-tracking should we get this merged?

@hpouillot hpouillot merged commit 742e3d8 into main Jul 2, 2026
28 checks passed
@hpouillot hpouillot deleted the hp/synthetic-logger-stacktrace-main branch July 2, 2026 08:45
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