Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Deprecate span toContext() and updateWithContext() #10030

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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