Skip to content

Commit 427602e

Browse files
authored
feat(remix): Update scope transactionName for Remix server features (#11784)
1 parent 2288caf commit 427602e

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

packages/remix/src/utils/instrumentServer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ function wrapRequestHandler(origRequestHandler: RequestHandler, build: ServerBui
451451
const url = new URL(request.url);
452452
const [name, source] = getTransactionName(routes, url);
453453

454+
isolationScope.setTransactionName(name);
454455
isolationScope.setSDKProcessingMetadata({
455456
request: {
456457
...normalizedRequest,

packages/remix/src/utils/serverAdapters/express.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getClient, hasTracingEnabled, setHttpStatus, withIsolationScope } from '@sentry/core';
22
import { flush } from '@sentry/node';
3-
import type { Span } from '@sentry/types';
3+
import type { Span, TransactionSource } from '@sentry/types';
44
import { extractRequestData, fill, isString, logger } from '@sentry/utils';
55

66
import { DEBUG_BUILD } from '../debug-build';
@@ -53,33 +53,35 @@ function wrapExpressRequestHandler(
5353
return resolvedBuild.then(resolved => {
5454
routes = createRoutes(resolved.routes);
5555

56-
startRequestHandlerTransactionWithRoutes.call(this, origRequestHandler, routes, req, res, next, url);
56+
const [name, source] = getTransactionName(routes, url);
57+
isolationScope.setTransactionName(name);
58+
59+
startRequestHandlerTransaction.call(this, origRequestHandler, req, res, next, name, source);
5760
});
5861
} else {
5962
routes = createRoutes(resolvedBuild.routes);
60-
61-
return startRequestHandlerTransactionWithRoutes.call(this, origRequestHandler, routes, req, res, next, url);
6263
}
6364
} else {
6465
routes = createRoutes(build.routes);
6566
}
6667

67-
return startRequestHandlerTransactionWithRoutes.call(this, origRequestHandler, routes, req, res, next, url);
68+
const [name, source] = getTransactionName(routes, url);
69+
isolationScope.setTransactionName(name);
70+
71+
return startRequestHandlerTransaction.call(this, origRequestHandler, req, res, next, name, source);
6872
});
6973
};
7074
}
7175

72-
function startRequestHandlerTransactionWithRoutes(
76+
function startRequestHandlerTransaction(
7377
this: unknown,
7478
origRequestHandler: ExpressRequestHandler,
75-
routes: ServerRoute[],
7679
req: ExpressRequest,
7780
res: ExpressResponse,
7881
next: ExpressNextFunction,
79-
url: URL,
82+
name: string,
83+
source: TransactionSource,
8084
): unknown {
81-
const [name, source] = getTransactionName(routes, url);
82-
8385
return startRequestHandlerSpan(
8486
{
8587
name,

packages/remix/test/integration/test/server/action.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
7070
});
7171

7272
assertSentryEvent(event[2], {
73+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
7374
exception: {
7475
values: [
7576
{
@@ -117,6 +118,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
117118
});
118119

119120
assertSentryEvent(event[2], {
121+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
120122
exception: {
121123
values: [
122124
{
@@ -180,6 +182,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
180182
});
181183

182184
assertSentryEvent(event[2], {
185+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
183186
exception: {
184187
values: [
185188
{
@@ -228,6 +231,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
228231
});
229232

230233
assertSentryEvent(event[2], {
234+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
231235
exception: {
232236
values: [
233237
{
@@ -276,6 +280,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
276280
});
277281

278282
assertSentryEvent(event[2], {
283+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
279284
exception: {
280285
values: [
281286
{
@@ -324,6 +329,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
324329
});
325330

326331
assertSentryEvent(event[2], {
332+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
327333
exception: {
328334
values: [
329335
{
@@ -372,6 +378,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
372378
});
373379

374380
assertSentryEvent(event[2], {
381+
transaction: expect.stringMatching(/routes\/action-json-response(\/|\.)\$id/),
375382
exception: {
376383
values: [
377384
{
@@ -420,6 +427,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
420427
});
421428

422429
assertSentryEvent(event[2], {
430+
transaction: expect.stringMatching(/routes\/server-side-unexpected-errors(\/|\.)\$id/),
423431
exception: {
424432
values: [
425433
{
@@ -468,6 +476,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
468476
});
469477

470478
assertSentryEvent(event[2], {
479+
transaction: expect.stringMatching(/routes\/server-side-unexpected-errors(\/|\.)\$id/),
471480
exception: {
472481
values: [
473482
{

packages/remix/test/integration/test/server/loader.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
2828
});
2929

3030
assertSentryEvent(event, {
31+
transaction: expect.stringMatching(/routes\/loader-json-response(\/|\.)\$id/),
3132
exception: {
3233
values: [
3334
{
@@ -70,6 +71,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
7071
});
7172

7273
assertSentryEvent(event, {
74+
transaction: expect.stringMatching(/routes\/loader-throw-response(\/|\.)\$id/),
7375
exception: {
7476
values: [
7577
{
@@ -159,6 +161,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
159161
});
160162

161163
assertSentryEvent(event[2], {
164+
transaction: expect.stringMatching(/routes\/loader-json-response(\/|\.)\$id/),
162165
exception: {
163166
values: [
164167
{

packages/remix/test/integration/test/server/ssr.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('Server Side Rendering', () => {
2222
});
2323

2424
assertSentryEvent(event[2], {
25+
transaction: 'routes/ssr-error',
2526
exception: {
2627
values: [
2728
{

0 commit comments

Comments
 (0)