From 050c52533d67a2b55cea120dd06710f31ffd4de3 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 12 Sep 2022 13:02:18 -0700 Subject: [PATCH] pass request to `tracesSampler` when starting transaction in data-fetcher wrappers --- .../src/config/wrappers/wrapperUtils.ts | 21 +++++++++++-------- packages/nextjs/test/config/wrappers.test.ts | 10 +++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/nextjs/src/config/wrappers/wrapperUtils.ts b/packages/nextjs/src/config/wrappers/wrapperUtils.ts index cf7e56d8f5f6..34ea3c999f53 100644 --- a/packages/nextjs/src/config/wrappers/wrapperUtils.ts +++ b/packages/nextjs/src/config/wrappers/wrapperUtils.ts @@ -93,16 +93,19 @@ export function callTracedServerSideDataFetcher 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); diff --git a/packages/nextjs/test/config/wrappers.test.ts b/packages/nextjs/test/config/wrappers.test.ts index 90af29200c00..e163a466e8e5 100644 --- a/packages/nextjs/test/config/wrappers.test.ts +++ b/packages/nextjs/test/config/wrappers.test.ts @@ -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 }); @@ -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 });