Skip to content

feat(error-tracking): add ambient trace IDs to exceptions - #228

Open
pauldambra wants to merge 1 commit into
mainfrom
posthog/exception-trace-context
Open

pauldambra wants to merge 1 commit 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 backend trace for an error captured by the Elixir Logger handler.

  • Add $trace_id and $span_id from a valid active OpenTelemetry span before the handler queues the exception.
  • Preserve leading zeros, unsampled spans, and caller properties. Missing or unreadable context still permits exception capture.
  • Keep OpenTelemetry as a test-only dependency. Document the behavior in the handler API documentation and add a minor release changeset.

This draft implements the proposed exception trace contract and waits for agreement there before merge.

💚 How did you test it?

  • Ran mix test, mix format --check-formatted, mix credo --strict, and mix posthog.public_api --check.
  • Added parameterized tests through Logger for real OpenTelemetry spans, context cleanup, invalid IDs, and atom or string property precedence.
  • Tested missing APIs, errors, throws, and exits in separate VMs to protect exception capture without changing the main VM.
  • Built a production consumer with warnings treated as errors. Built a local Hex package and checked that its metadata excludes OpenTelemetry.
  • Live API integration tests remain excluded by the repository default.

📝 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

Added .sampo/changesets/ambient-exception-trace-context.md directly using the documented Sampo format. The Sampo CLI is not installed.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Codex (gpt-6) used shell commands, Mix, Git, and the GitHub CLI. Skills: writing-tests, writing-code-comments, writing-user-facing-copy, and writing-pr-descriptions. 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
@github-actions

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-10-16T11:31:33.384636+00:00
Duration: 108643ms

⚠️ Some Tests Failed

40/47 tests passed, 7 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 610ms
Format Validation.Event Has Uuid ✅ 611ms
Format Validation.Event Has Lib Properties ✅ 611ms
Format Validation.Distinct Id Is String ✅ 611ms
Format Validation.Token Is Present ✅ 611ms
Format Validation.Custom Properties Preserved ✅ 611ms
Format Validation.Event Has Timestamp ✅ 611ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ❌ 610ms
Retry Behavior.Retries On 503 ✅ 5616ms
Retry Behavior.Does Not Retry On 400 ✅ 2614ms
Retry Behavior.Does Not Retry On 401 ✅ 2613ms
Retry Behavior.Respects Retry After Header ✅ 5616ms
Retry Behavior.Implements Backoff ✅ 15627ms
Retry Behavior.Retries On 500 ✅ 5616ms
Retry Behavior.Retries On 502 ✅ 5615ms
Retry Behavior.Retries On 504 ✅ 5617ms
Retry Behavior.Max Retries Respected ✅ 15627ms
Deduplication.Generates Unique Uuids ✅ 622ms
Deduplication.Preserves Uuid On Retry ✅ 5616ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10621ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5618ms
Deduplication.No Duplicate Events In Batch ✅ 616ms
Deduplication.Different Events Have Different Uuids ✅ 614ms
Compression.Sends Gzip When Enabled ✅ 611ms
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 ✅ 2614ms
Error Handling.Retries On 408 ✅ 5616ms

Failures

format_validation.non_utc_event_timestamp_is_converted_to_utc

Event 0 field 'timestamp' instant '2026-10-16T11:29:49.295141Z' != expected '2025-01-02T03:04:05Z'

Feature_Flags Tests

⚠️ 11/17 tests passed, 6 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 10ms
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 ✅ 6ms
Request Payload.Groups Round Trip ✅ 7ms
Request Payload.Groups Default To Empty Object ❌ 6ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 7ms
Request Payload.Disable Geoip Omitted Defaults To False ❌ 6ms
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 ✅ 608ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 12ms
Request Lifecycle.Mock Response Value Is Returned To Caller ❌ 7ms
Retry Behavior.Retries Flags On 502 ❌ 309ms
Retry Behavior.Retries Flags On 504 ❌ 311ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ❌ 611ms

Failures

request_payload.groups_default_to_empty_object

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

request_payload.disable_geoip_omitted_defaults_to_false

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

request_lifecycle.mock_response_value_is_returned_to_caller

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

retry_behavior.retries_flags_on_502

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

retry_behavior.retries_flags_on_504

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

@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

Copy link
Copy Markdown
Member Author

Note

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

Verdict: APPROVE (round 1 @ 9307250)

No actionable defect found in the exception trace change.

Key findings

The Logger entry path reads ambient context before capture. Caller and request trace properties keep priority, including atom and string keys. Valid unsampled spans retain fixed-width lowercase IDs. Missing or failing context does not stop exception capture.

Convergence

This round is dry. The simplify pass proposed no change. No review threads require action. The SDK spec agreement remains a merge hold.

Reviewer summaries

The independent router reviewed the full diff and surrounding merge paths. It reported low danger and high confidence, with no further delegation required.

The CI checks pass. Seven advisory compliance failures match documented adapter limits and flag response fixture differences. This review does not certify full SDK compliance.


Automated by QA Swarm - not a human review

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