12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- var {
- _nullishCoalesce,
- _asyncNullishCoalesce,
- _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 `getInitialProps` function
- *
- * @param origGetInitialProps The user's `getInitialProps` function
- * @param parameterizedRoute The page's parameterized route
- * @returns A wrapped version of the function
- */
- function wrapGetInitialPropsWithSentry(origGetInitialProps) {
- return new Proxy(origGetInitialProps, {
- apply: async (wrappingTarget, thisArg, args) => {
- if (isBuild.isBuild()) {
- return wrappingTarget.apply(thisArg, args);
- }
- core.addTracingExtensions();
- const [context] = args;
- const { req, res } = context;
- const errorWrappedGetInitialProps = wrapperUtils.withErrorInstrumentation(wrappingTarget);
- const options = _optionalChain([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3()]);
- // Generally we can assume that `req` and `res` are always defined on the server:
- // https://nextjs.org/docs/api-reference/data-fetching/get-initial-props#context-object
- // This does not seem to be the case in dev mode. Because we have no clean way of associating the the data fetcher
- // span with each other when there are no req or res objects, we simply do not trace them at all here.
- if (req && res && _optionalChain([options, 'optionalAccess', _4 => _4.instrumenter]) === 'sentry') {
- const tracedGetInitialProps = wrapperUtils.withTracedServerSideDataFetcher(errorWrappedGetInitialProps, req, res, {
- dataFetcherRouteName: context.pathname,
- requestedRouteName: context.pathname,
- dataFetchingMethodName: 'getInitialProps',
- });
- const initialProps
- = await _asyncNullishCoalesce((await tracedGetInitialProps.apply(thisArg, args)), async () => ( {})); // Next.js allows undefined to be returned from a getInitialPropsFunction.
- const activeSpan = core.getActiveSpan();
- const requestSpan = _nullishCoalesce(wrapperUtils.getSpanFromRequest(req), () => ( (activeSpan ? core.getRootSpan(activeSpan) : undefined)));
- if (requestSpan) {
- initialProps._sentryTraceData = core.spanToTraceHeader(requestSpan);
- const dynamicSamplingContext = core.getDynamicSamplingContextFromSpan(requestSpan);
- initialProps._sentryBaggage = utils.dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
- }
- return initialProps;
- } else {
- return errorWrappedGetInitialProps.apply(thisArg, args);
- }
- },
- });
- }
- /**
- * @deprecated Use `wrapGetInitialPropsWithSentry` instead.
- */
- const withSentryServerSideGetInitialProps = wrapGetInitialPropsWithSentry;
- exports.withSentryServerSideGetInitialProps = withSentryServerSideGetInitialProps;
- exports.wrapGetInitialPropsWithSentry = wrapGetInitialPropsWithSentry;
- //# sourceMappingURL=wrapGetInitialPropsWithSentry.js.map
|