Skip to content

Return null from TracerShim extract when the carrier has no span context#8505

Draft
thswlsqls wants to merge 1 commit into
open-telemetry:mainfrom
thswlsqls:fix/tracershim-extract-empty-carrier-null
Draft

Return null from TracerShim extract when the carrier has no span context#8505
thswlsqls wants to merge 1 commit into
open-telemetry:mainfrom
thswlsqls:fix/tracershim-extract-empty-carrier-null

Conversation

@thswlsqls

Copy link
Copy Markdown
Contributor

Fixes #4344

Description

  • Propagation.extractTextMap used Context.current() as the extract parent. A TextMapPropagator returns the input context unchanged when the carrier has no valid headers, so an empty-carrier extract with an active span returned that span as a non-null SpanContextShim.
  • This violates the OpenTracing Tracer#extract contract: with no serialized span state in the carrier, the result must be null.
  • Switching the parent to Context.root() makes extraction depend only on the carrier. A populated carrier decodes exactly as before; inject is left unchanged (preserving the current context there is intended).
  • The shim is deprecated but still published, so fixing this contract violation is still worthwhile.

Testing done

  • Added TracerShimTest#extract_emptyCarrier_withActiveSpan_returnsNull (fails before the change, passes after).
  • ./gradlew :opentracing-shim:check — 83 tests passed.
  • Added a ## Unreleased ### Shims entry in CHANGELOG.md. No public API change (apidiff unaffected; Propagation/TracerShim are package-private).

@thswlsqls thswlsqls force-pushed the fix/tracershim-extract-empty-carrier-null branch from 104cdd4 to 2c22bed Compare June 22, 2026 08:03
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.77%. Comparing base (824334c) to head (2c22bed).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8505   +/-   ##
=========================================
  Coverage     78.77%   78.77%           
  Complexity     8579     8579           
=========================================
  Files          1009     1009           
  Lines         28993    28993           
  Branches       3599     3599           
=========================================
  Hits          22839    22839           
  Misses         5311     5311           
  Partials        843      843           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

TracerShim#extract() returning current context instead of null in case of empty carrier

1 participant