Skip to content

feat(remix): Add route ID to remix routes #5568

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 2 commits into from
Aug 12, 2022
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
25 changes: 14 additions & 11 deletions packages/remix/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function makeWrappedDocumentRequestFunction(
};
}

function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'): DataFunction {
function makeWrappedDataFunction(origFn: DataFunction, id: string, name: 'action' | 'loader'): DataFunction {
return async function (this: unknown, args: DataFunctionArgs): Promise<Response | AppData> {
let res: Response | AppData;
const activeTransaction = getActiveTransaction();
Expand All @@ -216,8 +216,7 @@ function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'
try {
const span = activeTransaction.startChild({
op: `remix.server.${name}`,
// TODO: Consider using the `id` of the route this function belongs to
description: activeTransaction.name,
description: id,
tags: {
name,
},
Expand All @@ -241,13 +240,17 @@ function makeWrappedDataFunction(origFn: DataFunction, name: 'action' | 'loader'
};
}

function makeWrappedAction(origAction: DataFunction): DataFunction {
return makeWrappedDataFunction(origAction, 'action');
}
const makeWrappedAction =
(id: string) =>
(origAction: DataFunction): DataFunction => {
return makeWrappedDataFunction(origAction, id, 'action');
};

function makeWrappedLoader(origLoader: DataFunction): DataFunction {
return makeWrappedDataFunction(origLoader, 'loader');
}
const makeWrappedLoader =
(id: string) =>
(origLoader: DataFunction): DataFunction => {
return makeWrappedDataFunction(origLoader, id, 'loader');
};

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

if (wrappedRoute.module.action) {
fill(wrappedRoute.module, 'action', makeWrappedAction);
fill(wrappedRoute.module, 'action', makeWrappedAction(id));
}

if (wrappedRoute.module.loader) {
fill(wrappedRoute.module, 'loader', makeWrappedLoader);
fill(wrappedRoute.module, 'loader', makeWrappedLoader(id));
}

// Entry module should have a loader function to provide `sentry-trace` and `baggage`
Expand Down
5 changes: 1 addition & 4 deletions packages/remix/test/integration/test/server/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ describe('Remix API Actions', () => {
description: 'routes/action-json-response/$id',
op: 'remix.server.action',
},
// TODO: These two spans look exactly the same, but they are not.
// One is from the parent route, and the other is from the route we are reaching.
// We need to pass the names of the routes as their descriptions while wrapping loaders and actions.
{
description: 'routes/action-json-response/$id',
description: 'root',
op: 'remix.server.loader',
},
{
Expand Down
5 changes: 1 addition & 4 deletions packages/remix/test/integration/test/server/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ describe('Remix API Loaders', () => {
source: 'route',
},
spans: [
// TODO: These two spans look exactly the same, but they are not.
// One is from the parent route, and the other is from the route we are reaching.
// We need to pass the names of the routes as their descriptions while wrapping loaders and actions.
{
description: 'routes/loader-json-response/$id',
description: 'root',
op: 'remix.server.loader',
},
{
Expand Down