fix(instr-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used#4788
Conversation
a89e6b3 to
f14254a
Compare
f14254a to
658e198
Compare
|
ping to other reviewers @pichlermarc @JamieDanielson @dyladan @trentm |
|
I think it is correct that no span ( However, I'm not super-confident, so I was hoping to get review from some of the longer term reviewers. Should I can understand the desire to use |
|
Yeah, my use case is incrementally adding tracing to an existing service that gets a lot of traffic, and I want to be able to gradually increase the coverage of traces to decrease the risk of accidentally degrading prod performance from over-instrumentation. It has been a while since I made this change, so I forgot exactly what was happening, but I think we had I'm not sure whether |
|
@pichlermarc @JamieDanielson @dyladan @trentm could I get a review when you have time? Much appreciated :) |
|
@pichlermarc @JamieDanielson @dyladan @trentm would love to land this PR if possible |
I agree with this. I think what we're still trying to sort out is how we get into a state of an invalid span context here. @reberhardt7 Is there an issue with the client / is the client not behaving according to spec? Or is this somehow being set intentionally while rolling out the incremental instrumentation? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4788 +/- ##
=======================================
Coverage 95.06% 95.06%
=======================================
Files 307 307
Lines 8031 8031
Branches 1627 1627
=======================================
Hits 7635 7635
Misses 396 396 🚀 New features to boost your workflow:
|
|
Thank you for your contribution @reberhardt7! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |

Which problem is this PR solving?
The http instrumentation (and many other instrumentation libraries) create spans with INVALID_SPAN_CONTEXT to create NonRecordingSpans when we enable
requireParentand no parent is present: https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L769That works fine; those spans are not exported. However, when we create child spans, those end up becoming real spans that are exported. E.g. if we have an http server, when a request comes in, we create a span with INVALID_SPAN_CONTEXT, and then if the http request handler makes an outbound request, the instrumentation sees that it has a parent span (even though it is invalid) and creates a real child span, initiating a new trace.
The opentelemetry sdk creates new traces for descendants of INVALID_SPAN_CONTEXT:
opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/Tracer.ts
Line 91 in ecc88a3
Short description of the changes
This checks whether the parent span is recording, and does not create a real child span if the parent isn't recording.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Added unit test to verify fix
Checklist: