Skip to content

Commit 300031d

Browse files
committed
return undefined if no links
1 parent aa1ab44 commit 300031d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/core/src/utils/spanUtils.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ export function spanToTraceHeader(span: Span): string {
8686
/**
8787
* Converts the span links array to a flattened version to be sent within an envelope
8888
*/
89-
export function convertSpanLinksForEnvelope(links: SpanLink[]): SpanLinkJSON[] {
90-
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({
91-
span_id: spanId,
92-
trace_id: traceId,
93-
sampled: traceFlags === TRACE_FLAG_SAMPLED,
94-
attributes,
95-
...restContext,
96-
}));
89+
export function convertSpanLinksForEnvelope(links?: SpanLink[]): SpanLinkJSON[] | undefined {
90+
if (links && links.length > 0) {
91+
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({
92+
span_id: spanId,
93+
trace_id: traceId,
94+
sampled: traceFlags === TRACE_FLAG_SAMPLED,
95+
attributes,
96+
...restContext,
97+
}));
98+
} else {
99+
return undefined;
100+
}
97101
}
98102

99103
/**
@@ -153,7 +157,7 @@ export function spanToJSON(span: Span): SpanJSON {
153157
status: getStatusMessage(status),
154158
op: attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],
155159
origin: attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
156-
links: links ? convertSpanLinksForEnvelope(links) : undefined,
160+
links: convertSpanLinksForEnvelope(links),
157161
});
158162
}
159163

packages/opentelemetry/src/spanExporter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], sentS
348348
op,
349349
origin,
350350
measurements: timedEventsToMeasurements(span.events),
351-
links: links ? convertSpanLinksForEnvelope(links) : undefined,
351+
links: convertSpanLinksForEnvelope(links),
352352
});
353353

354354
spans.push(spanJSON);

0 commit comments

Comments
 (0)