MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / shouldContinueTrace

Function shouldContinueTrace

packages/core/src/utils/tracing.ts:153–179  ·  view source on GitHub ↗
(client: Client, baggageOrgId?: string)

Source from the content-addressed store, hash-verified

151 * See https://develop.sentry.dev/sdk/telemetry/traces/#stricttracecontinuation
152 */
153export function shouldContinueTrace(client: Client, baggageOrgId?: string): boolean {
154 const clientOrgId = extractOrgIdFromClient(client);
155
156 // Case: baggage orgID and Client orgID don't match - always start new trace
157 if (baggageOrgId && clientOrgId && baggageOrgId !== clientOrgId) {
158 debug.log(
159 `Won't continue trace because org IDs don't match (incoming baggage: ${baggageOrgId}, SDK options: ${clientOrgId})`,
160 );
161 return false;
162 }
163
164 const strictTraceContinuation = client.getOptions().strictTraceContinuation || false; // default for `strictTraceContinuation` is `false`
165
166 if (strictTraceContinuation) {
167 // With strict continuation enabled, don't continue trace if:
168 // - Baggage has orgID, but Client doesn't have one
169 // - Client has orgID, but baggage doesn't have one
170 if ((baggageOrgId && !clientOrgId) || (!baggageOrgId && clientOrgId)) {
171 debug.log(
172 `Starting a new trace because strict trace continuation is enabled but one org ID is missing (incoming baggage: ${baggageOrgId}, Sentry client: ${clientOrgId})`,
173 );
174 return false;
175 }
176 }
177
178 return true;
179}

Callers 3

tracing.test.tsFile · 0.90
continueTraceFunction · 0.90

Calls 3

extractOrgIdFromClientFunction · 0.90
logMethod · 0.65
getOptionsMethod · 0.65

Tested by

no test coverage detected