Skip to content

ref(v8): Remove deprecated span & transaction properties #11400

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

Merged
merged 1 commit into from
Apr 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type {
SpanOrigin,
SpanStatus,
SpanTimeInput,
TraceContext,
Transaction,
} from '@sentry/types';
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
import { getClient } from '../currentScopes';
Expand All @@ -25,18 +23,12 @@ import {
getStatusMessage,
spanTimeInputToSeconds,
spanToJSON,
spanToTraceContext,
} from '../utils/spanUtils';

/**
* Span contains all data about a span
*/
export class SentrySpan implements Span {
/**
* @inheritDoc
* @deprecated Use top level `Sentry.getRootSpan()` instead
*/
public transaction?: Transaction;
protected _traceId: string;
protected _spanId: string;
protected _parentSpanId?: string | undefined;
Expand Down Expand Up @@ -85,43 +77,6 @@ export class SentrySpan implements Span {
}
}

// This rule conflicts with another eslint rule :(
/* eslint-disable @typescript-eslint/member-ordering */

/**
* Timestamp in seconds (epoch time) indicating when the span started.
* @deprecated Use `spanToJSON()` instead.
*/
public get startTimestamp(): number {
return this._startTime;
}

/**
* Timestamp in seconds (epoch time) indicating when the span started.
* @deprecated In v8, you will not be able to update the span start time after creation.
*/
public set startTimestamp(startTime: number) {
this._startTime = startTime;
}

/**
* Timestamp in seconds when the span ended.
* @deprecated Use `spanToJSON()` instead.
*/
public get endTimestamp(): number | undefined {
return this._endTime;
}

/**
* Timestamp in seconds when the span ended.
* @deprecated Set the end time via `span.end()` instead.
*/
public set endTimestamp(endTime: number | undefined) {
this._endTime = endTime;
}

/* eslint-enable @typescript-eslint/member-ordering */

/** @inheritdoc */
public spanContext(): SpanContextData {
const { _spanId: spanId, _traceId: traceId, _sampled: sampled } = this;
Expand Down Expand Up @@ -157,10 +112,6 @@ export class SentrySpan implements Span {
addChildSpanToSpan(this, childSpan);

const rootSpan = getRootSpan(this);
// TODO: still set span.transaction here until we have a more permanent solution
// Probably similarly to the weakmap we hold in node
// eslint-disable-next-line deprecation/deprecation
childSpan.transaction = rootSpan as Transaction;

if (DEBUG_BUILD && rootSpan) {
const opStr = (spanContext && spanContext.op) || '< unknown op >';
Expand Down Expand Up @@ -251,35 +202,6 @@ export class SentrySpan implements Span {
this._onSpanEnded();
}

/**
* @inheritDoc
*
* @deprecated Use `spanToJSON()` or access the fields directly instead.
*/
public toContext(): SentrySpanArguments {
return dropUndefinedKeys({
data: this._attributes,
name: this._name,
endTimestamp: this._endTime,
op: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],
parentSpanId: this._parentSpanId,
sampled: this._sampled,
spanId: this._spanId,
startTimestamp: this._startTime,
status: this._status,
traceId: this._traceId,
});
}

/**
* @inheritDoc
*
* @deprecated Use `spanToTraceContext()` util function instead.
*/
public getTraceContext(): TraceContext {
return spanToTraceContext(this);
}

/**
* Get JSON representation of this span.
*
Expand Down Expand Up @@ -309,14 +231,6 @@ export class SentrySpan implements Span {
return !this._endTime && !!this._sampled;
}

/**
* Convert the object to JSON.
* @deprecated Use `spanToJSON(span)` instead.
*/
public toJSON(): SpanJSON {
return this.getSpanJSON();
}

/** Emit `spanEnd` when the span is ended. */
private _onSpanEnded(): void {
const client = getClient();
Expand Down
54 changes: 0 additions & 54 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
Context,
Contexts,
DynamicSamplingContext,
Hub,
Expand Down Expand Up @@ -74,11 +73,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
...this._attributes,
};

// this is because transactions are also spans, and spans have a transaction pointer
// TODO (v8): Replace this with another way to set the root span
// eslint-disable-next-line deprecation/deprecation
this.transaction = this;

// If Dynamic Sampling Context is provided during the creation of the transaction, we freeze it as it usually means
// there is incoming Dynamic Sampling Context. (Either through an incoming request, a baggage meta-tag, or other means)
const incomingDynamicSamplingContext = this._metadata.dynamicSamplingContext;
Expand Down Expand Up @@ -124,19 +118,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
return this;
}

/**
* Set the context of a transaction event.
* @deprecated Use either `.setAttribute()`, or set the context on the scope before creating the transaction.
*/
public setContext(key: string, context: Context | null): void {
if (context === null) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this._contexts[key];
} else {
this._contexts[key] = context;
}
}

/**
* @inheritDoc
*
Expand Down Expand Up @@ -167,41 +148,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
return this._hub.captureEvent(transaction);
}

/**
* @inheritDoc
*/
public toContext(): TransactionArguments {
// eslint-disable-next-line deprecation/deprecation
const spanContext = super.toContext();

return dropUndefinedKeys({
...spanContext,
name: this._name,
trimEnd: this._trimEnd,
});
}

/**
* @inheritdoc
*
* @experimental
*
* @deprecated Use top-level `getDynamicSamplingContextFromSpan` instead.
*/
public getDynamicSamplingContext(): Readonly<Partial<DynamicSamplingContext>> {
return getDynamicSamplingContextFromSpan(this);
}

/**
* Override the current hub with a new one.
* Used if you want another hub to finish the transaction.
*
* @internal
*/
public setHub(hub: Hub): void {
this._hub = hub;
}

/**
* Finish the transaction & prepare the event to send to Sentry.
*/
Expand Down
25 changes: 0 additions & 25 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Context } from './context';
import type { DynamicSamplingContext } from './envelope';
import type { MeasurementUnit } from './measurement';
import type { ExtractedNodeRequestData, WorkerLocation } from './misc';
Expand Down Expand Up @@ -58,23 +57,12 @@ export interface TraceparentData {
* Transaction "Class", inherits Span only has `setName`
*/
export interface Transaction extends Omit<TransactionArguments, 'name' | 'op' | 'spanId' | 'traceId'>, Span {
/**
* @inheritDoc
*/
startTimestamp: number;

/**
* Metadata about the transaction.
* @deprecated Use attributes or store data on the scope instead.
*/
metadata: TransactionMetadata;

/**
* Set the context of a transaction event.
* @deprecated Use either `.setAttribute()`, or set the context on the scope before creating the transaction.
*/
setContext(key: string, context: Context): void;

/**
* Set observed measurement for this transaction.
*
Expand All @@ -86,25 +74,12 @@ export interface Transaction extends Omit<TransactionArguments, 'name' | 'op' |
*/
setMeasurement(name: string, value: number, unit: MeasurementUnit): void;

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

/**
* Set metadata for this transaction.
* @deprecated Use attributes or store data on the scope instead.
*/
setMetadata(newMetadata: Partial<TransactionMetadata>): void;

/**
* Return the current Dynamic Sampling Context of this transaction
*
* @deprecated Use top-level `getDynamicSamplingContextFromSpan` instead.
*/
getDynamicSamplingContext(): Partial<DynamicSamplingContext>;

/**
* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
* Also the `sampled` decision will be inherited.
Expand Down