Skip to content

Parse sentry-org_id from incoming baggage for transaction continuation #1200

Description

@szokeasaurusrex

Parse sentry-org_id from incoming baggage headers and store the parsed value on TransactionContext for later strict continuation decisions. This task should not enforce strict continuation yet and should not implement full Dynamic Sampling Context parsing or outgoing baggage propagation. This is part of #1016.

The goal is to make the incoming organization ID available to transaction creation while keeping the change behavior-neutral.

Implementation notes

Target file:

  • sentry-core/src/performance.rs

Implementation:

  • Add an internal parsed incoming trace metadata type, for example struct IncomingTrace { sentry_trace: SentryTrace, org_id: Option<OrganizationId> }.
  • Preserve public compatibility for parse_headers; either keep parse_headers returning Option<SentryTrace> and add a private parse_incoming_trace_headers, or add a distinct helper while leaving parse_headers unchanged.
  • Extend TransactionContext with an internal incoming_org_id: Option<OrganizationId> field.
  • Initialize incoming_org_id to None in constructors except continue_from_headers.
  • Update TransactionContext::continue_from_headers to parse both sentry-trace and baggage.
  • Parse baggage minimally:
    • scan comma-separated baggage members
    • trim whitespace around members
    • match only key sentry-org_id
    • parse the value as OrganizationId
    • treat malformed, empty, duplicate-unparseable, or absent values as None
  • Do not parse, preserve, or serialize any other DSC fields.

Tests:

  • baggage: sentry-org_id=123 is parsed.
  • Baggage with unrelated fields before or after sentry-org_id is parsed.
  • Mixed-case baggage header name is accepted.
  • Malformed org IDs are treated as absent.
  • No sentry-trace means the returned context starts a fresh trace and does not carry an incoming org ID.
  • Validate with cargo test -p sentry-core performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions