Skip to content

Commit 16c4dbe

Browse files
authored
feat(core): Deprecate span toContext() and updateWithContext() (#10030)
These APIs are not really used, and are not compatible with OpenTelemetry. So let's deprecate them for removal in v8. Unless somebody knows a reason why we still need something like this?
1 parent f127479 commit 16c4dbe

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

MIGRATION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ npx @sentry/migr8@latest
88

99
This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes!
1010

11+
## Deprecated fields on `Span` and `Transaction`
12+
13+
In v8, the Span class is heavily reworked. The following properties & methods are thus deprecated:
14+
15+
* `span.toContext()`: Access the fields directly instead.
16+
* `span.updateWithContext(newSpanContext)`: Update the fields directly instead.
17+
1118
## Deprecate `pushScope` & `popScope` in favor of `withScope`
1219

1320
Instead of manually pushing/popping a scope, you should use `Sentry.withScope(callback: (scope: Scope))` instead.

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/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)