Skip to content

Commit 269a678

Browse files
committed
make toTracestate private
1 parent 91fda65 commit 269a678

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

packages/tracing/src/span.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,6 @@ export class Span implements SpanInterface {
248248
return `${this.traceId}-${this.spanId}${sampledString}`;
249249
}
250250

251-
/**
252-
* @inheritDoc
253-
*/
254-
public toTracestate(): string | undefined {
255-
const sentryTracestate = this.transaction?.metadata?.tracestate?.sentry || this._getNewTracestate();
256-
let thirdpartyTracestate = this.transaction?.metadata?.tracestate?.thirdparty;
257-
258-
// if there's third-party data, add a leading comma; otherwise, convert from `undefined` to the empty string, so the
259-
// end result doesn’t come out as `sentry=xxxxxundefined`
260-
thirdpartyTracestate = thirdpartyTracestate ? `,${thirdpartyTracestate}` : '';
261-
262-
return `${sentryTracestate}${thirdpartyTracestate}`;
263-
}
264-
265251
/**
266252
* @inheritDoc
267253
*/
@@ -304,7 +290,7 @@ export class Span implements SpanInterface {
304290
* @inheritDoc
305291
*/
306292
public getTraceHeaders(): TraceHeaders {
307-
const tracestate = this.toTracestate();
293+
const tracestate = this._toTracestate();
308294

309295
return {
310296
'sentry-trace': this.toTraceparent(),
@@ -395,4 +381,18 @@ export class Span implements SpanInterface {
395381
publicKey: dsn.publicKey!,
396382
})}`;
397383
}
384+
385+
/**
386+
* Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN.
387+
*/
388+
private _toTracestate(): string | undefined {
389+
const sentryTracestate = this.transaction?.metadata?.tracestate?.sentry || this._getNewTracestate();
390+
let thirdpartyTracestate = this.transaction?.metadata?.tracestate?.thirdparty;
391+
392+
// if there's third-party data, add a leading comma; otherwise, convert from `undefined` to the empty string, so the
393+
// end result doesn’t come out as `sentry=xxxxxundefined`
394+
thirdpartyTracestate = thirdpartyTracestate ? `,${thirdpartyTracestate}` : '';
395+
396+
return `${sentryTracestate}${thirdpartyTracestate}`;
397+
}
398398
}

packages/tracing/test/span.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@ describe('Span', () => {
124124
const transaction = new Transaction({ name: 'FETCH /ball', traceId }, hub);
125125
const span = transaction.startChild({ op: 'dig.hole' });
126126

127-
expect(span.toTracestate()).toEqual(computedTracestate);
127+
expect(span.getTraceHeaders().tracestate).toEqual(computedTracestate);
128128
});
129129

130130
test('third-party data', () => {
131131
const transaction = new Transaction({ name: 'FETCH /ball' }, hub);
132132
transaction.setMetadata({ tracestate: { sentry: computedTracestate, thirdparty: thirdpartyData } });
133133
const span = transaction.startChild({ op: 'dig.hole' });
134134

135-
expect(span.toTracestate()).toEqual(`${computedTracestate},${thirdpartyData}`);
135+
expect(span.getTraceHeaders().tracestate).toEqual(`${computedTracestate},${thirdpartyData}`);
136136
});
137137

138138
test('orphan span', () => {
139139
jest.spyOn(hubPackage, 'getCurrentHub').mockReturnValueOnce(hub);
140140
const span = new Span({ op: 'dig.hole' });
141141
span.traceId = traceId;
142142

143-
expect(span.toTracestate()).toEqual(computedTracestate);
143+
expect(span.getTraceHeaders().tracestate).toEqual(computedTracestate);
144144
});
145145
});
146146

packages/types/src/span.ts

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

152-
/** Return a traceparent-compatible header string */
153-
toTraceparent(): string;
154-
155-
/** Return a tracestate-compatible header string. Returns undefined if there is no client or no DSN. */
156-
toTracestate(): string | undefined;
152+
/**
153+
* Return a traceparent-compatible header string
154+
*
155+
* NOTE: Do not use `span.toTraceparnt` directly. Use `span.getTraceHeaders` instead.
156+
*/
157+
toTraceparent(): string; // TODO (kmclb) make this private
157158

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

0 commit comments

Comments
 (0)