Skip to content

Read trace propagation behavior from tracer's config, not global singleton#11327

Closed
dougqh wants to merge 1 commit intomasterfrom
dougqh/coretracer-cache-extract-behavior
Closed

Read trace propagation behavior from tracer's config, not global singleton#11327
dougqh wants to merge 1 commit intomasterfrom
dougqh/coretracer-cache-extract-behavior

Conversation

@dougqh
Copy link
Copy Markdown
Contributor

@dougqh dougqh commented May 8, 2026

Summary

CoreSpanBuilder.startSpan reads Config.get().getTracePropagationBehaviorExtract() for every remote-parent span build. Tracers configured via withProperties(...) end up with an initialConfig distinct from the global Config.get() singleton, and on master the override is silently ignored — span behavior follows the singleton, not the tracer's configuration.

This patch switches that one call site to tracer.initialConfig.getTracePropagationBehaviorExtract(), matching the pattern already used elsewhere in this file (e.g. line 841 in the constructor, the ConfigSnapshot class, and the various flush* methods that read initialConfig). Marginal getfield savings on the hot path; the main benefit is correctness.

Test plan

  • New regression test CoreSpanBuilderTest.extractBehaviorReadsTracerConfigNotGlobalSingleton:
    • Builds a CoreTracer via tracerBuilder().withProperties(props).build() where props selects RESTART.
    • Asserts the precondition that customTracer.initialConfig reflects the override.
    • Builds a span with a remote ExtractedContext parent and asserts RESTART behavior (parent dropped, parent context attached as a link).
    • I verified the test fails on master (without the production change) — global Config.get() returns CONTINUE, the parent isn't dropped, and assertNotEquals(extractedContext.getTraceId(), span.getTraceId()) fails.
  • ./gradlew :dd-trace-core:test --tests 'datadog.trace.core.CoreSpanBuilderTest' passes.
  • ./gradlew :dd-trace-core:spotlessCheck passes.
  • CI matrix.

🤖 Generated with Claude Code

…leton

CoreSpanBuilder.startSpan was reading Config.get().getTracePropagationBehaviorExtract()
from the global Config singleton on every remote-parent span build. The tracer's own
configuration was already available via tracer.initialConfig, which is the consistent
source used elsewhere in this file (line 841, ConfigSnapshot, etc.).

Reading from the singleton has two consequences:

- Span behavior depends on whatever the global Config is at build time, not on the
  tracer's configured behavior. Tracers built via withProperties(...) get a different
  Config from the singleton, and on master the override is silently ignored.
- Extra getfield on a hot path. Marginal but unnecessary.

Switch to tracer.initialConfig and add a regression test that builds a CoreTracer
with a Properties override and verifies the resulting span reflects the override.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: bug Bug report and fix labels May 8, 2026
@dougqh
Copy link
Copy Markdown
Contributor Author

dougqh commented May 8, 2026

Another failed Claude experiment

@dougqh dougqh closed this May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant