Skip to content

Commit b18cd37

Browse files
committed
remove default beforeNavigate
1 parent 5855f26 commit b18cd37

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
registerRequestInstrumentation,
1414
RequestInstrumentationOptions,
1515
} from './request';
16-
import { defaultBeforeNavigate, defaultRoutingInstrumentation } from './router';
16+
import { defaultRoutingInstrumentation } from './router';
1717

1818
export const DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600;
1919

@@ -66,7 +66,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
6666
*
6767
* If undefined is returned, a pageload/navigation transaction will not be created.
6868
*/
69-
beforeNavigate(context: TransactionContext): TransactionContext | undefined;
69+
beforeNavigate?(context: TransactionContext): TransactionContext | undefined;
7070

7171
/**
7272
* Instrumentation that creates routing change transactions. By default creates
@@ -80,7 +80,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
8080
}
8181

8282
const DEFAULT_BROWSER_TRACING_OPTIONS = {
83-
beforeNavigate: defaultBeforeNavigate,
8483
idleTimeout: DEFAULT_IDLE_TIMEOUT,
8584
markBackgroundTransactions: true,
8685
maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,
@@ -189,20 +188,21 @@ export class BrowserTracing implements Integration {
189188
const { beforeNavigate, idleTimeout, maxTransactionDuration } = this.options;
190189

191190
// if beforeNavigate returns undefined, we should not start a transaction.
192-
const ctx = beforeNavigate({
191+
const expandedContext = {
193192
...context,
194193
...getHeaderContext(),
195194
trimEnd: true,
196-
});
195+
};
196+
const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext;
197197

198-
if (ctx === undefined) {
198+
if (modifiedContext === undefined) {
199199
logger.log(`[Tracing] Did not create ${context.op} idleTransaction due to beforeNavigate`);
200200
return undefined;
201201
}
202202

203203
const hub = this._getCurrentHub();
204-
logger.log(`[Tracing] starting ${ctx.op} idleTransaction on scope`);
205-
const idleTransaction = startIdleTransaction(hub, ctx, idleTimeout, true);
204+
logger.log(`[Tracing] starting ${modifiedContext.op} idleTransaction on scope`);
205+
const idleTransaction = startIdleTransaction(hub, modifiedContext, idleTimeout, true);
206206
idleTransaction.registerBeforeFinishCallback((transaction, endTimestamp) => {
207207
this._metrics.addPerformanceEntries(transaction);
208208
adjustTransactionDuration(secToMs(maxTransactionDuration), transaction, endTimestamp);

packages/tracing/src/browser/router.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,3 @@ export function defaultRoutingInstrumentation<T extends TransactionType>(
5454
});
5555
}
5656
}
57-
58-
/** default implementation of Browser Tracing before navigate */
59-
export function defaultBeforeNavigate(context: TransactionContext): TransactionContext | undefined {
60-
return context;
61-
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ describe('BrowserTracing', () => {
7676
const browserTracing = createBrowserTracing();
7777

7878
expect(browserTracing.options).toEqual({
79-
beforeNavigate: expect.any(Function),
8079
idleTimeout: DEFAULT_IDLE_TIMEOUT,
8180
markBackgroundTransactions: true,
8281
maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,

packages/tracing/test/browser/router.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from 'jsdom';
22

3-
import { defaultBeforeNavigate, defaultRoutingInstrumentation } from '../../src/browser/router';
3+
import { defaultRoutingInstrumentation } from '../../src/browser/router';
44

55
let mockChangeHistory: ({ to, from }: { to: string; from?: string }) => void = () => undefined;
66
let addInstrumentationHandlerType: string = '';
@@ -15,13 +15,6 @@ jest.mock('@sentry/utils', () => {
1515
};
1616
});
1717

18-
describe('defaultBeforeNavigate()', () => {
19-
it('returns a context', () => {
20-
const ctx = { name: 'testing', status: 'ok' };
21-
expect(defaultBeforeNavigate(ctx)).toBe(ctx);
22-
});
23-
});
24-
2518
describe('defaultRoutingInstrumentation', () => {
2619
const mockFinish = jest.fn();
2720
const startTransaction = jest.fn().mockReturnValue({ finish: mockFinish });

0 commit comments

Comments
 (0)