Skip to content

Commit

Permalink
feat(core): Deprecate span toContext() and updateWithContext() (#…
Browse files Browse the repository at this point in the history
…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?
  • Loading branch information
mydea authored Jan 3, 2024
1 parent f127479 commit 16c4dbe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ npx @sentry/migr8@latest

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

## Deprecated fields on `Span` and `Transaction`

In v8, the Span class is heavily reworked. The following properties & methods are thus deprecated:

* `span.toContext()`: Access the fields directly instead.
* `span.updateWithContext(newSpanContext)`: Update the fields directly instead.

## Deprecate `pushScope` & `popScope` in favor of `withScope`

Instead of manually pushing/popping a scope, you should use `Sentry.withScope(callback: (scope: Scope))` instead.
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
* @inheritDoc
*/
public toContext(): TransactionContext {
// eslint-disable-next-line deprecation/deprecation
const spanContext = super.toContext();

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

this.name = transactionContext.name || '';
Expand Down
10 changes: 8 additions & 2 deletions packages/types/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,16 @@ export interface Span extends SpanContext {
/** Return a traceparent compatible header string */
toTraceparent(): string;

/** Returns the current span properties as a `SpanContext` */
/**
* Returns the current span properties as a `SpanContext`.
* @deprecated Use `toJSON()` or access the fields directly instead.
*/
toContext(): SpanContext;

/** Updates the current span with a new `SpanContext` */
/**
* Updates the current span with a new `SpanContext`.
* @deprecated Update the fields directly instead.
*/
updateWithContext(spanContext: SpanContext): this;

/** Convert the object to JSON for w. spans array info only */
Expand Down
10 changes: 8 additions & 2 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@ export interface Transaction extends TransactionContext, Omit<Span, 'setName' |
*/
setMeasurement(name: string, value: number, unit: MeasurementUnit): void;

/** Returns the current transaction properties as a `TransactionContext` */
/**
* Returns the current transaction properties as a `TransactionContext`.
* @deprecated Use `toJSON()` or access the fields directly instead.
*/
toContext(): TransactionContext;

/** Updates the current transaction with a new `TransactionContext` */
/**
* Updates the current transaction with a new `TransactionContext`.
* @deprecated Update the fields directly instead.
*/
updateWithContext(transactionContext: TransactionContext): this;

/**
Expand Down

0 comments on commit 16c4dbe

Please sign in to comment.