Skip to content

Commit

Permalink
fix strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Sep 12, 2023
1 parent 334eac9 commit 1825c15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 0 additions & 7 deletions packages/opentelemetry-node/src/spanprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
// so we cannot use hub.getSpan(), as we cannot rely on this being on the current span
const sentryParentSpan = otelParentSpanId && SENTRY_SPAN_PROCESSOR_MAP.get(otelParentSpanId);

if (this._strictSpanParentHandling && otelParentSpanId && !sentryParentSpan) {
logger.warn(
`SentrySpanProcessor could not find parent span with OTEL-spanId ${otelParentSpanId}. Dropping the span "${otelSpan.name}" with OTEL-spanID ${otelSpanId}...`,
);
return;
}

if (sentryParentSpan) {
const sentryChildSpan = sentryParentSpan.startChild({
description: otelSpan.name,
Expand Down
17 changes: 11 additions & 6 deletions packages/opentelemetry-node/test/spanprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ describe('SentrySpanProcessor', () => {
});
});

it('aborts when encountering a missing parent reference', () => {
// If we cannot find the parent span, it means we are continuing a trace from somehwere else
it('handles missing parent reference', () => {
const startTimestampMs = 1667381672309;
const endTimestampMs = 1667381672875;
const startTime = otelNumberToHrtime(startTimestampMs);
Expand All @@ -947,19 +948,20 @@ describe('SentrySpanProcessor', () => {

tracer.startActiveSpan('GET /users', parentOtelSpan => {
// We simulate the parent somehow not existing in our internal map
// this can happen if a race condition leads to spans being processed out of order
SENTRY_SPAN_PROCESSOR_MAP.delete(parentOtelSpan.spanContext().spanId);

tracer.startActiveSpan('SELECT * FROM users;', { startTime }, child => {
const childOtelSpan = child as OtelSpan;

// Parent span does not exist...
// Parent span cannot be looked up, because we deleted the reference before...
const sentrySpanTransaction = getSpanForOtelSpan(parentOtelSpan);
expect(sentrySpanTransaction).toBeUndefined();

// Span itself does not exist...
// Span itself does does exist as a transaction
const sentrySpan = getSpanForOtelSpan(childOtelSpan);
expect(sentrySpan).toBeUndefined();
expect(sentrySpan).toBeDefined();
expect(sentrySpan).toBeInstanceOf(Transaction);
expect(sentrySpan?.parentSpanId).toEqual(parentOtelSpan.spanContext().spanId);

child.end(endTime);
});
Expand Down Expand Up @@ -1004,9 +1006,12 @@ describe('SentrySpanProcessor', () => {
child.end();

expect(parentSpan).toBeDefined();
expect(childSpan).not.toBeDefined();
expect(childSpan).toBeDefined();
expect(parentSpan).toBeInstanceOf(Transaction);
expect(childSpan).toBeInstanceOf(Transaction);
expect(childSpan?.parentSpanId).toEqual(parentSpan?.spanId);
expect(parentSpan?.endTimestamp).toBeDefined();
expect(childSpan?.endTimestamp).toBeDefined();
});
});
});
Expand Down

0 comments on commit 1825c15

Please sign in to comment.