1- import {
2- debug ,
3- flushIfServerless ,
4- getDefaultIsolationScope ,
5- getIsolationScope ,
6- withIsolationScope ,
7- } from '@sentry/core' ;
8- import type { EventHandler , H3Event } from 'h3' ;
1+ import { debug } from '@sentry/core' ;
2+ import type { H3Event } from 'h3' ;
93import type { NitroAppPlugin } from 'nitropack' ;
104import type { NuxtRenderHTMLContext } from 'nuxt/app' ;
115import { sentryCaptureErrorHook } from '../hooks/captureErrorHook' ;
126import { updateRouteBeforeResponse } from '../hooks/updateRouteBeforeResponse' ;
137import { addSentryTracingMetaTags } from '../utils' ;
148
159export default ( nitroApp => {
16- nitroApp . h3App . handler = patchEventHandler ( nitroApp . h3App . handler ) ;
17-
1810 nitroApp . hooks . hook ( 'beforeResponse' , updateRouteBeforeResponse ) ;
1911
2012 nitroApp . hooks . hook ( 'error' , sentryCaptureErrorHook ) ;
@@ -37,26 +29,3 @@ export default (nitroApp => {
3729 }
3830 } ) ;
3931} ) satisfies NitroAppPlugin ;
40-
41- function patchEventHandler ( handler : EventHandler ) : EventHandler {
42- return new Proxy ( handler , {
43- async apply ( handlerTarget , handlerThisArg , handlerArgs : Parameters < EventHandler > ) {
44- const isolationScope = getIsolationScope ( ) ;
45- const newIsolationScope = isolationScope === getDefaultIsolationScope ( ) ? isolationScope . clone ( ) : isolationScope ;
46-
47- debug . log (
48- `Patched h3 event handler. ${
49- isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
50- } isolation scope.`,
51- ) ;
52-
53- return withIsolationScope ( newIsolationScope , async ( ) => {
54- try {
55- return await handlerTarget . apply ( handlerThisArg , handlerArgs ) ;
56- } finally {
57- await flushIfServerless ( ) ;
58- }
59- } ) ;
60- } ,
61- } ) ;
62- }
0 commit comments