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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 5.12.3

- [apm] fix: Remove undefined keys from trace.context

## 5.12.2

- [apm] ref: Check if Tracing integration is enabled before dropping transaction
Expand Down
56 changes: 32 additions & 24 deletions packages/apm/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,35 +314,43 @@ export class Span implements SpanInterface, SpanContext {
* @inheritDoc
*/
public getTraceContext(): object {
return {
data: this.data,
description: this.description,
op: this.op,
parent_span_id: this._parentSpanId,
span_id: this._spanId,
// Undefined status will be dropped by `JSON.stringify` anyway so it's safe to read it directly like that
status: this.tags.status,
tags: this.tags,
trace_id: this._traceId,
};
// JSON.parse + JSON.stringify to remove undefined values
// tslint:disable-next-line: no-unsafe-any
return JSON.parse(
JSON.stringify({
data: this.data,
description: this.description,
op: this.op,
parent_span_id: this._parentSpanId,
span_id: this._spanId,
// Undefined status will be dropped by `JSON.stringify` anyway so it's safe to read it directly like that
status: this.tags.status,
tags: this.tags,
trace_id: this._traceId,
}),
);
}

/**
* @inheritDoc
*/
public toJSON(): object {
return {
data: this.data,
description: this.description,
op: this.op,
parent_span_id: this._parentSpanId,
sampled: this.sampled,
span_id: this._spanId,
start_timestamp: this.startTimestamp,
tags: this.tags,
timestamp: this.timestamp,
trace_id: this._traceId,
transaction: this.transaction,
};
// JSON.parse + JSON.stringify to remove undefined values
// tslint:disable-next-line: no-unsafe-any
return JSON.parse(
JSON.stringify({
data: this.data,
description: this.description,
op: this.op,
parent_span_id: this._parentSpanId,
sampled: this.sampled,
span_id: this._spanId,
start_timestamp: this.startTimestamp,
tags: this.tags,
timestamp: this.timestamp,
trace_id: this._traceId,
transaction: this.transaction,
}),
);
}
}