Skip to content

feat(otel): add opt-in exception trace context - #374

Open
pauldambra wants to merge 2 commits into
mainfrom
posthog/exception-trace-context
Open

pauldambra wants to merge 2 commits into
mainfrom
posthog/exception-trace-context

Conversation

@pauldambra

Copy link
Copy Markdown
Member

[Robot] Draft prepared with Codex.

💡 Motivation and Context

Developers need to find the trace for a captured exception. Existing Go exception events do not identify the active span.

  • Add posthogotel.EnqueueWithContext to the existing optional OpenTelemetry module. It adds trace IDs only to exception messages.
  • Keep event and request-context properties ahead of derived IDs. Preserve unsampled spans, leading zeros, and capture after a failed lookup.
  • Copy event properties to prevent trace IDs from leaking when an exception is reused. Go keeps spans in context.Context, so callers pass that context.

This is an API proposal and an explicit integration. Existing core enqueue and automatic panic capture do not gain trace IDs. This draft does not claim automatic conformance with the proposed exception trace contract. It waits for API and contract agreement before merge.

💚 How did you test it?

  • Confirmed the new tests fail without the helper, then passed the table-driven tests through the real client's public BeforeSend hook.
  • Tested value and pointer messages, caller precedence, invalid or absent context, unreadable spans, reuse, nil inputs, and client errors.
  • Passed build, vet, and full race tests in the root and optional OpenTelemetry modules with Go 1.26.4.
  • Built, vetted, and ran the new tests against pinned released core v1.34.0 in a temporary copy without the local replacement.
  • Passed the core API snapshot, OpenTelemetry module tidy check, formatting, and diff checks. No dependency changes are required.

📝 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 pnpm changeset to generate a changeset file. Added a minor changeset directly; the release workflow tags nested modules from the root version.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Codex (gpt-6) used the shell, Go, Git, and the GitHub CLI. Skills used: writing-tests, writing-code-comments, writing-user-facing-copy, and writing-pr-descriptions. The helper uses the existing optional module to keep OpenTelemetry out of the core SDK. Human review is required.


Created with PostHog Desktop

Generated-By: PostHog Desktop
Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
@pauldambra pauldambra self-assigned this Oct 16, 2026

@posthog posthog Bot left a comment

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.

PostHog Review · Standard · reviewed 1e928fe: 1 Should fix.

This is the only automatic review while this pull request is a draft. Comment @posthog review to review new changes sooner. Otherwise, a review of the new changes runs when you mark it ready for review.

Comment thread otel/exception.go Outdated
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

posthog-go Compliance Report

Date: 2026-10-16 12:30:19 UTC
Duration: 168880ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

✅ 94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 16ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 4ms
Required Headers.Has Authorization Bearer Header ✅ 14ms
Required Headers.Has Content Type Json ✅ 4ms
Required Headers.Has Posthog Sdk Info Format ✅ 4ms
Required Headers.Has Posthog Attempt Header ✅ 4ms
Required Headers.Has Posthog Request Id ✅ 4ms
Required Headers.Has Posthog Request Timestamp ✅ 4ms
Required Headers.Has User Agent ✅ 14ms
Body Format.Body Has Created At And Batch ✅ 4ms
Body Format.No Api Key In Body ✅ 3ms
Body Format.No Sent At In Body ✅ 4ms
Event Format.Event Has Required Root Fields ✅ 4ms
Event Format.Event Uuid Is Valid ✅ 4ms
Event Format.Event Timestamp Is Rfc3339 ✅ 4ms
Event Format.Distinct Id Is String ✅ 4ms
Event Format.Distinct Id At Root Not Properties ✅ 4ms
Event Format.Custom Properties Preserved ✅ 4ms
Event Format.Set Properties Preserved ✅ 3ms
Event Format.Set Once Properties Preserved ✅ 14ms
Event Format.Groups Properties Preserved ✅ 4ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 4ms
Event Format.Event Has Required Root Fields Batch ✅ 5ms
Event Format.Event Uuid Is Valid Batch ✅ 6ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 5ms
Event Format.Distinct Id Is String Batch ✅ 5ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 6ms
Event Format.Custom Properties Preserved Batch ✅ 5ms
Event Format.Set Properties Preserved Batch ✅ 5ms
Event Format.Set Once Properties Preserved Batch ✅ 6ms
Event Format.Groups Properties Preserved Batch ✅ 5ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 5ms
Batch Behavior.Multiple Events In Single Batch ✅ 28ms
Batch Behavior.Batch Envelope Smoke ✅ 5ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 2ms
Batch Behavior.Flush At Triggers Batch ✅ 1006ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 5ms
Deduplication.Generates Unique Uuids ✅ 10ms
Deduplication.Different Events Same Content Different Uuids ✅ 5ms
Deduplication.Preserves Uuid On Retry ✅ 5135ms
Deduplication.Preserves Timestamp On Retry ✅ 5132ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5135ms
Deduplication.No Duplicate Events In Batch ✅ 29ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 4ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10138ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5134ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2012ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5134ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 6ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 26ms
Response Format Validation.Success No Retry After When All Ok ✅ 26ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 128ms
Response Format Validation.Success No Retry After When Drop Only ✅ 36ms
Response Format Validation.Response Echoes Request Id ✅ 6ms
Retry Behavior.Retries On 408 ✅ 5133ms
Retry Behavior.Retries On 500 ✅ 5134ms
Retry Behavior.Retries On 503 ✅ 5130ms
Retry Behavior.Retries On 504 ✅ 5134ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2131ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8135ms
Retry Behavior.Does Not Retry On 400 ✅ 2130ms
Retry Behavior.Does Not Retry On 401 ✅ 2131ms
Retry Behavior.Does Not Retry On 402 ✅ 2134ms
Retry Behavior.Does Not Retry On 413 ✅ 2131ms
Retry Behavior.Does Not Retry On 415 ✅ 2131ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2132ms
Retry Behavior.Implements Backoff ✅ 15133ms
Retry Behavior.Max Retries Respected ✅ 15142ms
Partial Batch Handling.Handles 200 Full Success ✅ 2008ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3028ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3032ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3030ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5132ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5135ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5133ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5134ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5133ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5134ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5133ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3028ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3031ms
Compression.Sends Gzip Content Encoding ✅ 6ms
Compression.No Content Encoding When Disabled ✅ 4ms
Compression.Compressed Body Is Decompressible ✅ 15ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2131ms
Event Options.Cookieless Mode Override ✅ 5ms
Event Options.Disable Skew Correction Override ✅ 4ms
Event Options.Process Person Profile Override ✅ 4ms
Event Options.Product Tour Id Override ✅ 15ms
Event Options.Unset Options Omitted ✅ 4ms
Event Options.Options Override In Batch ✅ 6ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 4ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 4ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 5ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 13ms
Request Payload.Flags Request Uses V2 Query Param ✅ 14ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 14ms
Request Payload.Flags Request Omits Authorization Header ✅ 14ms
Request Payload.Token In Flags Body Matches Init ✅ 15ms
Request Payload.Groups Round Trip ✅ 14ms
Request Payload.Groups Default To Empty Object ✅ 14ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 15ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 15ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 15ms
Request Lifecycle.No Flags Request On Init Alone ✅ 2ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 5ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 26ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 15ms
Retry Behavior.Retries Flags On 502 ✅ 16ms
Retry Behavior.Retries Flags On 504 ✅ 16ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 16ms

@pauldambra
pauldambra marked this pull request as ready for review October 16, 2026 11:58
@pauldambra
pauldambra requested a review from a team as a code owner October 16, 2026 11:58
@pauldambra

pauldambra commented Oct 16, 2026 •

Copy link
Copy Markdown
Member Author

Note

🤖 Automated comment by QA Swarm — not written by a human

Review: router passes, with a separate check of the public helper fix.

Verdict: ✅ APPROVE (round 2 @ 8c375c9)

No actionable findings remain in this review. The request trace override fault is fixed and has a regression test.

Key findings

  • The helper now keeps request trace values for clients that only implement Enqueue. Event properties still win.
  • The regression test failed before the fix and passes after it. Build, vet, and race tests pass for the optional module, including against released core v1.34.0.

Convergence

The first router pass confirmed the existing PostHog Review finding. The fix reply records the commit and test evidence.

Reviewer summaries

Reviewer Assessment
router, round 2 (gpt-6-sol) Low risk, high confidence. No new findings or further review needed.
API fix validator (gpt-6.1-sol) Accepted the narrow fix and test plan. This does not approve the proposed API or spec.
simplify (gpt-6-sol) No clear simplification. No files changed.

The API and proposed spec still need agreement before merge. This code review does not remove that hold.

Previous rounds (1)

round 1 @ 1e928fe - APPROVE WITH NITS: request trace overrides could be lost for enqueue-only clients; fixed in 8c375c9.


Automated by QA Swarm — not a human review

Generated-By: PostHog Desktop
Task-Id: 5681be44-4986-48db-b140-1bda88f75f96

This branch has not been deployed

No deployments
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.

2 participants