From e9f65220a0894f6515394746e7b70f8ad95dda10 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 18 Apr 2024 13:33:42 +0200 Subject: [PATCH] fix(nextjs): Do not sample next spans if they have remote parent --- packages/opentelemetry/src/sampler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry/src/sampler.ts b/packages/opentelemetry/src/sampler.ts index 10be97b0a4bd..d323ca4424e2 100644 --- a/packages/opentelemetry/src/sampler.ts +++ b/packages/opentelemetry/src/sampler.ts @@ -67,8 +67,8 @@ export class SentrySampler implements Sampler { // If we encounter a span emitted by Next.js, we do not want to sample it // The reason for this is that the data quality of the spans varies, it is different per version of Next, // and we need to keep our manual instrumentation around for the edge runtime anyhow. - // BUT we only do this if we don't have a parent span with a sampling decision yet - if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') { + // BUT we only do this if we don't have a parent span with a sampling decision yet (or if the parent is remote) + if (spanAttributes['next.span_type'] && (typeof parentSampled !== 'boolean' || parentContext?.isRemote)) { return { decision: SamplingDecision.NOT_RECORD, traceState: traceState }; }