SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is true

Offen
#9,062 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

@Eliot5566 arbeitet bereits daran.

Seit 26.11.2026.

  • #2 von @Eliot5566 — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
java

Rechercherichtung

Read SdkSpanBuilder.startSpan() around lines 201–215 and 258, then inspect CompositeSampler.shouldSample() around lines 50 and 95. Trace how an invalid parent SpanContext with a TraceState reaches the sampler when random trace IDs are enabled; the issue is done when the initial state remains observable to the sampler and is preserved in the resulting span. The issue cites related specification discussions in open-telemetry/opentelemetry-specification#5471 and #5472.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Bug SDK
Problem

In SdkSpanBuilder.startSpan(), when creating a root span (!parentSpanContext.isValid()) with a random IdGenerator (idGenerator.generatesRandomTraceIds() == true), parentContextForSampler replaces the Span in parentContext with RANDOM_TRACE_ID_PRIMORDIAL_SPAN, whose TraceState is TraceState.getDefault().

If a caller attaches an invalid SpanContext carrying initial TraceState (for example, ot=rv:... per Do not overwrite explicit randomness) to parentContext:

  • Sampler.shouldSample() cannot observe parentSpanContext.getTraceState() through parentContextForSampler (even though SdkSpanBuilder.java:258 passes parentSpanContext.getTraceState() to samplingResult.getUpdatedTraceState(...)).
  • CompositeSampler.shouldSample() reads traceState from parentContext (now empty) and reuses it in getUpdatedTraceState() (line 95), losing the caller's initial TraceState.

When idGenerator.generatesRandomTraceIds() is false, parentContextForSampler is left unchanged and the caller's TraceState is preserved.

Note: Upstream spec clarification on ShouldSample root TraceFlags and root-span TraceState is also tracked in open-telemetry/opentelemetry-specification#5471 and open-telemetry/opentelemetry-specification#5472.

Vorherrschende Sprache
Java
Sterne
2.5k
Forks
1.1k
Ø Merge
5 T. 11 Std.
Gemergte PRs (30 T.)
41

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus open-telemetry/opentelemetry-java

Alle Issues in open-telemetry/opentelemetry-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.