8000 ref(tracing): Deprecate `tracingOrigins` (#6176) · getsentry/sentry-javascript@aaf48a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit aaf48a1

Browse files
authored
ref(tracing): Deprecate tracingOrigins (#6176)
1 parent b4a4342 commit aaf48a1

File tree

4 files changed

+9
-55
lines changed

4 files changed

+9
-55
lines changed

packages/nextjs/src/index.client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function init(options: NextjsOptions): void {
5959

6060
function createClientIntegrations(userIntegrations: UserIntegrations = []): UserIntegrations {
6161
const defaultBrowserTracingIntegration = new BrowserTracing({
62+
// eslint-disable-next-line deprecation/deprecation
6263
tracingOrigins: [...defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
6364
routingInstrumentation: nextRouterInstrumentation,
6465
});

packages/tracing/src/browser/browsertracing.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,10 @@ export class BrowserTracing implements Integration {
147147

148148
private _getCurrentHub?: () => Hub;
149149

150-
private readonly _emitOptionsWarning?: boolean;
151-
152150
public constructor(_options?: Partial<BrowserTracingOptions>) {
153-
let tracingOrigins = defaultRequestInstrumentationOptions.tracingOrigins;
154-
// NOTE: Logger doesn't work in constructors, as it's initialized after integrations instances
155-
if (_options) {
156-
if (_options.tracingOrigins && Array.isArray(_options.tracingOrigins)) {
157-
tracingOrigins = _options.tracingOrigins;
158-
} else {
159-
__DEBUG_BUILD__ && (this._emitOptionsWarning = true);
160-
}
161-
}
162-
163151
this.options = {
164152
...DEFAULT_BROWSER_TRACING_OPTIONS,
165153
..._options,
166-
tracingOrigins,
167154
};
168155

169156
const { _metricOptions } = this.options;
@@ -179,17 +166,6 @@ export class BrowserTracing implements Integration {
179166
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
180167
this._getCurrentHub = getCurrentHub;
181168

182-
if (this._emitOptionsWarning) {
183-
__DEBUG_BUILD__ &&
184-
logger.warn(
185-
'[Tracing] You need to define `tracingOrigins` in the options. Set an array of urls or patterns to trace.',
186-
);
187-
__DEBUG_BUILD__ &&
188-
logger.warn(
189-
`[Tracing] We added a reasonable default for you: ${defaultRequestInstrumentationOptions.tracingOrigins}`,
190-
);
191-
}
192-
193169
// eslint-disable-next-line @typescript-eslint/unbound-method
194170
const {
195171
routingInstrumentation: instrumentRouting,
@@ -198,6 +174,7 @@ export class BrowserTracing implements Integration {
198174
markBackgroundTransactions,
199175
traceFetch,
200176
traceXHR,
177+
// eslint-disable-next-line deprecation/deprecation
201178
tracingOrigins,
202179
shouldCreateSpanForRequest,
203180
} = this.options;

packages/tracing/src/browser/request.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//];
1717
/** Options for Request Instrumentation */
1818
export interface RequestInstrumentationOptions {
1919
/**
20-
* List of strings / regex where the integration should create Spans out of. Additionally this will be used
21-
* to define which outgoing requests the `sentry-trace` header will be attached to.
22-
*
23-
* Default: ['localhost', /^\//] {@see DEFAULT_TRACING_ORIGINS}
20+
* @deprecated Will be removed in v8.
21+
* Use `shouldCreateSpanForRequest` to control span creation and `tracePropagationTargets` to control
22+
* trace header attachment.
2423
*/
2524
tracingOrigins: Array<string | RegExp>;
2625

@@ -50,7 +49,7 @@ export interface RequestInstrumentationOptions {
5049
* This function will be called before creating a span for a request with the given url.
5150
* Return false if you don't want a span for the given url.
5251
*
53-
* By default it uses the `tracingOrigins` options as a url match.
52+
* Default: (url: string) => true
5453
*/
5554
shouldCreateSpanForRequest?(url: string): boolean;
5655
}
@@ -114,6 +113,7 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
114113

115114
/** Registers span creators for xhr and fetch requests */
116115
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
116+
// eslint-disable-next-line deprecation/deprecation
117117
const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets, shouldCreateSpanForRequest } = {
118118
...defaultRequestInstrumentationOptions,
119119
..._options,

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ jest.mock('@sentry/utils', () => {
3434

3535
jest.mock('../../src/browser/metrics');
3636

37-
const { logger } = jest.requireActual('@sentry/utils');
38-
const warnSpy = jest.spyOn(logger, 'warn');
39-
4037
beforeAll(() => {
4138
const dom = new JSDOM();
4239
// @ts-ignore need to override global document
@@ -55,8 +52,6 @@ describe('BrowserTracing', () => {
5552
hub = new Hub(new BrowserClient(options));
5653
makeMain(hub);
5754
document.head.innerHTML = '';
58-
59-
warnSpy.mockClear();
6055
});
6156

6257
afterEach(() => {
@@ -134,33 +129,14 @@ describe('BrowserTracing', () => {
134129
});
135130

136131
describe('tracingOrigins', () => {
137-
it('warns and uses default tracing origins if none are provided', () => {
138-
const inst = createBrowserTracing(true, {
139-
routingInstrumentation: customInstrumentRouting,
140-
});
141-
142-
expect(warnSpy).toHaveBeenCalledTimes(2);
143-
expect(inst.options.tracingOrigins).toEqual(defaultRequestInstrumentationOptions.tracingOrigins);
144-
});
145-
146-
it('warns and uses default tracing origins if tracing origins are not defined', () => {
147-
const inst = createBrowserTracing(true, {
148-
routingInstrumentation: customInstrumentRouting,
149-
tracingOrigins: undefined,
150-
});
151-
152-
expect(warnSpy).toHaveBeenCalledTimes(2);
153-
expect(inst.options.tracingOrigins).toEqual(defaultRequestInstrumentationOptions.tracingOrigins);
154-
});
155-
156132
it('sets tracing origins if provided and does not warn', () => {
157133
const sampleTracingOrigins = ['something'];
158134
const inst = createBrowserTracing(true, {
159135
routingInstrumentation: customInstrumentRouting,
160136
tracingOrigins: sampleTracingOrigins,
161137
});
162138

163-
expect(warnSpy).toHaveBeenCalledTimes(0);
139+
// eslint-disable-next-line deprecation/deprecation
164140
expect(inst.options.tracingOrigins).toEqual(sampleTracingOrigins);
165141
});
166142

@@ -171,7 +147,7 @@ describe('BrowserTracing', () => {
171147
tracingOrigins: sampleTracingOrigins,
172148
});
173149

174-
expect(warnSpy).toHaveBeenCalledTimes(0);
150+
// eslint-disable-next-line deprecation/deprecation
175151
expect(inst.options.tracingOrigins).toEqual(sampleTracingOrigins);
176152
});
177153
});

0 commit comments

Comments
 (0)
0