wrapApiHandlerWithSentry.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const core = require('@sentry/core');
  3. const edgeWrapperUtils = require('../common/utils/edgeWrapperUtils.js');
  4. /**
  5. * Wraps a Next.js edge route handler with Sentry error and performance instrumentation.
  6. */
  7. function wrapApiHandlerWithSentry(
  8. handler,
  9. parameterizedRoute,
  10. ) {
  11. return new Proxy(handler, {
  12. apply: (wrappingTarget, thisArg, args) => {
  13. const req = args[0];
  14. const activeSpan = core.getActiveSpan();
  15. const wrappedHandler = edgeWrapperUtils.withEdgeWrapping(wrappingTarget, {
  16. spanDescription:
  17. activeSpan || !(req instanceof Request)
  18. ? `handler (${parameterizedRoute})`
  19. : `${req.method} ${parameterizedRoute}`,
  20. spanOp: activeSpan ? 'function' : 'http.server',
  21. mechanismFunctionName: 'wrapApiHandlerWithSentry',
  22. });
  23. return wrappedHandler.apply(thisArg, args);
  24. },
  25. });
  26. }
  27. /**
  28. * @deprecated Use `wrapApiHandlerWithSentry` instead.
  29. */
  30. const withSentryAPI = wrapApiHandlerWithSentry;
  31. exports.withSentryAPI = withSentryAPI;
  32. exports.wrapApiHandlerWithSentry = wrapApiHandlerWithSentry;
  33. //# sourceMappingURL=wrapApiHandlerWithSentry.js.map