Skip to content

Commit e47fcdc

Browse files
committed
Address review comments.
1 parent 8a3311c commit e47fcdc

File tree

2 files changed

+35
-52
lines changed

2 files changed

+35
-52
lines changed

packages/remix/src/client/browserTracingIntegration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import type { RemixBrowserTracingIntegrationOptions } from './performance';
77
* This integration will create pageload and navigation spans.
88
*/
99
export function browserTracingIntegration(options: RemixBrowserTracingIntegrationOptions): Integration {
10-
if (options.startTransactionOnPageLoad === undefined) {
11-
options.startTransactionOnPageLoad = true;
10+
if (options.instrumentPageLoad === undefined) {
11+
options.instrumentPageLoad = true;
1212
}
1313

14-
if (options.startTransactionOnLocationChange === undefined) {
15-
options.startTransactionOnLocationChange = true;
14+
if (options.instrumentNavigation === undefined) {
15+
options.instrumentNavigation = true;
1616
}
1717

1818
setGlobals({
1919
useEffect: options.useEffect,
2020
useLocation: options.useLocation,
2121
useMatches: options.useMatches,
22-
startTransactionOnLocationChange: options.startTransactionOnLocationChange,
22+
startTransactionOnLocationChange: options.instrumentNavigation,
2323
});
2424

2525
const browserTracingIntegrationInstance = originalBrowserTracingIntegration({
@@ -31,9 +31,9 @@ export function browserTracingIntegration(options: RemixBrowserTracingIntegratio
3131
return {
3232
...browserTracingIntegrationInstance,
3333
afterAllSetup(client) {
34-
browserTracingIntegrationInstance.afterAllSetup?.(client);
34+
browserTracingIntegrationInstance.afterAllSetup(client);
3535

36-
if (options.startTransactionOnPageLoad) {
36+
if (options.instrumentPageLoad) {
3737
startPageloadSpan();
3838
}
3939
},

packages/remix/src/client/performance.tsx

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
startBrowserTracingPageLoadSpan,
99
withErrorBoundary,
1010
} from '@sentry/react';
11-
import type { Span, Transaction, TransactionContext } from '@sentry/types';
11+
import type { Span, StartSpanOptions, Transaction, TransactionContext } from '@sentry/types';
1212
import { isNodeEnv, logger } from '@sentry/utils';
1313
import * as React from 'react';
1414

@@ -41,16 +41,12 @@ export type RemixBrowserTracingIntegrationOptions = Partial<Parameters<typeof or
4141
useEffect?: UseEffect;
4242
useLocation?: UseLocation;
4343
useMatches?: UseMatches;
44-
startTransactionOnPageLoad?: boolean;
45-
startTransactionOnLocationChange?: boolean;
4644
};
4745

4846
const DEFAULT_TAGS = {
4947
'routing.instrumentation': 'remix-router',
5048
} as const;
5149

52-
let activeRootSpan: Span | undefined;
53-
5450
let _useEffect: UseEffect | undefined;
5551
let _useLocation: UseLocation | undefined;
5652
let _useMatches: UseMatches | undefined;
@@ -77,6 +73,16 @@ export function startPageloadSpan(): void {
7773
return;
7874
}
7975

76+
const spanContext: StartSpanOptions = {
77+
name: initPathName,
78+
op: 'pageload',
79+
origin: 'auto.pageload.remix',
80+
tags: DEFAULT_TAGS,
81+
metadata: {
82+
source: 'url',
83+
},
84+
};
85+
8086
// If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
8187
if (!_customStartTransaction) {
8288
const client = getClient<BrowserClient>();
@@ -85,31 +91,23 @@ export function startPageloadSpan(): void {
8591
return;
8692
}
8793

88-
startBrowserTracingPageLoadSpan(client, {
89-
name: initPathName,
90-
op: 'pageload',
91-
origin: 'auto.pageload.remix',
92-
tags: DEFAULT_TAGS,
93-
metadata: {
94-
source: 'url',
95-
},
96-
});
97-
98-
activeRootSpan = getActiveSpan();
94+
startBrowserTracingPageLoadSpan(client, spanContext);
9995
} else {
100-
activeRootSpan = _customStartTransaction({
101-
name: initPathName,
102-
op: 'pageload',
103-
origin: 'auto.pageload.remix',
104-
tags: DEFAULT_TAGS,
105-
metadata: {
106-
source: 'url',
107-
},
108-
});
96+
_customStartTransaction(spanContext);
10997
}
11098
}
11199

112100
function startNavigationSpan(matches: RouteMatch<string>[]): void {
101+
const spanContext: StartSpanOptions = {
102+
name: matches[matches.length - 1].id,
103+
op: 'navigation',
104+
origin: 'auto.navigation.remix',
105+
tags: DEFAULT_TAGS,
106+
metadata: {
107+
source: 'route',
108+
},
109+
};
110+
113111
// If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
114112
if (!_customStartTransaction) {
115113
const client = getClient<BrowserClient>();
@@ -118,27 +116,9 @@ function startNavigationSpan(matches: RouteMatch<string>[]): void {
118116
return;
119117
}
120118

121-
startBrowserTracingNavigationSpan(client, {
122-
name: matches[matches.length - 1].id,
123-
op: 'navigation',
124-
origin: 'auto.navigation.remix',
125-
tags: DEFAULT_TAGS,
126-
metadata: {
127-
source: 'route',
128-
},
129-
});
130-
131-
activeRootSpan = getActiveSpan();
119+
startBrowserTracingNavigationSpan(client, spanContext);
132120
} else {
133-
activeRootSpan = _customStartTransaction({
134-
name: matches[matches.length - 1].id,
135-
op: 'navigation',
136-
origin: 'auto.navigation.remix',
137-
tags: DEFAULT_TAGS,
138-
metadata: {
139-
source: 'route',
140-
},
141-
});
121+
_customStartTransaction(spanContext);
142122
}
143123
}
144124

@@ -208,6 +188,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
208188

209189
_useEffect(() => {
210190
const activeRootSpan = getActiveSpan();
191+
211192
if (activeRootSpan && matches && matches.length) {
212193
const transaction = getRootSpan(activeRootSpan);
213194

@@ -221,6 +202,8 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
221202
}, []);
222203

223204
_useEffect(() => {
205+
const activeRootSpan = getActiveSpan();
206+
224207
if (isBaseLocation) {
225208
if (activeRootSpan) {
226209
activeRootSpan.end();

0 commit comments

Comments
 (0)