Skip to content

Commit

Permalink
fix(remix): Pass transaction name as route to RequestData. (#6276)
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Nov 24, 2022
1 parent e97ae86 commit 9f522c9
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions packages/remix/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ async function captureRemixServerException(err: Error, name: string, request: Re
const normalizedRequest = normalizeRemixRequest(request as unknown as any);

captureException(isResponse(err) ? await extractResponseError(err) : err, scope => {
scope.setSDKProcessingMetadata({ request: normalizedRequest });
const activeTransactionName = getActiveTransaction()?.name;

scope.setSDKProcessingMetadata({
request: {
...normalizedRequest,
// When `route` is not defined, `RequestData` integration uses the full URL
route: activeTransactionName
? {
path: activeTransactionName,
}
: undefined,
},
});

scope.addEventProcessor(event => {
addExceptionMechanism(event, {
type: 'instrument',
Expand Down Expand Up @@ -378,19 +391,24 @@ function wrapRequestHandler(origRequestHandler: RequestHandler, build: ServerBui

const normalizedRequest = normalizeRemixRequest(request);

const url = new URL(request.url);
const [name, source] = getTransactionName(routes, url, pkg);

if (scope) {
scope.setSDKProcessingMetadata({
request: normalizedRequest,
request: {
...normalizedRequest,
route: {
path: name,
},
},
});
}

if (!options || !hasTracingEnabled(options)) {
return origRequestHandler.call(this, request, loadContext);
}

const url = new URL(request.url);
const [name, source] = getTransactionName(routes, url, pkg);

const transaction = startRequestHandlerTransaction(hub, name, source, {
headers: {
'sentry-trace': request.headers.get('sentry-trace') || '',
Expand Down

0 comments on commit 9f522c9

Please sign in to comment.