Skip to content

Commit 678d601

Browse files
committed
deprecate toTraceparent
1 parent ea6b9ef commit 678d601

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/tracing/src/span.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class Span implements SpanInterface {
126126
if (spanContext.parentSpanId) {
127127
this.parentSpanId = spanContext.parentSpanId;
128128
}
129-
// We want to include booleans as well here
129+
// check this way instead of the normal way to make sure we don't miss cases where sampled = false
130130
if ('sampled' in spanContext) {
131131
this.sampled = spanContext.sampled;
132132
}
@@ -241,11 +241,9 @@ export class Span implements SpanInterface {
241241
* @inheritDoc
242242
*/
243243
public toTraceparent(): string {
244-
let sampledString = '';
245-
if (this.sampled !== undefined) {
246-
sampledString = this.sampled ? '-1' : '-0';
247-
}
248-
return `${this.traceId}-${this.spanId}${sampledString}`;
244+
logger.warn('Direct use of `span.toTraceparent` is deprecated. Use `span.getTraceHeaders` instead.');
245+
246+
return this._toSentrytrace();
249247
}
250248

251249
/**

packages/types/src/span.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ export interface Span extends SpanContext {
149149
*/
150150
isSuccess(): boolean;
151151

152-
/** Return a traceparent compatible header string */
153-
toTraceparent(): string;
152+
/**
153+
* Return a traceparent-compatible header string
154+
*
155+
* @deprecated Do not use `span.toTraceparnt` directly. Use `span.getTraceHeaders` instead.
156+
*/
157+
toTraceparent(): string; // TODO (kmclb) make this private
154158

155159
/** Returns the current span properties as a `SpanContext` */
156160
toContext(): SpanContext;

0 commit comments

Comments
 (0)