Skip to content

Commit ef18cc7

Browse files
committed
feat(core): Deprecate span toContext() and updateWithContext()
These APIs are not really used, and are not compatible with OpenTelemetry. So let's deprecate them for removal in v8.
1 parent f127479 commit ef18cc7

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
149149
* @inheritDoc
150150
*/
151151
public toContext(): TransactionContext {
152+
// eslint-disable-next-line deprecation/deprecation
152153
const spanContext = super.toContext();
153154

154155
return dropUndefinedKeys({
@@ -162,6 +163,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
162163
* @inheritDoc
163164
*/
164165
public updateWithContext(transactionContext: TransactionContext): this {
166+
// eslint-disable-next-line deprecation/deprecation
165167
super.updateWithContext(transactionContext);
166168

167169
this.name = transactionContext.name || '';

packages/tracing/test/span.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ describe('Span', () => {
471471
});
472472
});
473473

474+
/* eslint-disable deprecation/deprecation */
474475
describe('toContext and updateWithContext', () => {
475476
test('toContext should return correct context', () => {
476477
const originalContext = { traceId: 'a', spanId: 'b', sampled: false, description: 'test', op: 'op' };
@@ -551,6 +552,7 @@ describe('Span', () => {
551552
expect(span.data).toStrictEqual({ data0: 'foo', data1: 'bar' });
552553
});
553554
});
555+
/* eslint-enable deprecation/deprecation */
554556

555557
describe('getDynamicSamplingContext', () => {
556558
beforeEach(() => {

packages/types/src/span.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,16 @@ export interface Span extends SpanContext {
221221
/** Return a traceparent compatible header string */
222222
toTraceparent(): string;
223223

224-
/** Returns the current span properties as a `SpanContext` */
224+
/**
225+
* Returns the current span properties as a `SpanContext`.
226+
* @deprecated Use `toJSON()` or access the fields directly instead.
227+
*/
225228
toContext(): SpanContext;
226229

227-
/** Updates the current span with a new `SpanContext` */
230+
/**
231+
* Updates the current span with a new `SpanContext`.
232+
* @deprecated Update the fields directly instead.
233+
*/
228234
updateWithContext(spanContext: SpanContext): this;
229235

230236
/** Convert the object to JSON for w. spans array info only */

packages/types/src/transaction.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ export interface Transaction extends TransactionContext, Omit<Span, 'setName' |
102102
*/
103103
setMeasurement(name: string, value: number, unit: MeasurementUnit): void;
104104

105-
/** Returns the current transaction properties as a `TransactionContext` */
105+
/**
106+
* Returns the current transaction properties as a `TransactionContext`.
107+
* @deprecated Use `toJSON()` or access the fields directly instead.
108+
*/
106109
toContext(): TransactionContext;
107110

108-
/** Updates the current transaction with a new `TransactionContext` */
111+
/**
112+
* Updates the current transaction with a new `TransactionContext`.
113+
* @deprecated Update the fields directly instead.
114+
*/
109115
updateWithContext(transactionContext: TransactionContext): this;
110116

111117
/**

0 commit comments

Comments
 (0)