Skip to content

Commit 3eb9e05

Browse files
authored
ref(tracing): Clarify naming in BrowserTracing integration (#3338)
1 parent 77b8301 commit 3eb9e05

File tree

13 files changed

+84
-85
lines changed

13 files changed

+84
-85
lines changed

packages/angular/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ Registering a Trace Service is a 3-step process.
8282
instrumentation:
8383

8484
```javascript
85-
import { init, routingInstrumentation } from '@sentry/angular';
85+
import { init, instrumentAngularRouting } from '@sentry/angular';
8686
import { Integrations as TracingIntegrations } from '@sentry/tracing';
8787

8888
init({
8989
dsn: '__DSN__',
9090
integrations: [
9191
new TracingIntegrations.BrowserTracing({
9292
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
93-
routingInstrumentation: routingInstrumentation,
93+
routingInstrumentation: instrumentAngularRouting,
9494
}),
9595
],
9696
tracesSampleRate: 1,

packages/angular/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export { init } from './sdk';
44
export { createErrorHandler, ErrorHandlerOptions } from './errorhandler';
55
export {
66
getActiveTransaction,
7-
routingInstrumentation,
7+
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point
8+
instrumentAngularRouting, // new name
9+
routingInstrumentation, // legacy name
810
TraceClassDecorator,
911
TraceMethodDecorator,
1012
TraceDirective,

packages/angular/src/tracing.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ let stashedStartTransactionOnLocationChange: boolean;
1414
* Creates routing instrumentation for Angular Router.
1515
*/
1616
export function routingInstrumentation(
17-
startTransaction: (context: TransactionContext) => Transaction | undefined,
17+
customStartTransaction: (context: TransactionContext) => Transaction | undefined,
1818
startTransactionOnPageLoad: boolean = true,
1919
startTransactionOnLocationChange: boolean = true,
2020
): void {
2121
instrumentationInitialized = true;
22-
stashedStartTransaction = startTransaction;
22+
stashedStartTransaction = customStartTransaction;
2323
stashedStartTransactionOnLocationChange = startTransactionOnLocationChange;
2424

2525
if (startTransactionOnPageLoad) {
26-
startTransaction({
26+
customStartTransaction({
2727
name: window.location.pathname,
2828
op: 'pageload',
2929
});
3030
}
3131
}
3232

33+
export const instrumentAngularRouting = routingInstrumentation;
34+
3335
/**
3436
* Grabs active transaction off scope
3537
*/

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance)
337337
sentryConfig['integrations'] = [
338338
...existingIntegrations,
339339
new tracing.Integrations.BrowserTracing({
340-
routingInstrumentation: (startTransaction, startTransactionOnPageLoad) => {
340+
routingInstrumentation: (customStartTransaction, startTransactionOnPageLoad) => {
341341
const routerMain = appInstance.lookup('router:main');
342342
const routerService = appInstance.lookup('service:router');
343-
_instrumentEmberRouter(routerService, routerMain, config, startTransaction, startTransactionOnPageLoad);
343+
_instrumentEmberRouter(routerService, routerMain, config, customStartTransaction, startTransactionOnPageLoad);
344344
},
345345
idleTimeout,
346346
}),

packages/react/src/reactrouter.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ export function reactRouterV4Instrumentation(
4747
routes?: RouteConfig[],
4848
matchPath?: MatchPath,
4949
): ReactRouterInstrumentation {
50-
return reactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
50+
return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
5151
}
5252

5353
export function reactRouterV5Instrumentation(
5454
history: RouterHistory,
5555
routes?: RouteConfig[],
5656
matchPath?: MatchPath,
5757
): ReactRouterInstrumentation {
58-
return reactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
58+
return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
5959
}
6060

61-
function reactRouterInstrumentation(
61+
function createReactRouterInstrumentation(
6262
history: RouterHistory,
6363
name: string,
6464
allRoutes: RouteConfig[] = [],
6565
matchPath?: MatchPath,
6666
): ReactRouterInstrumentation {
67-
function getName(pathname: string): string {
67+
function getTransactionName(pathname: string): string {
6868
if (allRoutes === [] || !matchPath) {
6969
return pathname;
7070
}
@@ -80,10 +80,10 @@ function reactRouterInstrumentation(
8080
return pathname;
8181
}
8282

83-
return (startTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {
83+
return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {
8484
if (startTransactionOnPageLoad && global && global.location) {
85-
activeTransaction = startTransaction({
86-
name: getName(global.location.pathname),
85+
activeTransaction = customStartTransaction({
86+
name: getTransactionName(global.location.pathname),
8787
op: 'pageload',
8888
tags: {
8989
'routing.instrumentation': name,
@@ -101,8 +101,8 @@ function reactRouterInstrumentation(
101101
'routing.instrumentation': name,
102102
};
103103

104-
activeTransaction = startTransaction({
105-
name: getName(location.pathname),
104+
activeTransaction = customStartTransaction({
105+
name: getTransactionName(location.pathname),
106106
op: 'navigation',
107107
tags,
108108
});

packages/tracing/src/browser/browsertracing.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { registerBackgroundTabDetection } from './backgroundtab';
1010
import { MetricsInstrumentation } from './metrics';
1111
import {
1212
defaultRequestInstrumentationOptions,
13-
registerRequestInstrumentation,
13+
instrumentOutgoingRequests,
1414
RequestInstrumentationOptions,
1515
} from './request';
16-
import { defaultRoutingInstrumentation } from './router';
16+
import { instrumentRoutingWithDefaults } from './router';
1717

1818
export const DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600;
1919

@@ -77,7 +77,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7777
* pageload and navigation transactions.
7878
*/
7979
routingInstrumentation<T extends Transaction>(
80-
startTransaction: (context: TransactionContext) => T | undefined,
80+
customStartTransaction: (context: TransactionContext) => T | undefined,
8181
startTransactionOnPageLoad?: boolean,
8282
startTransactionOnLocationChange?: boolean,
8383
): void;
@@ -87,7 +87,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS = {
8787
idleTimeout: DEFAULT_IDLE_TIMEOUT,
8888
markBackgroundTransactions: true,
8989
maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,
90-
routingInstrumentation: defaultRoutingInstrumentation,
90+
routingInstrumentation: instrumentRoutingWithDefaults,
9191
startTransactionOnLocationChange: true,
9292
startTransactionOnPageLoad: true,
9393
...defaultRequestInstrumentationOptions,
@@ -158,7 +158,7 @@ export class BrowserTracing implements Integration {
158158

159159
// eslint-disable-next-line @typescript-eslint/unbound-method
160160
const {
161-
routingInstrumentation,
161+
routingInstrumentation: instrumentRouting,
162162
startTransactionOnLocationChange,
163163
startTransactionOnPageLoad,
164164
markBackgroundTransactions,
@@ -168,7 +168,7 @@ export class BrowserTracing implements Integration {
168168
shouldCreateSpanForRequest,
169169
} = this.options;
170170

171-
routingInstrumentation(
171+
instrumentRouting(
172172
(context: TransactionContext) => this._createRouteTransaction(context),
173173
startTransactionOnPageLoad,
174174
startTransactionOnLocationChange,
@@ -178,7 +178,7 @@ export class BrowserTracing implements Integration {
178178
registerBackgroundTabDetection();
179179
}
180180

181-
registerRequestInstrumentation({ traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest });
181+
instrumentOutgoingRequests({ traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest });
182182
}
183183

184184
/** Create routing idle transaction. */

packages/tracing/src/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { BrowserTracing } from './browsertracing';
22
export {
3-
registerRequestInstrumentation,
3+
instrumentOutgoingRequests,
44
RequestInstrumentationOptions,
55
defaultRequestInstrumentationOptions,
66
} from './request';

packages/tracing/src/browser/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
8383
};
8484

8585
/** Registers span creators for xhr and fetch requests */
86-
export function registerRequestInstrumentation(_options?: Partial<RequestInstrumentationOptions>): void {
86+
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
8787
// eslint-disable-next-line @typescript-eslint/unbound-method
8888
const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
8989
...defaultRequestInstrumentationOptions,

packages/tracing/src/browser/router.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const global = getGlobalObject<Window>();
66
/**
77
* Default function implementing pageload and navigation transactions
88
*/
9-
export function defaultRoutingInstrumentation<T extends Transaction>(
10-
startTransaction: (context: TransactionContext) => T | undefined,
9+
export function instrumentRoutingWithDefaults<T extends Transaction>(
10+
customStartTransaction: (context: TransactionContext) => T | undefined,
1111
startTransactionOnPageLoad: boolean = true,
1212
startTransactionOnLocationChange: boolean = true,
1313
): void {
@@ -20,7 +20,7 @@ export function defaultRoutingInstrumentation<T extends Transaction>(
2020

2121
let activeTransaction: T | undefined;
2222
if (startTransactionOnPageLoad) {
23-
activeTransaction = startTransaction({ name: global.location.pathname, op: 'pageload' });
23+
activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'pageload' });
2424
}
2525

2626
if (startTransactionOnLocationChange) {
@@ -47,7 +47,7 @@ export function defaultRoutingInstrumentation<T extends Transaction>(
4747
// If there's an open transaction on the scope, we need to finish it before creating an new one.
4848
activeTransaction.finish();
4949
}
50-
activeTransaction = startTransaction({ name: global.location.pathname, op: 'navigation' });
50+
activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'navigation' });
5151
}
5252
},
5353
type: 'history',

packages/tracing/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export { Integrations };
88
export { Span } from './span';
99
export { Transaction } from './transaction';
1010
export {
11-
registerRequestInstrumentation,
11+
// TODO deprecate old name in v7
12+
instrumentOutgoingRequests as registerRequestInstrumentation,
1213
RequestInstrumentationOptions,
1314
defaultRequestInstrumentationOptions,
1415
} from './browser';

0 commit comments

Comments
 (0)