From 7ed50ed33ae8e0c584c25298cd94a551cfbd7838 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 28 Aug 2023 15:42:24 +0100 Subject: [PATCH] fix: Defer tracing decision to downstream SDKs when using SDK without performance (#8839) --- packages/core/src/scope.ts | 1 - packages/hub/test/scope.test.ts | 4 ++-- packages/node/test/integrations/http.test.ts | 5 +++-- packages/tracing-internal/src/browser/browsertracing.ts | 2 +- packages/types/src/tracing.ts | 2 +- packages/utils/src/tracing.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index b72defc56016..8875f1c996f2 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -636,6 +636,5 @@ function generatePropagationContext(): PropagationContext { return { traceId: uuid4(), spanId: uuid4().substring(16), - sampled: false, }; } diff --git a/packages/hub/test/scope.test.ts b/packages/hub/test/scope.test.ts index 982cba766a87..4c0d830340ec 100644 --- a/packages/hub/test/scope.test.ts +++ b/packages/hub/test/scope.test.ts @@ -20,7 +20,7 @@ describe('Scope', () => { expect(scope._propagationContext).toEqual({ traceId: expect.any(String), spanId: expect.any(String), - sampled: false, + sampled: undefined, dsc: undefined, parentSpanId: undefined, }); @@ -442,7 +442,7 @@ describe('Scope', () => { expect(scope._propagationContext).toEqual({ traceId: expect.any(String), spanId: expect.any(String), - sampled: false, + sampled: undefined, }); // @ts-expect-error accessing private property expect(scope._propagationContext).not.toEqual(oldPropagationContext); diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index e784eb308f54..0f1613a27345 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -208,10 +208,11 @@ describe('tracing', () => { const baggageHeader = request.getHeader('baggage') as string; const parts = sentryTraceHeader.split('-'); - expect(parts.length).toEqual(3); + + // Should not include sampling decision since we don't wanna influence the tracing decisions downstream + expect(parts.length).toEqual(2); expect(parts[0]).toEqual(traceId); expect(parts[1]).toEqual(expect.any(String)); - expect(parts[2]).toEqual('0'); expect(baggageHeader).toEqual( `sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=${traceId}`, diff --git a/packages/tracing-internal/src/browser/browsertracing.ts b/packages/tracing-internal/src/browser/browsertracing.ts index d01c837d26c2..a11ea7ff2cf2 100644 --- a/packages/tracing-internal/src/browser/browsertracing.ts +++ b/packages/tracing-internal/src/browser/browsertracing.ts @@ -364,7 +364,7 @@ export class BrowserTracing implements Integration { traceId: idleTransaction.traceId, spanId: idleTransaction.spanId, parentSpanId: idleTransaction.parentSpanId, - sampled: !!idleTransaction.sampled, + sampled: idleTransaction.sampled, }); } diff --git a/packages/types/src/tracing.ts b/packages/types/src/tracing.ts index 11c4a1658d50..7c5b02c45596 100644 --- a/packages/types/src/tracing.ts +++ b/packages/types/src/tracing.ts @@ -5,7 +5,7 @@ export type TracePropagationTargets = (string | RegExp)[]; export interface PropagationContext { traceId: string; spanId: string; - sampled: boolean; + sampled?: boolean; parentSpanId?: string; dsc?: DynamicSamplingContext; } diff --git a/packages/utils/src/tracing.ts b/packages/utils/src/tracing.ts index f879b856f9f2..6ad839f2b920 100644 --- a/packages/utils/src/tracing.ts +++ b/packages/utils/src/tracing.ts @@ -61,7 +61,7 @@ export function tracingContextFromHeaders( const propagationContext: PropagationContext = { traceId: traceId || uuid4(), spanId: uuid4().substring(16), - sampled: parentSampled === undefined ? false : parentSampled, + sampled: parentSampled, }; if (parentSpanId) {