Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(instr-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used #4788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reberhardt7
Copy link

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 requireParent and no parent is present: https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L769

That 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:

!api.trace.isSpanContextValid(parentSpanContext)

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added unit test to verify fix

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@reberhardt7 reberhardt7 requested a review from a team June 12, 2024 22:42
Copy link

linux-foundation-easycla bot commented Jun 12, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: reberhardt7 / name: Ryan Eberhardt (658e198)

@reberhardt7
Copy link
Author

I've signed the CLA, but it looks like the CLA bot hasn't updated yet. I'm hoping it'll update automatically in a few hours or something like that
Screenshot 2024-06-13 at 4 39 20 PM

@reberhardt7 reberhardt7 force-pushed the fix-http-requireparent branch 2 times, most recently from a89e6b3 to f14254a Compare June 14, 2024 01:38
package-lock.json Outdated Show resolved Hide resolved
@reberhardt7 reberhardt7 force-pushed the fix-http-requireparent branch from f14254a to 658e198 Compare June 20, 2024 18:14
@david-luna david-luna self-requested a review June 21, 2024 08:27
@david-luna
Copy link
Contributor

ping to other reviewers @pichlermarc @JamieDanielson @dyladan @trentm

@trentm
Copy link
Contributor

trentm commented Jun 25, 2024

I think it is correct that no span (trace.getSpan(ctx) === undefined) and an invalid span (api.trace.isSpanContextValid(trace.getSpan(ctx)) === false) should be treated as equivalent for requireParent config vars.

However, I'm not super-confident, so I was hoping to get review from some of the longer term reviewers.

Should suppressTracing, isTracingSuppressed (APIs from @opentelemetry/core) possibly fit in here for the presumed use case?

I can understand the desire to use requireParentforIncomingSpans=true to only get traces for "interesting" incoming requests to a service. (I'm guessing at the use case.)
This means that every instrumentation that can generate outgoing spans would need to have a requireParent config and the user would have it set it true for all of them, right?

@reberhardt7
Copy link
Author

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 requireParentforIncomingSpans=true in a few services that we only wanted to trace in the context of requests from another service.

I'm not sure whether isTracingSuppressed would fit in here. My guess is no, because we don't necessarily want to actively suppress any child spans that are created from this context, in case we legitimately want to start tracing later on.

@reberhardt7
Copy link
Author

@pichlermarc @JamieDanielson @dyladan @trentm could I get a review when you have time? Much appreciated :)

@reberhardt7
Copy link
Author

@pichlermarc @JamieDanielson @dyladan @trentm would love to land this PR if possible

@pichlermarc pichlermarc added bug Something isn't working pkg:instrumentation-http priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect labels Nov 21, 2024
@JamieDanielson
Copy link
Member

I think it is correct that no span (trace.getSpan(ctx) === undefined) and an invalid span (api.trace.isSpanContextValid(trace.getSpan(ctx)) === false) should be treated as equivalent for requireParent config vars.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:instrumentation-http priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants