@@ -314,35 +314,43 @@ export class Span implements SpanInterface, SpanContext {
314
314
* @inheritDoc
315
315
*/
316
316
public getTraceContext ( ) : object {
317
- return {
318
- data : this . data ,
319
- description : this . description ,
320
- op : this . op ,
321
- parent_span_id : this . _parentSpanId ,
322
- span_id : this . _spanId ,
323
- // Undefined status will be dropped by `JSON.stringify` anyway so it's safe to read it directly like that
324
- status : this . tags . status ,
325
- tags : this . tags ,
326
- trace_id : this . _traceId ,
327
- } ;
317
+ // JSON.parse + JSON.stringify to remove undefined values
318
+ // tslint:disable-next-line: no-unsafe-any
319
+ return JSON . parse (
320
+ JSON . stringify ( {
321
+ data : this . data ,
322
+ description : this . description ,
323
+ op : this . op ,
324
+ parent_span_id : this . _parentSpanId ,
325
+ span_id : this . _spanId ,
326
+ // Undefined status will be dropped by `JSON.stringify` anyway so it's safe to read it directly like that
327
+ status : this . tags . status ,
328
+ tags : this . tags ,
329
+ trace_id : this . _traceId ,
330
+ } ) ,
331
+ ) ;
328
332
}
329
333
330
334
/**
331
335
* @inheritDoc
332
336
*/
333
337
public toJSON ( ) : object {
334
- return {
335
- data : this . data ,
336
- description : this . description ,
337
- op : this . op ,
338
- parent_span_id : this . _parentSpanId ,
339
- sampled : this . sampled ,
340
- span_id : this . _spanId ,
341
- start_timestamp : this . startTimestamp ,
342
- tags : this . tags ,
343
- timestamp : this . timestamp ,
344
- trace_id : this . _traceId ,
345
- transaction : this . transaction ,
346
- } ;
338
+ // JSON.parse + JSON.stringify to remove undefined values
339
+ // tslint:disable-next-line: no-unsafe-any
340
+ return JSON . parse (
341
+ JSON . stringify ( {
342
+ data : this . data ,
343
+ description : this . description ,
344
+ op : this . op ,
345
+ parent_span_id : this . _parentSpanId ,
346
+ sampled : this . sampled ,
347
+ span_id : this . _spanId ,
348
+ start_timestamp : this . startTimestamp ,
349
+ tags : this . tags ,
350
+ timestamp : this . timestamp ,
351
+ trace_id : this . _traceId ,
352
+ transaction : this . transaction ,
353
+ } ) ,
354
+ ) ;
347
355
}
348
356
}
0 commit comments