Skip to content

Commit

Permalink
pass request to tracesSampler when starting transaction in data-fet…
Browse files Browse the repository at this point in the history
…cher wrappers
  • Loading branch information
lobsterkatie committed Sep 20, 2022
1 parent 19c4fb1 commit ab6d376
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 ab6d376

Please sign in to comment.