Skip to content

feat(remix): Update scope transactionName when resolving route #11420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/remix/src/client/performance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
getActiveSpan,
getCurrentScope,
getRootSpan,
} from '@sentry/core';
import type { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/react';
Expand Down Expand Up @@ -158,14 +159,18 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
const matches = _useMatches();

_useEffect(() => {
const activeRootSpan = getActiveSpan();
if (matches && matches.length) {
const routeName = matches[matches.length - 1].id;
getCurrentScope().setTransactionName(routeName);

if (activeRootSpan && matches && matches.length) {
const transaction = getRootSpan(activeRootSpan);
const activeRootSpan = getActiveSpan();
if (activeRootSpan) {
const transaction = getRootSpan(activeRootSpan);

if (transaction) {
transaction.updateName(matches[matches.length - 1].id);
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
if (transaction) {
transaction.updateName(routeName);
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
}
Comment on lines +162 to +173
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly refactored this part because we always want to update the scope's transaction name; not just if there's an active span

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ test('should report a manually captured error.', async ({ page }) => {
const [errorEnvelope, pageloadEnvelope] = envelopes;

expect(errorEnvelope.level).toBe('error');
// TODO: Comment back in once we update the scope transaction name on the client side
// expect(errorEnvelope.transaction).toBe('/capture-exception');
expect(errorEnvelope.transaction).toBe('/capture-exception');
expect(errorEnvelope.exception?.values).toMatchObject([
{
type: 'Error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ test('should report a manually captured message.', async ({ page }) => {
const [messageEnvelope, pageloadEnvelope] = envelopes;

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

expect(pageloadEnvelope.contexts?.trace?.op).toBe('pageload');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ test('should capture React component errors.', async ({ page }) => {
mechanism: { type: useV2 ? 'instrument' : 'generic', handled: !useV2 },
},
]);
expect(errorEnvelope.transaction).toBe(
useV2 ? 'routes/error-boundary-capture.$id' : 'routes/error-boundary-capture/$id',
);
});