Skip to content

Commit

Permalink
fix(nextjs): Pass request in sampling context of data fetchers wrappe…
Browse files Browse the repository at this point in the history
…r transaction (#5730)

This adds the request to the sampling context passed to the `startTransaction` call in the data fetchers wrapper in nextjs, to bring it in line with the `startTransaction` calls elsewhere in the SDK.
  • Loading branch information
lobsterkatie committed Sep 21, 2022
1 parent 19c4fb1 commit a780472
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/nextjs/src/config/wrappers/wrapperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,19 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr

const dynamicSamplingContext = baggageHeaderToDynamicSamplingContext(rawBaggageString);

const newTransaction = startTransaction({
op: 'nextjs.data.server',
name: options.requestedRouteName,
...traceparentData,
status: 'ok',
metadata: {
source: 'route',
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
const newTransaction = startTransaction(
{
op: 'nextjs.data.server',
name: options.requestedRouteName,
...traceparentData,
status: 'ok',
metadata: {
source: 'route',
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
},
},
});
{ request: req },
);

requestTransaction = newTransaction;
autoEndTransactionOnResponseEnd(newTransaction, res);
Expand Down
10 changes: 10 additions & 0 deletions packages/nextjs/test/config/wrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ describe('data-fetching function wrappers', () => {
op: 'nextjs.data.server',
metadata: expect.objectContaining({ source: 'route' }),
}),
{
request: expect.objectContaining({
url: 'http://dogs.are.great/tricks/kangaroo',
}),
},
);

expect(setMetadataSpy).toHaveBeenCalledWith({ request: req });
Expand All @@ -62,6 +67,11 @@ describe('data-fetching function wrappers', () => {
op: 'nextjs.data.server',
metadata: expect.objectContaining({ source: 'route' }),
}),
{
request: expect.objectContaining({
url: 'http://dogs.are.great/tricks/kangaroo',
}),
},
);

expect(setMetadataSpy).toHaveBeenCalledWith({ request: req });
Expand Down

0 comments on commit a780472

Please sign in to comment.