wrapApiHandlerWithSentry.js 1.1 KB

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