1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { _nullishCoalesce, _optionalChain } from '@sentry/utils';
- import { addTracingExtensions, getActiveSpan, spanToTraceHeader, getDynamicSamplingContextFromSpan, getClient, getRootSpan } from '@sentry/core';
- import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
- import { isBuild } from './utils/isBuild.js';
- import { getSpanFromRequest, withErrorInstrumentation, withTracedServerSideDataFetcher } from './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()) {
- return wrappingTarget.apply(thisArg, args);
- }
- addTracingExtensions();
- const [context] = args;
- const { req, res } = context;
- const errorWrappedGetServerSideProps = withErrorInstrumentation(wrappingTarget);
- const options = _optionalChain([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3()]);
- if (_optionalChain([options, 'optionalAccess', _4 => _4.instrumenter]) === 'sentry') {
- const tracedGetServerSideProps = withTracedServerSideDataFetcher(errorWrappedGetServerSideProps, req, res, {
- dataFetcherRouteName: parameterizedRoute,
- requestedRouteName: parameterizedRoute,
- dataFetchingMethodName: 'getServerSideProps',
- });
- const serverSideProps = await (tracedGetServerSideProps.apply(thisArg, args)
- );
- if (serverSideProps && 'props' in serverSideProps) {
- const activeSpan = getActiveSpan();
- const requestTransaction = _nullishCoalesce(getSpanFromRequest(req), () => ( (activeSpan ? getRootSpan(activeSpan) : undefined)));
- if (requestTransaction) {
- serverSideProps.props._sentryTraceData = spanToTraceHeader(requestTransaction);
- const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestTransaction);
- serverSideProps.props._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
- }
- }
- return serverSideProps;
- } else {
- return errorWrappedGetServerSideProps.apply(thisArg, args);
- }
- },
- });
- }
- /**
- * @deprecated Use `withSentryGetServerSideProps` instead.
- */
- const withSentryGetServerSideProps = wrapGetServerSidePropsWithSentry;
- export { withSentryGetServerSideProps, wrapGetServerSidePropsWithSentry };
- //# sourceMappingURL=wrapGetServerSidePropsWithSentry.js.map
|