Skip to content

Commit b1a2f8b

Browse files
authored
feat(remix): Update scope transactionName when resolving route (#11420)
This PR updates the current scope's `transactionName` when our Remix router instrumentation resolves the parameterized route name.
1 parent a132d5c commit b1a2f8b

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

packages/remix/src/client/performance.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
33
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
44
getActiveSpan,
5+
getCurrentScope,
56
getRootSpan,
67
} from '@sentry/core';
78
import type { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/react';
@@ -158,14 +159,18 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
158159
const matches = _useMatches();
159160

160161
_useEffect(() => {
161-
const activeRootSpan = getActiveSpan();
162+
if (matches && matches.length) {
163+
const routeName = matches[matches.length - 1].id;
164+
getCurrentScope().setTransactionName(routeName);
162165

163-
if (activeRootSpan && matches && matches.length) {
164-
const transaction = getRootSpan(activeRootSpan);
166+
const activeRootSpan = getActiveSpan();
167+
if (activeRootSpan) {
168+
const transaction = getRootSpan(activeRootSpan);
165169

166-
if (transaction) {
167-
transaction.updateName(matches[matches.length - 1].id);
168-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
170+
if (transaction) {
171+
transaction.updateName(routeName);
172+
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
173+
}
169174
}
170175
}
171176

packages/remix/test/integration/test/client/capture-exception.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ test('should report a manually captured error.', async ({ page }) => {
88
const [errorEnvelope, pageloadEnvelope] = envelopes;
99

1010
expect(errorEnvelope.level).toBe('error');
11-
// TODO: Comment back in once we update the scope transaction name on the client side
12-
// expect(errorEnvelope.transaction).toBe('/capture-exception');
11+
expect(errorEnvelope.transaction).toBe('/capture-exception');
1312
expect(errorEnvelope.exception?.values).toMatchObject([
1413
{
1514
type: 'Error',

packages/remix/test/integration/test/client/capture-message.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ test('should report a manually captured message.', async ({ page }) => {
88
const [messageEnvelope, pageloadEnvelope] = envelopes;
99

1010
expect(messageEnvelope.level).toBe('info');
11-
// TODO: Comment back in once we update the scope transaction name on the client side
12-
// expect(messageEnvelope.transaction).toBe('/capture-message');
11+
expect(messageEnvelope.transaction).toBe('/capture-message');
1312
expect(messageEnvelope.message).toBe('Sentry Manually Captured Message');
1413

1514
expect(pageloadEnvelope.contexts?.trace?.op).toBe('pageload');

packages/remix/test/integration/test/client/errorboundary.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ test('should capture React component errors.', async ({ page }) => {
3939
mechanism: { type: useV2 ? 'instrument' : 'generic', handled: !useV2 },
4040
},
4141
]);
42+
expect(errorEnvelope.transaction).toBe(
43+
useV2 ? 'routes/error-boundary-capture.$id' : 'routes/error-boundary-capture/$id',
44+
);
4245
});

0 commit comments

Comments
 (0)