Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ccc51f3

Browse files
authoredAug 12, 2022
feat(remix): Add route ID to remix routes (#5568)
1 parent fbb44d5 commit ccc51f3

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed
 

‎packages/remix/src/utils/instrumentServer.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function makeWrappedDocumentRequestFunction(
203203
};
204204
}
205205

206-
function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'): DataFunction {
206+
function makeWrappedDataFunction(origFn: DataFunction, id: string, name: 'action' | 'loader'): DataFunction {
207207
return async function (this: unknown, args: DataFunctionArgs): Promise<Response | AppData> {
208208
let res: Response | AppData;
209209
const activeTransaction = getActiveTransaction();
@@ -216,8 +216,7 @@ function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'
216216
try {
217217
const span = activeTransaction.startChild({
218218
op: `remix.server.${name}`,
219-
// TODO: Consider using the `id` of the route this function belongs to
220-
description: activeTransaction.name,
219+
description: id,
221220
tags: {
222221
name,
223222
},
@@ -241,13 +240,17 @@ function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'
241240
};
242241
}
243242

244-
function makeWrappedAction(origAction: DataFunction): DataFunction {
245-
return makeWrappedDataFunction(origAction, 'action');
246-
}
243+
const makeWrappedAction =
244+
(id: string) =>
245+
(origAction: DataFunction): DataFunction => {
246+
return makeWrappedDataFunction(origAction, id, 'action');
247+
};
247248

248-
function makeWrappedLoader(origLoader: DataFunction): DataFunction {
249-
return makeWrappedDataFunction(origLoader, 'loader');
250-
}
249+
const makeWrappedLoader =
250+
(id: string) =>
251+
(origLoader: DataFunction): DataFunction => {
252+
return makeWrappedDataFunction(origLoader, id, 'loader');
253+
};
251254

252255
function getTraceAndBaggage(): { sentryTrace?: string; sentryBaggage?: string } {
253256
const transaction = getActiveTransaction();
@@ -427,11 +430,11 @@ function makeWrappedCreateRequestHandler(
427430
const wrappedRoute = { ...route, module: { ...route.module } };
428431

429432
if (wrappedRoute.module.action) {
430-
fill(wrappedRoute.module, 'action', makeWrappedAction);
433+
fill(wrappedRoute.module, 'action', makeWrappedAction(id));
431434
}
432435

433436
if (wrappedRoute.module.loader) {
434-
fill(wrappedRoute.module, 'loader', makeWrappedLoader);
437+
fill(wrappedRoute.module, 'loader', makeWrappedLoader(id));
435438
}
436439

437440
// Entry module should have a loader function to provide `sentry-trace` and `baggage`

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ describe('Remix API Actions', () => {
2222
description: 'routes/action-json-response/$id',
2323
op: 'remix.server.action',
2424
},
25-
// TODO: These two spans look exactly the same, but they are not.
26-
// One is from the parent route, and the other is from the route we are reaching.
27-
// We need to pass the names of the routes as their descriptions while wrapping loaders and actions.
2825
{
29-
description: 'routes/action-json-response/$id',
26+
description: 'root',
3027
op: 'remix.server.loader',
3128
},
3229
{

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ describe('Remix API Loaders', () => {
5858
source: 'route',
5959
},
6060
spans: [
61-
// TODO: These two spans look exactly the same, but they are not.
62-
// One is from the parent route, and the other is from the route we are reaching.
63-
// We need to pass the names of the routes as their descriptions while wrapping loaders and actions.
6461
{
65-
description: 'routes/loader-json-response/$id',
62+
description: 'root',
6663
op: 'remix.server.loader',
6764
},
6865
{

0 commit comments

Comments
 (0)
Please sign in to comment.