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!: Remove spanId from propagation context #14733

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 16, 2024

Closes #12385

This also deprecates getPropagationContextFromSpan as it is no longer used/needed. We may think about removing this in v9, but IMHO we can also just leave this for v9, it does not hurt too much to have it in there...

@mydea mydea self-assigned this Dec 16, 2024
Copy link
Contributor

github-actions bot commented Dec 16, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.21 KB -0.05% -11 B 🔽
@sentry/browser - with treeshaking flags 21.88 KB -0.05% -9 B 🔽
@sentry/browser (incl. Tracing) 35.71 KB -0.07% -24 B 🔽
@sentry/browser (incl. Tracing, Replay) 72.96 KB -0.04% -28 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 63.35 KB -0.04% -21 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 77.36 KB -0.04% -26 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 89.75 KB -0.03% -26 B 🔽
@sentry/browser (incl. Feedback) 39.97 KB -0.03% -11 B 🔽
@sentry/browser (incl. sendFeedback) 27.82 KB -0.04% -11 B 🔽
@sentry/browser (incl. FeedbackAsync) 32.6 KB -0.04% -11 B 🔽
@sentry/react 25.92 KB -0.03% -6 B 🔽
@sentry/react (incl. Tracing) 38.58 KB -0.04% -15 B 🔽
@sentry/vue 27.45 KB -0.04% -9 B 🔽
@sentry/vue (incl. Tracing) 37.58 KB -0.06% -23 B 🔽
@sentry/svelte 23.38 KB -0.05% -10 B 🔽
CDN Bundle 24.36 KB -0.09% -20 B 🔽
CDN Bundle (incl. Tracing) 37.42 KB -0.05% -17 B 🔽
CDN Bundle (incl. Tracing, Replay) 72.52 KB -0.04% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 77.89 KB -0.03% -21 B 🔽
CDN Bundle - uncompressed 71.56 KB -0.09% -59 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 110.92 KB -0.06% -65 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 224.97 KB -0.03% -65 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 238.19 KB -0.03% -65 B 🔽
@sentry/nextjs (client) 38.83 KB -0.04% -15 B 🔽
@sentry/sveltekit (client) 36.25 KB -0.06% -21 B 🔽
@sentry/node 162.66 KB -0.07% -103 B 🔽
@sentry/node - without tracing 98.97 KB -0.02% -20 B 🔽
@sentry/aws-serverless 126.61 KB -0.09% -109 B 🔽

View base workflow run

@@ -1,230 +0,0 @@
import { Scope, getGlobalScope, prepareEvent } from '@sentry/core';
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is not needed, it is just a duplicate of the core tests. this is a leftover from the experimental days when node had a forked/custom scope, but it is the same now.

function getParentSampled(parentSpan: Span, traceId: string, spanName: string): boolean | undefined {
const parentContext = parentSpan.spanContext();

// Only inherit sample rate if `traceId` is the same
// Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
if (isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
if (parentContext.isRemote) {
const parentSampled = getParentRemoteSampled(parentSpan);
const parentSampled = getSamplingDecision(parentSpan.spanContext());
Copy link
Member Author

@mydea mydea Dec 16, 2024

Choose a reason for hiding this comment

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

This method implementation was redundant, we already check traceId outside here, so we can simply get the decision directly. This was the only place where we still used getPropagationContextFromSpan.

@mydea mydea force-pushed the fn/removeSpanId branch 2 times, most recently from 5a72bc7 to 4eb2604 Compare December 17, 2024 08:29
@mydea mydea marked this pull request as ready for review December 17, 2024 09:11
Closes #12385

This also deprecates `getPropagationContextFromSpan` as it is no longer used/needed. We may think about removing this in v9, but IMHO we can also just leave this for v9, it does not hurt too much to have it in there...
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

I think this is in a good state, given we already made the decision that it's okay TwP scenarios to have different spanIds in consecutive errors or calls (see my other comment as well).

Before we merge this, I'd like to ensure that we have the following scenarios covered:

  • [TwP] trace id within trace envelope header is equal to event.contexts.trace
  • The sentry-trace header contains the id of the http.client span of the request

I'm fairly sure we already test this but it's probably worth to double check it

Comment on lines +44 to +55
expect(traceData['sentry-trace']).toMatch(/^[a-f0-9]{32}-[a-f0-9]{16}$/);
expect(traceData['sentry-trace']).toContain(`${trace_id}-`);
// span_id is a random span ID
expect(traceData['sentry-trace']).not.toContain(span_id);

expect(traceData.baggage).toContain(`sentry-trace_id=${trace_id}`);
expect(traceData.baggage).not.toContain('sentry-sampled=');

expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`);
expect(traceData.metaTags).toMatch(/<meta name="sentry-trace" content="[a-f0-9]{32}-[a-f0-9]{16}"\/>/);
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-`);
// span_id is a random span ID
expect(traceData.metaTags).not.toContain(span_id);
Copy link
Member

Choose a reason for hiding this comment

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

hmm so I'm a bit concerned about this. IIUC previously, the spanIds in this test were equal because we stored it on the PC. Now, consecutive calls to APIs like getTraceData() or getTraceMetaTags() like in this test deliver diverging span ids.

This also implies the following scenario for a TwP-configured SDK:

  1. app makes http request and propagates a sentry-trace header with spanId 123
  2. directly afterwards an error is captured and its event.context.trace holds a different spanId 456

I thought about the implications of this and while I'm still worried, I couldn't really come up with a concrete use case where this is actually problematic. I was especially worried if we'd send different spanIds within one error or transaction event but I think we only send this in event.context.trace. The trace envelope header does not contain the spanId at all, so it shouldn't be a problem.

However, we should ensure that the same traceId is still used in both places. Which I hope we have tests for but it's better to double-check.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, so the traceId is tested here (see line 53).

I totally get what you mean, it was the same for me - thinking, hmm, this is different, but then, is it actually a problem?

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.

[v9] Rethink spanId on propagationContext
2 participants