Skip to content

Commit 7d5d3f2

Browse files
committed
fix: Dont clash between span and scope trace context data
1 parent 9cc5548 commit 7d5d3f2

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

packages/apm/src/span.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ export class Span implements SpanInterface, SpanContext {
287287
}
288288

289289
return this._hub.captureEvent({
290-
contexts: { trace: this.getTraceContext() },
291290
spans: finishedSpans,
292291
start_timestamp: this.startTimestamp,
293292
tags: this.tags,
@@ -312,22 +311,17 @@ export class Span implements SpanInterface, SpanContext {
312311
* @inheritDoc
313312
*/
314313
public getTraceContext(): object {
315-
const context = {
314+
return {
316315
data: this.data,
317316
description: this.description,
318317
op: this.op,
319318
parent_span_id: this._parentSpanId,
320319
span_id: this._spanId,
320+
// Undefined status will be dropped by `JSON.stringify` anyway so it's safe to read it directly like that
321+
status: this.tags.status,
321322
tags: this.tags,
322323
trace_id: this._traceId,
323324
};
324-
325-
if (this.tags.status) {
326-
// TODO: Fixme, just use better typings
327-
(context as any).status = this.tags.status;
328-
}
329-
330-
return context;
331325
}
332326

333327
/**

packages/hub/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export class Scope implements ScopeInterface {
329329
}
330330
if (this._span) {
331331
event.contexts = event.contexts || {};
332-
event.contexts.trace = this._span;
332+
event.contexts.trace = this._span.getTraceContext();
333333
}
334334

335335
this._applyFingerprint(event);

packages/types/src/span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface SpanContext {
5454
/**
5555
* Completion status of the Span.
5656
*/
57-
status?: boolean;
57+
status?: SpanStatus;
5858
/**
5959
* Parent Span ID
6060
*/

0 commit comments

Comments
 (0)