Skip to content

Commit 2b43383

Browse files
authored
fix(remix): Avoid rewrapping root loader. (#16136)
Resolves: #16075 We used to allow rewrapping of the root loader when we had a separate Express adapter, where we could not determine the instrumentation order. Now that we don't have it anymore, we can remove this. Still, can't reproduce the original issue running e2e test apps under load. But it's clear that's what caused it.
1 parent 8131751 commit 2b43383

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

dev-packages/e2e-tests/test-applications/create-remix-app-v2/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
},
1313
"dependencies": {
1414
"@sentry/remix": "latest || *",
15-
"@remix-run/css-bundle": "2.7.2",
16-
"@remix-run/node": "2.7.2",
17-
"@remix-run/react": "2.7.2",
18-
"@remix-run/serve": "2.7.2",
15+
"@remix-run/css-bundle": "2.16.5",
16+
"@remix-run/node": "2.16.5",
17+
"@remix-run/react": "2.16.5",
18+
"@remix-run/serve": "2.16.5",
1919
"isbot": "^3.6.8",
2020
"react": "^18.2.0",
2121
"react-dom": "^18.2.0"
2222
},
2323
"devDependencies": {
2424
"@playwright/test": "~1.50.0",
2525
"@sentry-internal/test-utils": "link:../../../test-utils",
26-
"@remix-run/dev": "2.7.2",
27-
"@remix-run/eslint-config": "2.7.2",
26+
"@remix-run/dev": "2.16.5",
27+
"@remix-run/eslint-config": "2.16.5",
2828
"@sentry/core": "latest || *",
2929
"@types/react": "^18.0.35",
3030
"@types/react-dom": "^18.0.11",

dev-packages/e2e-tests/test-applications/remix-hydrogen/tests/server-transactions.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
4040

4141
const httpServerTraceId = httpServerTransaction.contexts?.trace?.trace_id;
4242
const httpServerSpanId = httpServerTransaction.contexts?.trace?.span_id;
43-
const loaderSpanId = httpServerTransaction?.spans?.find(span => span.op === 'function.remix.loader')?.span_id;
4443

4544
const pageLoadTraceId = pageloadTransaction.contexts?.trace?.trace_id;
4645
const pageLoadSpanId = pageloadTransaction.contexts?.trace?.span_id;
@@ -50,7 +49,6 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
5049

5150
expect(httpServerTraceId).toBeDefined();
5251
expect(httpServerSpanId).toBeDefined();
53-
expect(loaderSpanId).toBeDefined();
5452

5553
expect(pageLoadTraceId).toEqual(httpServerTraceId);
5654
expect(pageLoadSpanId).not.toEqual(httpServerSpanId);

packages/remix/src/server/instrumentServer.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,18 @@ function instrumentBuildCallback(
364364
for (const [id, route] of Object.entries(build.routes)) {
365365
const wrappedRoute = { ...route, module: { ...route.module } };
366366

367+
// Entry module should have a loader function to provide `sentry-trace` and `baggage`
368+
// They will be available for the root `meta` function as `data.sentryTrace` and `data.sentryBaggage`
369+
if (!wrappedRoute.parentId) {
370+
if (!wrappedRoute.module.loader) {
371+
wrappedRoute.module.loader = () => ({});
372+
}
373+
374+
if (!(wrappedRoute.module.loader as WrappedFunction).__sentry_original__) {
375+
fill(wrappedRoute.module, 'loader', makeWrappedRootLoader());
376+
}
377+
}
378+
367379
const routeAction = wrappedRoute.module.action as undefined | WrappedFunction;
368380
if (routeAction && !routeAction.__sentry_original__) {
369381
fill(wrappedRoute.module, 'action', makeWrappedAction(id, options?.instrumentTracing));
@@ -374,17 +386,6 @@ function instrumentBuildCallback(
374386
fill(wrappedRoute.module, 'loader', makeWrappedLoader(id, options?.instrumentTracing));
375387
}
376388

377-
// Entry module should have a loader function to provide `sentry-trace` and `baggage`
378-
// They will be available for the root `meta` function as `data.sentryTrace` and `data.sentryBaggage`
379-
if (!wrappedRoute.parentId) {
380-
if (!wrappedRoute.module.loader) {
381-
wrappedRoute.module.loader = () => ({});
382-
}
383-
384-
// We want to wrap the root loader regardless of whether it's already wrapped before.
385-
fill(wrappedRoute.module, 'loader', makeWrappedRootLoader());
386-
}
387-
388389
routes[id] = wrappedRoute;
389390
}
390391

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ describe('Remix API Actions', () => {
2828
data: {
2929
'code.function': 'loader',
3030
'sentry.op': 'loader.remix',
31-
'match.route.id': 'routes/action-json-response.$id',
31+
'match.route.id': 'root',
3232
'match.params.id': '123123',
3333
},
3434
},
3535
{
3636
data: {
3737
'code.function': 'loader',
3838
'sentry.op': 'loader.remix',
39-
'match.route.id': 'root',
39+
'match.route.id': 'routes/action-json-response.$id',
4040
'match.params.id': '123123',
4141
},
4242
},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ describe('Remix API Loaders', () => {
242242
data: {
243243
'code.function': 'loader',
244244
'sentry.op': 'loader.remix',
245-
'match.route.id': 'routes/loader-defer-response.$id',
245+
'match.route.id': 'root',
246246
},
247247
},
248248
{
249249
data: {
250250
'code.function': 'loader',
251251
'sentry.op': 'loader.remix',
252-
'match.route.id': 'root',
252+
'match.route.id': 'routes/loader-defer-response.$id',
253253
},
254254
},
255255
],

0 commit comments

Comments
 (0)