|
1 | 1 | /* eslint-disable max-lines */ |
2 | 2 | import { getCurrentHub } from '@sentry/hub'; |
3 | 3 | import { Hub, Primitive, Span as SpanInterface, SpanContext, TraceHeaders } from '@sentry/types'; |
4 | | -import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils'; |
| 4 | +import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils'; |
5 | 5 |
|
6 | 6 | import { SpanStatus } from './spanstatus'; |
7 | 7 | import { Transaction } from './transaction'; |
@@ -242,11 +242,9 @@ export class Span implements SpanInterface { |
242 | 242 | * @inheritDoc |
243 | 243 | */ |
244 | 244 | public toTraceparent(): string { |
245 | | - let sampledString = ''; |
246 | | - if (this.sampled !== undefined) { |
247 | | - sampledString = this.sampled ? '-1' : '-0'; |
248 | | - } |
249 | | - return `${this.traceId}-${this.spanId}${sampledString}`; |
| 245 | + logger.warn('Direct use of `span.toTraceparent` is deprecated. Use `span.getTraceHeaders` instead.'); |
| 246 | + |
| 247 | + return this._toSentrytrace(); |
250 | 248 | } |
251 | 249 |
|
252 | 250 | /** |
@@ -294,7 +292,7 @@ export class Span implements SpanInterface { |
294 | 292 | const tracestate = this._toTracestate(); |
295 | 293 |
|
296 | 294 | return { |
297 | | - 'sentry-trace': this.toTraceparent(), |
| 295 | + 'sentry-trace': this._toSentrytrace(), |
298 | 296 | ...(tracestate && { tracestate }), |
299 | 297 | }; |
300 | 298 | } |
@@ -383,6 +381,17 @@ export class Span implements SpanInterface { |
383 | 381 | })}`; |
384 | 382 | } |
385 | 383 |
|
| 384 | + /** |
| 385 | + * Return a tracestate-compatible header string. |
| 386 | + */ |
| 387 | + private _toSentrytrace(): string { |
| 388 | + let sampledString = ''; |
| 389 | + if (this.sampled !== undefined) { |
| 390 | + sampledString = this.sampled ? '-1' : '-0'; |
| 391 | + } |
| 392 | + return `${this.traceId}-${this.spanId}${sampledString}`; |
| 393 | + } |
| 394 | + |
386 | 395 | /** |
387 | 396 | * Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN. |
388 | 397 | */ |
|
0 commit comments