Skip to content

otelhttptrace: fix header attributes lost when using sub-spans#8797

Open
imorte wants to merge 6 commits intoopen-telemetry:mainfrom
imorte:fix/otelhttptrace-header-attributes
Open

otelhttptrace: fix header attributes lost when using sub-spans#8797
imorte wants to merge 6 commits intoopen-telemetry:mainfrom
imorte:fix/otelhttptrace-header-attributes

Conversation

@imorte
Copy link
Copy Markdown

@imorte imorte commented Apr 10, 2026

When subspans are enabled (default), wroteHeaderField() writes header attributes to ct.root which points to the already ended http.getconn subspan. SetAttributes on an ended span is a silent noop, so all http.request.header.* attributes are quietly dropped.

This works correctly with WithoutSubSpans() because ct.root is set to the parent span from context, which is still active.

The fix sets ct.root to the parent span from context in both modes

@imorte imorte requested review from a team and dmathieu as code owners April 10, 2026 12:57
@imorte imorte force-pushed the fix/otelhttptrace-header-attributes branch from 981aa28 to 5c75af3 Compare April 11, 2026 13:39
@dmathieu
Copy link
Copy Markdown
Member

Could you add a changelog entry?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.5%. Comparing base (5288efd) to head (e6ac621).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8797   +/-   ##
=====================================
  Coverage   83.4%   83.5%           
=====================================
  Files        192     192           
  Lines      15639   15636    -3     
=====================================
+ Hits       13057   13065    +8     
+ Misses      2134    2123   -11     
  Partials     448     448           
Files with missing lines Coverage Δ
...on/net/http/httptrace/otelhttptrace/clienttrace.go 83.4% <100.0%> (-0.3%) ⬇️

... and 1 file with indirect coverage changes

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

@imorte
Copy link
Copy Markdown
Author

imorte commented Apr 13, 2026

Could you add a changelog entry?

done

@dmathieu
Copy link
Copy Markdown
Member

With this change, we set ct.root twice in tge same method, both with the span from context.
It seems like we could set it only once, at the start of the method?

@imorte
Copy link
Copy Markdown
Author

imorte commented Apr 14, 2026

With this change, we set ct.root twice in tge same method, both with the span from context. It seems like we could set it only once, at the start of the method?

fixed

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.

2 participants