wrapGetStaticPropsWithSentry.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { _optionalChain } from '@sentry/utils';
  2. import { addTracingExtensions, getClient } from '@sentry/core';
  3. import { isBuild } from './utils/isBuild.js';
  4. import { callDataFetcherTraced, withErrorInstrumentation } from './utils/wrapperUtils.js';
  5. /**
  6. * Create a wrapped version of the user's exported `getStaticProps` function
  7. *
  8. * @param origGetStaticProps The user's `getStaticProps` function
  9. * @param parameterizedRoute The page's parameterized route
  10. * @returns A wrapped version of the function
  11. */
  12. function wrapGetStaticPropsWithSentry(
  13. origGetStaticPropsa,
  14. parameterizedRoute,
  15. ) {
  16. return new Proxy(origGetStaticPropsa, {
  17. apply: (wrappingTarget, thisArg, args) => {
  18. if (isBuild()) {
  19. return wrappingTarget.apply(thisArg, args);
  20. }
  21. addTracingExtensions();
  22. const errorWrappedGetStaticProps = withErrorInstrumentation(wrappingTarget);
  23. const options = _optionalChain([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3()]);
  24. if (_optionalChain([options, 'optionalAccess', _4 => _4.instrumenter]) === 'sentry') {
  25. return callDataFetcherTraced(errorWrappedGetStaticProps, args, {
  26. parameterizedRoute,
  27. dataFetchingMethodName: 'getStaticProps',
  28. });
  29. }
  30. return errorWrappedGetStaticProps.apply(thisArg, args);
  31. },
  32. });
  33. }
  34. /**
  35. * @deprecated Use `wrapGetStaticPropsWithSentry` instead.
  36. */
  37. const withSentryGetStaticProps = wrapGetStaticPropsWithSentry;
  38. export { withSentryGetStaticProps, wrapGetStaticPropsWithSentry };
  39. //# sourceMappingURL=wrapGetStaticPropsWithSentry.js.map