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

feat(node): Ensure tracing without performance (TWP) works #11564

Merged
merged 13 commits into from
Apr 15, 2024
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 11, 2024

This fixes the node SDK to make tracing without performance work as expected.

This has three aspects:

  1. Ensure we always have an url to check against tracePropagationTargets, even if the span is not sampled.
  2. Ensure we use the correct propagation context always
  3. Ensure we actually consistently handle ougoing http.client spans without an active transaction

The fix for 2. was to have a fallback behavior if we don't have a scope linked to a context yet (we'll just use the current scope then). This is needed because we won't necessarily have an assigned scope yet at the time this is called, because at this point in time this is still a floating context. This also meant removing the fallback code to look at the remote span context (because we'll always have a scope now).

The fix for 3. was to move this out of the http integration and do this in the sampler instead.

The fix for 1. was a bit more elaborate, because we require different things to solve the http instrumentation and the fetch instrumentation.

For fetch, we leverage our sampler, which can attach trace state that even unsampled spans will have. We attach the URL as trace state which we can read in the propagator, ensuring this works even for unsampled spans.

Sadly, for http this is not sufficient, because our usage of onlyIfParentForOutgoingRequest lead to some spans being created outside of the sampler. By removing this option (see 3) and doing stuff in the sampler instead, we can ensure that all spans for http are handled properly.

This also bumps our node-fetch otel instrumentation to 1.2.0 which fixes headers for Node 21 (tests were actually failing without this!).

@mydea mydea self-assigned this Apr 11, 2024
Copy link
Contributor

github-actions bot commented Apr 11, 2024

size-limit report 📦

Path Size
@sentry/browser 22.17 KB (0%)
@sentry/browser (incl. Tracing) 31.77 KB (0%)
@sentry/browser (incl. Tracing, Replay) 67.08 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 60.49 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 70.92 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) 80.81 KB (0%)
@sentry/browser (incl. Feedback) 35.73 KB (0%)
@sentry/browser (incl. Feedback, Feedback Modal) 35.73 KB (0%)
@sentry/browser (incl. Feedback, Feedback Modal, Feedback Screenshot) 37.75 KB (0%)
@sentry/browser (incl. sendFeedback) 26.97 KB (0%)
@sentry/react 24.85 KB (0%)
@sentry/react (incl. Tracing) 34.67 KB (0%)
@sentry/vue 25.74 KB (0%)
@sentry/vue (incl. Tracing) 33.48 KB (0%)
@sentry/svelte 22.3 KB (0%)
CDN Bundle 24.29 KB (0%)
CDN Bundle (incl. Tracing) 32.79 KB (0%)
CDN Bundle (incl. Tracing, Replay) 66.44 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 82.61 KB (0%)
CDN Bundle - uncompressed 72.37 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 98.42 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 208.08 KB (0%)
@sentry/nextjs (client) 34.03 KB (0%)
@sentry/sveltekit (client) 32.27 KB (0%)
@sentry/node 120.41 KB (+0.07% 🔺)

@mydea mydea marked this pull request as ready for review April 12, 2024 07:59
@mydea mydea requested review from lforst, Lms24, AbhiPrasad and s1gr1d April 12, 2024 10:19
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important tests.

To me, this change screams that we need to decouple our propagation logic from opentlemetry as it seem like OTEL is a bit incompatible with our concept for twp.

Comment on lines 94 to 98

const scopes = getCapturedScopesOnSpan(span);

const isolationScope = (scopes.isolationScope || getIsolationScope()).clone();
const scope = scopes.scope || getCurrentScope();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we moving this above the early return? As far as I can see it doesn't do anything right? (Also the "Update the isolation scope, isolate this request" comment is a bit orphanded now)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I moved stuff around multiple times here, will move it back down!

packages/node/src/integrations/http.ts Show resolved Hide resolved
@mydea mydea merged commit 832a7bf into develop Apr 15, 2024
95 checks passed
@mydea mydea deleted the fn/twp-node branch April 15, 2024 09:48
Lms24 added a commit that referenced this pull request Apr 17, 2024
…ario (#11636) (#11659)

For some reason, this commit (#11564) caused a conflict in our
master->develop sync. Let's fix this by cherry picking it onto master.
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.

3 participants