Skip to content

feat(core): Implement strictTraceContinuation #16313

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

Merged
merged 16 commits into from
Jul 25, 2025
Merged

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented May 16, 2025

This implements strictTraceContinuation based on those docs: https://develop.sentry.dev/sdk/telemetry/traces/#stricttracecontinuation

closes #16291

@s1gr1d s1gr1d requested review from mydea and Lms24 May 16, 2025 09:32
Copy link
Contributor

github-actions bot commented May 16, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.76 kB +0.06% +14 B 🔺
@sentry/browser - with treeshaking flags 22.35 kB +0.09% +18 B 🔺
@sentry/browser (incl. Tracing) 39.41 kB +0.06% +21 B 🔺
@sentry/browser (incl. Tracing, Replay) 77.52 kB -0.01% -2 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.39 kB +0.04% +22 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 82.23 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 94.35 kB +0.02% +13 B 🔺
@sentry/browser (incl. Feedback) 40.45 kB +0.03% +9 B 🔺
@sentry/browser (incl. sendFeedback) 28.44 kB +0.1% +26 B 🔺
@sentry/browser (incl. FeedbackAsync) 33.34 kB +0.04% +11 B 🔺
@sentry/react 25.5 kB +0.02% +5 B 🔺
@sentry/react (incl. Tracing) 41.38 kB -0.01% -3 B 🔽
@sentry/vue 28.2 kB +0.08% +21 B 🔺
@sentry/vue (incl. Tracing) 41.21 kB +0.02% +6 B 🔺
@sentry/svelte 23.79 kB +0.08% +19 B 🔺
CDN Bundle 25.28 kB +0.45% +113 B 🔺
CDN Bundle (incl. Tracing) 39.28 kB +0.22% +83 B 🔺
CDN Bundle (incl. Tracing, Replay) 75.39 kB +0.27% +197 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 80.82 kB +0.24% +189 B 🔺
CDN Bundle - uncompressed 73.86 kB +0.6% +438 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 116.29 kB +0.19% +211 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 230.53 kB +0.21% +470 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.35 kB +0.2% +470 B 🔺
@sentry/nextjs (client) 43.44 kB +0.06% +23 B 🔺
@sentry/sveltekit (client) 39.84 kB +0.05% +17 B 🔺
@sentry/node-core 47.48 kB +0.35% +165 B 🔺
@sentry/node 144.12 kB +0.13% +180 B 🔺
@sentry/node - without tracing 91.58 kB +0.2% +176 B 🔺
@sentry/aws-serverless 103.03 kB +0.19% +188 B 🔺

View base workflow run

const incomingDsc = baggageHeaderToDynamicSamplingContext(baggage);
const baggageOrgId = incomingDsc?.org_id;

let sdkOrgId: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

m: I think we should use the same logic here as for injecting the org id, which is use the specified one if defined, else extract it from dsn? We may also put this into a reusable utility, I suppose!

sdkOrgId = extractOrgIdFromDsnHost(dsn.host);
}

const shouldStartNewTrace = (): boolean => {
Copy link
Member

Choose a reason for hiding this comment

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

l: Let's maybe make this a separate function that takes arguments instead of inlining this function? No strong feelings, but this is how we usually do this I suppose 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah no strong opinions about this. Just thought it's not a lot of logic and when inlining this it does not disrupt you from the code-reading flow but it still keeps this part of the code separated :D

@s1gr1d s1gr1d marked this pull request as draft May 16, 2025 09:47
s1gr1d added 9 commits May 16, 2025 14:24
# Conflicts:
#	packages/core/src/index.ts
#	packages/core/src/tracing/dynamicSamplingContext.ts
#	packages/core/src/tracing/trace.ts
#	packages/core/src/utils/dsn.ts
#	packages/core/src/utils/tracing.ts
#	packages/core/test/lib/utils/tracing.test.ts
@s1gr1d s1gr1d marked this pull request as ready for review July 24, 2025 14:06
@s1gr1d s1gr1d requested review from andreiborza and cleptric July 24, 2025 14:25
@@ -10,7 +10,7 @@ import {
import type { DynamicSamplingContext } from '../types-hoist/envelope';
import type { Span } from '../types-hoist/span';
import { baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader } from '../utils/baggage';
import { extractOrgIdFromDsnHost } from '../utils/dsn';
import { deriveOrgIdFromClient } from '../utils/dsn';
Copy link
Member

Choose a reason for hiding this comment

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

l: why did we change this? IMHO derive is not easier to understand/grasp as extract...? 😅

Copy link
Member

Choose a reason for hiding this comment

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

with change, I mean re-word :D I would just go with extractOrgIdFromClient or something like this?

Copy link
Member Author

@s1gr1d s1gr1d Jul 25, 2025

Choose a reason for hiding this comment

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

It's a different function :D
I extracted the logic of getting the org ID.

extractOrgIdFromDsnHost is still available: https://github.com/getsentry/sentry-javascript/pull/16313/files#diff-b6e0f71bb87e888ddb45cd78dcf2cb7efdf9c80b6d596c0224648b1f78bdcb29R148

The one function is doing extractOrIdFromDsnHost, which is really just looking at the host string and extracting it from there. And deriveOrgIdFromClient is looking at different cues (either the org ID or the host on the client) to get the org ID.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, right, that makes sense of course - what I mean is that I think derive is a non-ideal term/prefix for the function name :D we do not use it anywhere in the code, rather we always use e.g. extractXX or getXX or something like this, so I'd rather use something along these lines for consistency - it is a different method of course :)

Copy link
Member Author

Choose a reason for hiding this comment

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

ah got you, that makes sense of course 👍

* The organization ID is extracted from the DSN. If the client options include a `orgId`, this will always take precedence.
*/
export function deriveOrgIdFromClient(client: Client | undefined): string | undefined {
const options = client?.getOptions();
Copy link
Member

Choose a reason for hiding this comment

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

l: I would re-organize this a bit and either:

  1. Enforce that client is not undefined - imho this is likely the nicer API, and then check at call-site if the client is undefined.
  2. Or else check at the top of the function if client is defined and return undefined early, avoiding repeated optional chaining below.

Copy link
Member

Choose a reason for hiding this comment

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

re 1: it is a bit weird to have an API deriveXXFromY and allow no Y to be passed in :D

* The result is dependent on the `strictTraceContinuation` option in the client.
* See https://develop.sentry.dev/sdk/telemetry/traces/#stricttracecontinuation
*/
export function shouldContinueTrace(client: Client | undefined, baggageOrgId?: string): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Also here, do we need to allow empty client? IMHO we never want to continue a trace if we have no client, so we can probably just check this at call site as well?

@s1gr1d s1gr1d requested a review from mydea July 25, 2025 08:14

let org_id: string | undefined;

if (options?.orgId) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (options?.orgId) {
if (options.orgId) {

I think this always exists now?

return false;
}

const strictTraceContinuation = client.getOptions()?.strictTraceContinuation || false; // default for `strictTraceContinuation` is `false`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const strictTraceContinuation = client.getOptions()?.strictTraceContinuation || false; // default for `strictTraceContinuation` is `false`
const strictTraceContinuation = client.getOptions().strictTraceContinuation || false; // default for `strictTraceContinuation` is `false`

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

small nits but overall looks great! 👍

@s1gr1d s1gr1d merged commit b0909cd into develop Jul 25, 2025
171 checks passed
@s1gr1d s1gr1d deleted the sig/strictTraceContinuation branch July 25, 2025 11:32
s1gr1d added a commit to getsentry/sentry-docs that referenced this pull request Jul 29, 2025
## DESCRIBE YOUR PR

Docs for `strictTraceContinuation` and `orgId` ([related
PR](getsentry/sentry-javascript#16313)).

I'm not 100% sure where I should put the `orgId` as it does not 100% fit
into the "Tracing Options" section but it's currently only used for
tracing.

closes getsentry/sentry-javascript#16308

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [ ] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
lucas-zimerman pushed a commit to getsentry/sentry-docs that referenced this pull request Jul 29, 2025
## DESCRIBE YOUR PR

Docs for `strictTraceContinuation` and `orgId` ([related
PR](getsentry/sentry-javascript#16313)).

I'm not 100% sure where I should put the `orgId` as it does not 100% fit
into the "Tracing Options" section but it's currently only used for
tracing.

closes getsentry/sentry-javascript#16308

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [ ] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
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.

Implement strictTraceContinuation handling
2 participants