diff --git a/packages/apm/src/span.ts b/packages/apm/src/span.ts index 9f328a15e2d6..0621fb5949da 100644 --- a/packages/apm/src/span.ts +++ b/packages/apm/src/span.ts @@ -71,6 +71,11 @@ export class Span implements SpanInterface, SpanContext { */ private readonly _parentSpanId?: string; + /** + * Internal keeper of the status + */ + private _status?: SpanStatus; + /** * @inheritDoc */ @@ -153,6 +158,9 @@ export class Span implements SpanInterface, SpanContext { if (spanContext.tags) { this.tags = spanContext.tags; } + if (spanContext.status) { + this._status = spanContext.status; + } } /** @@ -229,7 +237,7 @@ export class Span implements SpanInterface, SpanContext { * @inheritDoc */ public setStatus(value: SpanStatus): this { - this.setTag('status', value); + this._status = value; return this; } @@ -249,7 +257,7 @@ export class Span implements SpanInterface, SpanContext { * @inheritDoc */ public isSuccess(): boolean { - return this.tags.status === SpanStatus.Ok; + return this._status === SpanStatus.Ok; } /** @@ -333,7 +341,7 @@ export class Span implements SpanInterface, SpanContext { op: this.op, parent_span_id: this._parentSpanId, span_id: this._spanId, - status: this.tags.status, + status: this._status, tags: Object.keys(this.tags).length > 0 ? this.tags : undefined, trace_id: this._traceId, }); diff --git a/packages/apm/test/span.test.ts b/packages/apm/test/span.test.ts index ee641c276426..b18aa2051293 100644 --- a/packages/apm/test/span.test.ts +++ b/packages/apm/test/span.test.ts @@ -55,13 +55,13 @@ describe('Span', () => { test('setStatus', () => { const span = new Span({}); span.setStatus(SpanStatus.PermissionDenied); - expect(span.tags.status).toBe('permission_denied'); + expect((span.getTraceContext() as any).status).toBe('permission_denied'); }); test('setHttpStatus', () => { const span = new Span({}); span.setHttpStatus(404); - expect(span.tags.status).toBe('not_found'); + expect((span.getTraceContext() as any).status).toBe('not_found'); expect(span.tags['http.status_code']).toBe('404'); });