Skip to content

Commit 00071fd

Browse files
committed
Revert "feat(tracing): Deprecate transaction-related options for BrowserTracing (#10303)"
This reverts commit 3b4650c.
1 parent 10345d4 commit 00071fd

File tree

6 files changed

+196
-326
lines changed

6 files changed

+196
-326
lines changed

MIGRATION.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ npx @sentry/migr8@latest
1010
This will let you select which updates to run, and automatically update your code. Make sure to still review all code
1111
changes!
1212

13-
## Deprecate transaction-related options to `BrowserTracing`
14-
15-
When configuring the `BrowserTracing` integration, some options have been renamed:
16-
17-
- `startTransactionOnPageLoad` --> `spanOnPageLoad`
18-
- `startTransactionOnLocationChange` --> `spanOnLocationChange`
19-
- `markBackgroundTransactions` --> `markBackgroundSpan`
20-
21-
Also, `beforeNavigate` is replaced with a `beforeStartSpan` callback, which receives `StartSpanOptions`.
22-
2313
## Deprecate using `getClient()` to check if the SDK was initialized
2414

2515
In v8, `getClient()` will stop returning `undefined` if `Sentry.init()` was not called. For cases where this may be used

packages/core/src/tracing/trace.ts

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types';
2-
1+
import type {
2+
Instrumenter,
3+
Primitive,
4+
Scope,
5+
Span,
6+
SpanTimeInput,
7+
TransactionContext,
8+
TransactionMetadata,
9+
} from '@sentry/types';
10+
import type { SpanAttributes } from '@sentry/types';
11+
import type { SpanOrigin } from '@sentry/types';
12+
import type { TransactionSource } from '@sentry/types';
313
import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils';
414

515
import { DEBUG_BUILD } from '../debug-build';
@@ -10,6 +20,105 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors';
1020
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
1121
import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
1222

23+
interface StartSpanOptions extends TransactionContext {
24+
/** A manually specified start time for the created `Span` object. */
25+
startTime?: SpanTimeInput;
26+
27+
/** If defined, start this span off this scope instead off the current scope. */
28+
scope?: Scope;
29+
30+
/** The name of the span. */
31+
name: string;
32+
33+
/** An op for the span. This is a categorization for spans. */
34+
op?: string;
35+
36+
/** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */
37+
origin?: SpanOrigin;
38+
39+
/** Attributes for the span. */
40+
attributes?: SpanAttributes;
41+
42+
// All remaining fields are deprecated
43+
44+
/**
45+
* @deprecated Manually set the end timestamp instead.
46+
*/
47+
trimEnd?: boolean;
48+
49+
/**
50+
* @deprecated This cannot be set manually anymore.
51+
*/
52+
parentSampled?: boolean;
53+
54+
/**
55+
* @deprecated Use attributes or set data on scopes instead.
56+
*/
57+
metadata?: Partial<TransactionMetadata>;
58+
59+
/**
60+
* The name thingy.
61+
* @deprecated Use `name` instead.
62+
*/
63+
description?: string;
64+
65+
/**
66+
* @deprecated Use `span.setStatus()` instead.
67+
*/
68+
status?: string;
69+
70+
/**
71+
* @deprecated Use `scope` instead.
72+
*/
73+
parentSpanId?: string;
74+
75+
/**
76+
* @deprecated You cannot manually set the span to sampled anymore.
77+
*/
78+
sampled?: boolean;
79+
80+
/**
81+
* @deprecated You cannot manually set the spanId anymore.
82+
*/
83+
spanId?: string;
84+
85+
/**
86+
* @deprecated You cannot manually set the traceId anymore.
87+
*/
88+
traceId?: string;
89+
90+
/**
91+
* @deprecated Use an attribute instead.
92+
*/
93+
source?: TransactionSource;
94+
95+
/**
96+
* @deprecated Use attributes or set tags on the scope instead.
97+
*/
98+
tags?: { [key: string]: Primitive };
99+
100+
/**
101+
* @deprecated Use attributes instead.
102+
*/
103+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
104+
data?: { [key: string]: any };
105+
106+
/**
107+
* @deprecated Use `startTime` instead.
108+
*/
109+
startTimestamp?: number;
110+
111+
/**
112+
* @deprecated Use `span.end()` instead.
113+
*/
114+
endTimestamp?: number;
115+
116+
/**
117+
* @deprecated You cannot set the instrumenter manually anymore.
118+
*/
119+
instrumenter?: Instrumenter;
120+
}
121+
13122
/**
14123
* Wraps a function with a transaction/span and finishes the span after the function is done.
15124
*

packages/tracing-internal/src/browser/browsertracing.ts

Lines changed: 30 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable max-lines, complexity */
1+
/* eslint-disable max-lines */
22
import type { Hub, IdleTransaction } from '@sentry/core';
33
import {
44
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -9,14 +9,7 @@ import {
99
spanToJSON,
1010
startIdleTransaction,
1111
} from '@sentry/core';
12-
import type {
13-
EventProcessor,
14-
Integration,
15-
StartSpanOptions,
16-
Transaction,
17-
TransactionContext,
18-
TransactionSource,
19-
} from '@sentry/types';
12+
import type { EventProcessor, Integration, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
2013
import { getDomElement, logger, tracingContextFromHeaders } from '@sentry/utils';
2114

2215
import { DEBUG_BUILD } from '../common/debug-build';
@@ -66,49 +59,28 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
6659
*/
6760
heartbeatInterval: number;
6861

69-
/**
70-
* If a span should be created on location (history) changes.
71-
* Default: true
72-
*/
73-
spanOnLocationChange: boolean;
74-
75-
/**
76-
* If a span should be created on pageload.
77-
* Default: true
78-
*/
79-
spanOnPageLoad: boolean;
80-
81-
/**
82-
* Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
83-
* not suited towards doing precise measurements of operations. By default, we recommend that this option
84-
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
85-
*
86-
* Default: true
87-
*/
88-
markBackgroundSpan: boolean;
89-
9062
/**
9163
* Flag to enable/disable creation of `navigation` transaction on history changes.
64+
*
9265
* Default: true
93-
* @deprecated Configure `spanOnLocationChange` instead.
9466
*/
95-
startTransactionOnLocationChange?: boolean;
67+
startTransactionOnLocationChange: boolean;
9668

9769
/**
9870
* Flag to enable/disable creation of `pageload` transaction on first pageload.
71+
*
9972
* Default: true
100-
* @deprecated Configure `spanOnPageLoad` instead.
10173
*/
102-
startTransactionOnPageLoad?: boolean;
74+
startTransactionOnPageLoad: boolean;
10375

10476
/**
10577
* Flag Transactions where tabs moved to background with "cancelled". Browser background tab timing is
10678
* not suited towards doing precise measurements of operations. By default, we recommend that this option
10779
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
80+
*
10881
* Default: true
109-
* @deprecated Configure `markBackgroundSpan` instead.
11082
*/
111-
markBackgroundTransactions?: boolean;
83+
markBackgroundTransactions: boolean;
11284

11385
/**
11486
* If true, Sentry will capture long tasks and add them to the corresponding transaction.
@@ -145,12 +117,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
145117
onStartRouteTransaction: (t: Transaction | undefined, ctx: TransactionContext, getCurrentHub: () => Hub) => void;
146118
}>;
147119

148-
/**
149-
* A callback which is called before a span for a pageload or navigation is started.
150-
* It receives the options passed to `startSpan`, and expects to return an updated options object.
151-
*/
152-
beforeStartSpan?: (options: StartSpanOptions) => StartSpanOptions;
153-
154120
/**
155121
* beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction
156122
* context data, or drop the transaction entirely (by setting `sampled = false` in the context).
@@ -160,8 +126,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
160126
* @param context: The context data which will be passed to `startTransaction` by default
161127
*
162128
* @returns A (potentially) modified context object, with `sampled = false` if the transaction should be dropped.
163-
*
164-
* @deprecated Use `beforeStartSpan` instead.
165129
*/
166130
beforeNavigate?(this: void, context: TransactionContext): TransactionContext | undefined;
167131

@@ -179,10 +143,10 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
179143

180144
const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
181145
...TRACING_DEFAULTS,
146+
markBackgroundTransactions: true,
182147
routingInstrumentation: instrumentRoutingWithDefaults,
183-
spanOnLocationChange: true,
184-
spanOnPageLoad: true,
185-
markBackgroundSpan: true,
148+
startTransactionOnLocationChange: true,
149+
startTransactionOnPageLoad: true,
186150
enableLongTask: true,
187151
_experiments: {},
188152
...defaultRequestInstrumentationOptions,
@@ -226,42 +190,20 @@ export class BrowserTracing implements Integration {
226190

227191
private _hasSetTracePropagationTargets: boolean;
228192

229-
public constructor(_options: Partial<BrowserTracingOptions> = {}) {
193+
public constructor(_options?: Partial<BrowserTracingOptions>) {
230194
this.name = BROWSER_TRACING_INTEGRATION_ID;
231195
this._hasSetTracePropagationTargets = false;
232196

233197
addTracingExtensions();
234198

235199
if (DEBUG_BUILD) {
236200
this._hasSetTracePropagationTargets = !!(
201+
_options &&
237202
// eslint-disable-next-line deprecation/deprecation
238203
(_options.tracePropagationTargets || _options.tracingOrigins)
239204
);
240205
}
241206

242-
// Migrate legacy options
243-
// TODO v8: Remove this
244-
/* eslint-disable deprecation/deprecation */
245-
if (typeof _options.startTransactionOnPageLoad === 'boolean') {
246-
_options.spanOnPageLoad = _options.startTransactionOnPageLoad;
247-
}
248-
if (typeof _options.startTransactionOnLocationChange === 'boolean') {
249-
_options.spanOnLocationChange = _options.startTransactionOnLocationChange;
250-
}
251-
if (typeof _options.markBackgroundTransactions === 'boolean') {
252-
_options.markBackgroundSpan = _options.markBackgroundTransactions;
253-
}
254-
/* eslint-enable deprecation/deprecation */
255-
256-
// TODO (v8): remove this block after tracingOrigins is removed
257-
// Set tracePropagationTargets to tracingOrigins if specified by the user
258-
// In case both are specified, tracePropagationTargets takes precedence
259-
// eslint-disable-next-line deprecation/deprecation
260-
if (!_options.tracePropagationTargets && _options.tracingOrigins) {
261-
// eslint-disable-next-line deprecation/deprecation
262-
_options.tracePropagationTargets = _options.tracingOrigins;
263-
}
264-
265207
this.options = {
266208
...DEFAULT_BROWSER_TRACING_OPTIONS,
267209
..._options,
@@ -273,6 +215,15 @@ export class BrowserTracing implements Integration {
273215
this.options.enableLongTask = this.options._experiments.enableLongTask;
274216
}
275217

218+
// TODO (v8): remove this block after tracingOrigins is removed
219+
// Set tracePropagationTargets to tracingOrigins if specified by the user
220+
// In case both are specified, tracePropagationTargets takes precedence
221+
// eslint-disable-next-line deprecation/deprecation
222+
if (_options && !_options.tracePropagationTargets && _options.tracingOrigins) {
223+
// eslint-disable-next-line deprecation/deprecation
224+
this.options.tracePropagationTargets = _options.tracingOrigins;
225+
}
226+
276227
this._collectWebVitals = startTrackingWebVitals();
277228
if (this.options.enableLongTask) {
278229
startTrackingLongTasks();
@@ -294,9 +245,9 @@ export class BrowserTracing implements Integration {
294245

295246
const {
296247
routingInstrumentation: instrumentRouting,
297-
spanOnPageLoad,
298-
spanOnLocationChange,
299-
markBackgroundSpan,
248+
startTransactionOnLocationChange,
249+
startTransactionOnPageLoad,
250+
markBackgroundTransactions,
300251
traceFetch,
301252
traceXHR,
302253
shouldCreateSpanForRequest,
@@ -332,11 +283,11 @@ export class BrowserTracing implements Integration {
332283

333284
return transaction;
334285
},
335-
spanOnPageLoad,
336-
spanOnLocationChange,
286+
startTransactionOnPageLoad,
287+
startTransactionOnLocationChange,
337288
);
338289

339-
if (markBackgroundSpan) {
290+
if (markBackgroundTransactions) {
340291
registerBackgroundTabDetection();
341292
}
342293

@@ -363,14 +314,7 @@ export class BrowserTracing implements Integration {
363314

364315
const hub = this._getCurrentHub();
365316

366-
const {
367-
// eslint-disable-next-line deprecation/deprecation
368-
beforeNavigate,
369-
beforeStartSpan,
370-
idleTimeout,
371-
finalTimeout,
372-
heartbeatInterval,
373-
} = this.options;
317+
const { beforeNavigate, idleTimeout, finalTimeout, heartbeatInterval } = this.options;
374318

375319
const isPageloadTransaction = context.op === 'pageload';
376320

@@ -392,11 +336,7 @@ export class BrowserTracing implements Integration {
392336
trimEnd: true,
393337
};
394338

395-
const contextAfterProcessing = beforeStartSpan ? beforeStartSpan(expandedContext) : expandedContext;
396-
397-
const modifiedContext =
398-
// eslint-disable-next-line deprecation/deprecation
399-
typeof beforeNavigate === 'function' ? beforeNavigate(contextAfterProcessing) : contextAfterProcessing;
339+
const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext;
400340

401341
// For backwards compatibility reasons, beforeNavigate can return undefined to "drop" the transaction (prevent it
402342
// from being sent to Sentry).

0 commit comments

Comments
 (0)