Skip to content

Commit 889dc17

Browse files
committed
add request to transaction metadata
1 parent d253c94 commit 889dc17

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

packages/nextjs/src/config/wrappers/wrapperUtils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
106106

107107
requestTransaction = newTransaction;
108108
autoEndTransactionOnResponseEnd(newTransaction, res);
109+
110+
// Link the transaction and the request together, so that when we would normally only have access to one, it's
111+
// still possible to grab the other.
109112
setTransactionOnRequest(newTransaction, req);
113+
newTransaction.setMetadata({ request: req });
110114
}
111115

112116
const dataFetcherSpan = requestTransaction.startChild({

packages/nextjs/src/utils/instrumentServer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
276276
// like `source: isDynamicRoute? 'url' : 'route'`
277277
// TODO: What happens when `withSentry` is used also? Which values of `name` and `source` win?
278278
source: 'url',
279+
request: req,
279280
},
280281
...traceparentData,
281282
},

packages/nextjs/src/utils/withSentry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
7272
name: `${reqMethod}${reqPath}`,
7373
op: 'http.server',
7474
...traceparentData,
75-
metadata: { baggage, source: 'route' },
75+
metadata: { baggage, source: 'route', request: req },
7676
},
7777
// extra context passed to the `tracesSampler`
7878
{ request: req },

0 commit comments

Comments
 (0)