{"version":3,"file":"wrapErrorGetInitialPropsWithSentry.js","sources":["../../../../src/common/pages-router-instrumentation/wrapErrorGetInitialPropsWithSentry.ts"],"sourcesContent":["import type { NextPageContext } from 'next';\nimport type { ErrorProps } from 'next/error';\nimport { isBuild } from '../utils/isBuild';\nimport { withErrorInstrumentation, withTracedServerSideDataFetcher } from '../utils/wrapperUtils';\n\ntype ErrorGetInitialProps = (context: NextPageContext) => Promise;\n\n/**\n * Create a wrapped version of the user's exported `getInitialProps` function in\n * a custom error page (\"_error.js\").\n *\n * @param origErrorGetInitialProps The user's `getInitialProps` function\n * @param parameterizedRoute The page's parameterized route\n * @returns A wrapped version of the function\n */\nexport function wrapErrorGetInitialPropsWithSentry(\n origErrorGetInitialProps: ErrorGetInitialProps,\n): ErrorGetInitialProps {\n return new Proxy(origErrorGetInitialProps, {\n apply: async (wrappingTarget, thisArg, args: Parameters) => {\n if (isBuild()) {\n return wrappingTarget.apply(thisArg, args);\n }\n\n const [context] = args;\n const { req, res } = context;\n\n const errorWrappedGetInitialProps = withErrorInstrumentation(wrappingTarget);\n // Generally we can assume that `req` and `res` are always defined on the server:\n // https://nextjs.org/docs/api-reference/data-fetching/get-initial-props#context-object\n // This does not seem to be the case in dev mode. Because we have no clean way of associating the the data fetcher\n // span with each other when there are no req or res objects, we simply do not trace them at all here.\n if (req && res) {\n const tracedGetInitialProps = withTracedServerSideDataFetcher(errorWrappedGetInitialProps, req, res, {\n dataFetcherRouteName: '/_error',\n requestedRouteName: context.pathname,\n dataFetchingMethodName: 'getInitialProps',\n });\n\n const {\n data: errorGetInitialProps,\n baggage,\n sentryTrace,\n }: {\n data?: unknown;\n baggage?: string;\n sentryTrace?: string;\n } = await tracedGetInitialProps.apply(thisArg, args);\n\n if (typeof errorGetInitialProps === 'object' && errorGetInitialProps !== null) {\n if (sentryTrace) {\n // The Next.js serializer throws on undefined values so we need to guard for it (#12102)\n (errorGetInitialProps as Record)._sentryTraceData = sentryTrace;\n }\n\n // The Next.js serializer throws on undefined values so we need to guard for it (#12102)\n if (baggage) {\n (errorGetInitialProps as Record)._sentryBaggage = baggage;\n }\n }\n\n return errorGetInitialProps;\n } else {\n return errorWrappedGetInitialProps.apply(thisArg, args);\n }\n },\n });\n}\n"],"names":[],"mappings":";;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kCAAkC;AAClD,EAAE,wBAAwB;AAC1B,EAAwB;AACxB,EAAE,OAAO,IAAI,KAAK,CAAC,wBAAwB,EAAE;AAC7C,IAAI,KAAK,EAAE,OAAO,cAAc,EAAE,OAAO,EAAE,IAAI,KAAuC;AACtF,MAAM,IAAI,OAAO,EAAE,EAAE;AACrB,QAAQ,OAAO,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;AAClD,MAAM;;AAEN,MAAM,MAAM,CAAC,OAAO,CAAA,GAAI,IAAI;AAC5B,MAAM,MAAM,EAAE,GAAG,EAAE,GAAA,EAAI,GAAI,OAAO;;AAElC,MAAM,MAAM,2BAAA,GAA8B,wBAAwB,CAAC,cAAc,CAAC;AAClF;AACA;AACA;AACA;AACA,MAAM,IAAI,GAAA,IAAO,GAAG,EAAE;AACtB,QAAQ,MAAM,qBAAA,GAAwB,+BAA+B,CAAC,2BAA2B,EAAE,GAAG,EAAE,GAAG,EAAE;AAC7G,UAAU,oBAAoB,EAAE,SAAS;AACzC,UAAU,kBAAkB,EAAE,OAAO,CAAC,QAAQ;AAC9C,UAAU,sBAAsB,EAAE,iBAAiB;AACnD,SAAS,CAAC;;AAEV,QAAQ,MAAM;AACd,UAAU,IAAI,EAAE,oBAAoB;AACpC,UAAU,OAAO;AACjB,UAAU,WAAW;AACrB;;AAIQ,GAAI,MAAM,qBAAqB,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;;AAE5D,QAAQ,IAAI,OAAO,oBAAA,KAAyB,YAAY,oBAAA,KAAyB,IAAI,EAAE;AACvF,UAAU,IAAI,WAAW,EAAE;AAC3B;AACA,YAA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