Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/opentelemetry-node/src/propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export class SentryPropagator implements TextMapPropagator {
const traceparentData = extractTraceparentData(header);
newContext = newContext.setValue(SENTRY_TRACE_PARENT_CONTEXT_KEY, traceparentData);
if (traceparentData) {
const traceFlags = traceparentData.parentSampled ? TraceFlags.SAMPLED : TraceFlags.NONE;
const spanContext = {
traceId: traceparentData.traceId || '',
spanId: traceparentData.parentSpanId || '',
isRemote: true,
traceFlags,
// Always sample if traceparent exists, we use SentrySpanProcessor to make sampling decisions with `startTransaction`.
traceFlags: TraceFlags.SAMPLED,
};
newContext = trace.setSpanContext(newContext, spanContext);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/opentelemetry-node/src/spanprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function getTraceData(otelSpan: OtelSpan, parentContext: Context): Partial<Trans
| Partial<DynamicSamplingContext>
| undefined;

return {
const context: Partial<TransactionContext> = {
spanId,
traceId,
parentSpanId,
Expand All @@ -139,6 +139,13 @@ function getTraceData(otelSpan: OtelSpan, parentContext: Context): Partial<Trans
source: 'custom',
},
};

// Only inherit sample rate if `traceId` is the same
if (traceparentData && traceId === traceparentData.traceId) {
Copy link
Member

Choose a reason for hiding this comment

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

this state is obviously possible but it's not clear to me

  • when that happens
  • if there's a mismatch, we don't take the sampled decision, but what are the consequences of that in the later flow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to sleep on this and come back to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so the only way there is a possible mismatch is if there is user mis-configuration - like they override span attributes themselves or do some custom logic. From what I read through, the SDK itself should not make this possible in any way.

With that in mind, I'm going to keep this guard anyway because I don't wanna re-run tests, but I don't think this check is necessary in other SDKs.

Copy link
Member

Choose a reason for hiding this comment

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

alright sounds good

context.parentSampled = traceparentData.parentSampled;
}

return context;
}

function finishTransactionWithContextFromOtelData(transaction: Transaction, otelSpan: OtelSpan): void {
Expand Down