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
23 changes: 10 additions & 13 deletions packages/opentelemetry-node/src/spanprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@ export const SENTRY_SPAN_PROCESSOR_MAP: Map<SentrySpan['spanId'], SentrySpan> =
export class SentrySpanProcessor implements OtelSpanProcessor {
public constructor() {
addGlobalEventProcessor(event => {
const otelSpan = trace.getActiveSpan();
const otelSpan = trace.getActiveSpan() as OtelSpan;
if (!otelSpan) {
return event;
}

const otelSpanId = otelSpan.spanContext().spanId;
const sentrySpan = SENTRY_SPAN_PROCESSOR_MAP.get(otelSpanId);

if (!sentrySpan) {
return event;
}
const otelSpanContext = otelSpan.spanContext();

// If event has already set `trace` context, use that one.
// This happens in the case of transaction events.
event.contexts = { trace: sentrySpan.getTraceContext(), ...event.contexts };
const transactionName = sentrySpan.transaction && sentrySpan.transaction.name;
if (transactionName) {
event.tags = { transaction: transactionName, ...event.tags };
}
event.contexts = {
trace: {
trace_id: otelSpanContext.traceId,
span_id: otelSpanContext.spanId,
parent_span_id: otelSpan.parentSpanId,
},
...event.contexts,
};

return event;
});
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-node/test/spanprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ describe('SentrySpanProcessor', () => {
expect(sentryEvent).toBeDefined();
expect(sentryEvent.exception).toBeDefined();
expect(sentryEvent.contexts.trace).toEqual({
description: otelSpan.name,
parent_span_id: otelSpan.parentSpanId,
span_id: otelSpan.spanContext().spanId,
trace_id: otelSpan.spanContext().traceId,
Expand Down