var { _nullishCoalesce, _optionalChain } = require('@sentry/utils'); Object.defineProperty(exports, '__esModule', { value: true }); const core = require('@sentry/core'); const utils = require('@sentry/utils'); const isBuild = require('./utils/isBuild.js'); const wrapperUtils = require('./utils/wrapperUtils.js'); /** * Create a wrapped version of the user's exported `getServerSideProps` function * * @param origGetServerSideProps The user's `getServerSideProps` function * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ function wrapGetServerSidePropsWithSentry( origGetServerSideProps, parameterizedRoute, ) { return new Proxy(origGetServerSideProps, { apply: async (wrappingTarget, thisArg, args) => { if (isBuild.isBuild()) { return wrappingTarget.apply(thisArg, args); } core.addTracingExtensions(); const [context] = args; const { req, res } = context; const errorWrappedGetServerSideProps = wrapperUtils.withErrorInstrumentation(wrappingTarget); const options = _optionalChain([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3()]); if (_optionalChain([options, 'optionalAccess', _4 => _4.instrumenter]) === 'sentry') { const tracedGetServerSideProps = wrapperUtils.withTracedServerSideDataFetcher(errorWrappedGetServerSideProps, req, res, { dataFetcherRouteName: parameterizedRoute, requestedRouteName: parameterizedRoute, dataFetchingMethodName: 'getServerSideProps', }); const serverSideProps = await (tracedGetServerSideProps.apply(thisArg, args) ); if (serverSideProps && 'props' in serverSideProps) { const activeSpan = core.getActiveSpan(); const requestTransaction = _nullishCoalesce(wrapperUtils.getSpanFromRequest(req), () => ( (activeSpan ? core.getRootSpan(activeSpan) : undefined))); if (requestTransaction) { serverSideProps.props._sentryTraceData = core.spanToTraceHeader(requestTransaction); const dynamicSamplingContext = core.getDynamicSamplingContextFromSpan(requestTransaction); serverSideProps.props._sentryBaggage = utils.dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext); } } return serverSideProps; } else { return errorWrappedGetServerSideProps.apply(thisArg, args); } }, }); } /** * @deprecated Use `withSentryGetServerSideProps` instead. */ const withSentryGetServerSideProps = wrapGetServerSidePropsWithSentry; exports.withSentryGetServerSideProps = withSentryGetServerSideProps; exports.wrapGetServerSidePropsWithSentry = wrapGetServerSidePropsWithSentry; //# sourceMappingURL=wrapGetServerSidePropsWithSentry.js.map