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

Merged
merged 5 commits into from
Jan 9, 2025
Merged

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 22.8 KB +0.29% +66 B 🔺
@sentry/browser - with treeshaking flags 21.55 KB +0.18% +38 B 🔺
@sentry/browser (incl. Tracing) 35.4 KB +0.04% +11 B 🔺
@sentry/browser (incl. Tracing, Replay) 72.09 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.63 KB +0.02% +7 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.35 KB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 88.38 KB +0.01% +4 B 🔺
@sentry/browser (incl. Feedback) 39.12 KB +0.12% +48 B 🔺
@sentry/browser (incl. sendFeedback) 27.48 KB +0.22% +60 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.3 KB +0.18% +59 B 🔺
@sentry/react 25.55 KB +0.22% +57 B 🔺
@sentry/react (incl. Tracing) 38.15 KB +0.01% +1 B 🔺
@sentry/vue 27.09 KB +0.05% +13 B 🔺
@sentry/vue (incl. Tracing) 37.24 KB +0.01% +1 B 🔺
@sentry/svelte 22.94 KB +0.34% +78 B 🔺
CDN Bundle 24.15 KB +0.13% +30 B 🔺
CDN Bundle (incl. Tracing) 35.71 KB +0.05% +15 B 🔺
CDN Bundle (incl. Tracing, Replay) 70.27 KB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 75.48 KB +0.03% +19 B 🔺
CDN Bundle - uncompressed 70.59 KB +0.18% +124 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 106.08 KB +0.04% +39 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 216.96 KB +0.02% +39 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.71 KB +0.02% +39 B 🔺
@sentry/nextjs (client) 38.28 KB -0.01% -1 B 🔽
@sentry/sveltekit (client) 35.91 KB +0.04% +13 B 🔺
@sentry/node 161.45 KB -0.02% -19 B 🔽
@sentry/node - without tracing 97.34 KB +0.06% +56 B 🔺
@sentry/aws-serverless 127.1 KB -0.02% -24 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
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 +57
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?

mydea added 4 commits January 8, 2025 11:03
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...

fix tests

remove unneeded test

fix stuff

fix tests

better test

fix test
@mydea mydea requested a review from Lms24 January 8, 2025 10:30
packages/core/src/types-hoist/tracing.ts Outdated Show resolved Hide resolved
@mydea mydea merged commit d5af638 into develop Jan 9, 2025
154 checks passed
@mydea mydea deleted the fn/removeSpanId branch January 9, 2025 08:26
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
3 participants