Skip to content

Commit 7b2826c

Browse files
committed
fix
1 parent 2935759 commit 7b2826c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/opentelemetry-node/src/spanprocessor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
8585
// so we cannot use hub.getSpan(), as we cannot rely on this being on the current span
8686
const sentryParentSpan = otelParentSpanId && SENTRY_SPAN_PROCESSOR_MAP.get(otelParentSpanId);
8787

88-
if (this._strictSpanParentHandling && !!otelParentSpanId && !sentryParentSpan) {
88+
if (this._strictSpanParentHandling && otelParentSpanId && !sentryParentSpan) {
8989
logger.warn(
9090
`SentrySpanProcessor could not find parent span with OTEL-spanId ${otelParentSpanId}. Dropping the span "${otelSpan.name}" with OTEL-spanID ${otelSpanId}...`,
9191
);
@@ -129,6 +129,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
129129
if (!sentrySpan) {
130130
__DEBUG_BUILD__ &&
131131
logger.error(`SentrySpanProcessor could not find span with OTEL-spanId ${otelSpanId} to finish.`);
132+
this._clearSpan(otelSpanId);
132133
return;
133134
}
134135

@@ -312,6 +313,8 @@ function scheduleToClear(otelSpanId: string): void {
312313

313314
if (!span) {
314315
// hmm, something is fishy here, but abort...
316+
// But to be sure we still try to delete the SCHEDULE_TO_CLEAR, to avoid leaks
317+
SCHEDULE_TO_CLEAR.delete(otelSpanId);
315318
return;
316319
}
317320

packages/opentelemetry-node/test/spanprocessor.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ describe('SentrySpanProcessor', () => {
937937
});
938938
});
939939

940-
it('aborts when encountering a missing parent reference xxx', () => {
940+
it('aborts when encountering a missing parent reference', () => {
941941
const startTimestampMs = 1667381672309;
942942
const endTimestampMs = 1667381672875;
943943
const startTime = otelNumberToHrtime(startTimestampMs);
@@ -1004,11 +1004,9 @@ describe('SentrySpanProcessor', () => {
10041004
child.end();
10051005

10061006
expect(parentSpan).toBeDefined();
1007-
expect(childSpan).toBeDefined();
1007+
expect(childSpan).not.toBeDefined();
10081008
expect(parentSpan).toBeInstanceOf(Transaction);
1009-
expect(childSpan).toBeInstanceOf(Transaction);
10101009
expect(parentSpan?.endTimestamp).toBeDefined();
1011-
expect(childSpan?.endTimestamp).toBeDefined();
10121010
});
10131011
});
10141012
});

0 commit comments

Comments
 (0)