wrapGetStaticPropsWithSentry.js 1.7 KB

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