@@ -4,7 +4,7 @@ import * as path from 'path';
4
4
import type { InputPluginOption } from 'rollup' ;
5
5
6
6
/**
7
- * Adds a template for the middleware instrumentation.
7
+ * Adds a server import for the middleware instrumentation.
8
8
*/
9
9
export function addMiddlewareImports ( ) : void {
10
10
addServerImports ( [
@@ -34,12 +34,17 @@ export function addMiddlewareInstrumentation(nitro: Nitro): void {
34
34
} ) ;
35
35
}
36
36
37
+ /**
38
+ * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.
39
+ *
40
+ * @param nitro Nitro instance
41
+ * @returns The rollup plugin for the middleware instrumentation.
42
+ */
37
43
function middlewareInstrumentationPlugin ( nitro : Nitro ) : InputPluginOption {
38
44
const middlewareFiles = new Set < string > ( ) ;
39
45
40
46
return {
41
47
name : 'sentry-nuxt-middleware-instrumentation' ,
42
-
43
48
buildStart ( ) {
44
49
// Collect middleware files during build start
45
50
nitro . scannedHandlers ?. forEach ( ( { middleware, handler } ) => {
@@ -48,7 +53,6 @@ function middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {
48
53
}
49
54
} ) ;
50
55
} ,
51
-
52
56
transform ( code : string , id : string ) {
53
57
// Only transform files we've identified as middleware
54
58
if ( middlewareFiles . has ( id ) ) {
@@ -64,6 +68,14 @@ function middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {
64
68
} ;
65
69
}
66
70
71
+ /**
72
+ * Wraps the middleware user code to instrument it.
73
+ *
74
+ * @param originalCode The original user code of the middleware.
75
+ * @param fileName The name of the middleware file, used for the span name and logging.
76
+ *
77
+ * @returns The wrapped user code of the middleware.
78
+ */
67
79
function wrapMiddlewareCode ( originalCode : string , fileName : string ) : string {
68
80
return `
69
81
import { instrumentMiddlewareHandler } from '#imports';
0 commit comments