Skip to content

fix: fill OpenTelemetry trace IDs below context tags and super properties - #1122

Open
eli-r-ph wants to merge 1 commit into
v1from
v1-trace-ids-as-sdk-values
Open

eli-r-ph wants to merge 1 commit into
v1from
v1-trace-ids-as-sdk-values

Conversation

@eli-r-ph

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

On v1, the $trace_id and $span_id that the SDK takes from the active OpenTelemetry span are merged into the call's own properties, so they win over the same keys in context tags and super_properties. Across the v1 SDKs, a value the caller sets (on the event, in a context or globally) wins over a value the SDK adds. posthog-node and posthog-go already let caller and context trace IDs win over the active span's, and posthog-rs is moving to the same rule.

  • The span IDs now fill with the other values the SDK sets: after the call's properties, context tags and super_properties, before before_send.
  • The SDK adds both IDs or neither: if any layer sets $trace_id or $span_id, it adds neither, so an event never pairs one trace's ID with another span.
  • capture, capture_ai and capture_exception on Client, and AsyncPosthog, follow the rule. Client.capture_exception still always adds the span IDs.
  • The 8.0 migration guide and a changeset describe the change from 7.x (the span beat context tags there).

💚 How did you test it?

  • New wire tests (sync and async) with a real active OpenTelemetry span, over capture, capture_ai and capture_exception: both IDs added when no layer sets them; a call property, a context tag or a super property wins and stops both derived IDs; before_send sees the derived IDs and can change them. The caller, context and super cases fail without this change.
  • pytest posthog/test (5326 passed), ruff check, ruff format --check, mypy and make public_api_check pass locally.

📝 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)

Authored with Claude Code (Claude Opus 5.5), directed by @eli-r-ph.

🤖 Generated with Claude Code

…ties

The $trace_id and $span_id taken from the active OpenTelemetry span are
values the SDK adds, so they now fill after the call's properties,
context tags and super_properties, and before before_send. They fill as
a pair: when any layer sets either key, the SDK adds neither. This
covers capture, capture_ai and capture_exception on Client and
AsyncPosthog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eli-r-ph eli-r-ph self-assigned this Oct 24, 2026
@eli-r-ph
eli-r-ph marked this pull request as ready for review October 24, 2026 00:30
@eli-r-ph
eli-r-ph requested a review from a team as a code owner October 24, 2026 00:30

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.

1 participant