Skip to content

fix(tracing): background root spans overwrite native propagation context #6697

Description

@alwx

Problem

syncPropagationContextToNative (added in #6686) fires on every root span via the spanStart hook. Background/inactive roots created with startInactiveSpan({ forceTransaction: true }) — app-start in integrations/appStart.ts — also trigger a sync, overwriting the native scope with their traceId/spanId while a navigation root may already be active. When these background roots end, there is no restore, so in-flight native HTTP requests (OkHttp / URLSession) get attributed to the wrong trace.

A secondary issue: sampleRand is read from getCurrentScope().getPropagationContext() at sync time, which can be stale for these background roots since they don't update the propagation context before starting (unlike idle navigation spans).

Steps to reproduce

  1. App-start span fires mid-navigation
  2. Native HTTP request starts during the navigation transaction
  3. The request is linked to the app-start trace instead of the navigation trace

Expected

Background/inactive root spans should not overwrite the native propagation context when an active navigation trace is already set.

Possible fix

Move the sync out of the generic spanStart hook and into startIdleNavigationSpan directly, after the span is made active. This naturally excludes background roots without needing to filter by op or attributes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions