@@ -8,7 +8,7 @@ const patchedUseInstances = new WeakSet<Hono<any>>();
88// oxlint-disable-next-line typescript/no-explicit-any
99const patchedMethodInstances = new WeakSet < Hono < any > > ( ) ;
1010
11- const HTTP_METHODS = [ 'get' , 'post' , 'put' , 'delete' , 'options' , 'patch' , 'all' ] as const ;
11+ const HTTP_METHODS = [ 'get' , 'post' , 'put' , 'delete' , 'options' , 'patch' , 'all' , 'query' ] as const ;
1212
1313/**
1414 * Patches `app.use` (instance own property) on a Hono instance to instrument middleware at registration time.
@@ -40,7 +40,7 @@ export function patchAppUse<E extends Env>(app: Hono<E>): void {
4040}
4141
4242/**
43- * Patches HTTP method class fields (get, post, put, delete, options, patch, all) to instrument inline middleware at registration time.
43+ * Patches HTTP method class fields to instrument inline middleware at registration time.
4444 *
4545 * For `app.get('/path', mw1, mw2, handler)`, all handlers except the last are middleware and get wrapped with spans.
4646 * The final handler (the route handler) is already covered by the root http.server transaction.
@@ -54,19 +54,13 @@ export function patchHttpMethodHandlers<E extends Env>(app: Hono<E>): void {
5454 patchedMethodInstances . add ( app ) ;
5555
5656 for ( const method of HTTP_METHODS ) {
57- app [ method ] = new Proxy ( app [ method ] , {
58- apply ( target , thisArg , args : unknown [ ] ) {
59- return Reflect . apply ( target , thisArg , wrapInlineMiddleware ( args ) ) ;
60- } ,
61- } ) ;
57+ patchRegistrationMethod ( app , method , wrapInlineMiddleware ) ;
6258 }
6359
64- app . on = new Proxy ( app . on , {
65- apply ( target , thisArg , args : unknown [ ] ) {
66- // .on(method, path, ...handlers) — first two args are method and path
67- const [ method , path , ...handlers ] = args ;
68- return Reflect . apply ( target , thisArg , [ method , path , ...wrapInlineMiddleware ( handlers ) ] ) ;
69- } ,
60+ patchRegistrationMethod ( app , 'on' , args => {
61+ // .on(method, path, ...handlers) — first two args are method and path
62+ const [ method , path , ...handlers ] = args ;
63+ return [ method , path , ...wrapInlineMiddleware ( handlers ) ] ;
7064 } ) ;
7165}
7266
@@ -89,3 +83,17 @@ function wrapInlineMiddleware(args: unknown[]): unknown[] {
8983 }
9084 return wrapped ;
9185}
86+
87+ function patchRegistrationMethod ( app : object , method : string , transformArgs : ( args : unknown [ ] ) => unknown [ ] ) : void {
88+ const registration : unknown = Reflect . get ( app , method ) ;
89+ if ( typeof registration !== 'function' ) {
90+ return ;
91+ }
92+
93+ const patchedRegistration = new Proxy ( registration , {
94+ apply ( target , thisArg , args : unknown [ ] ) {
95+ return Reflect . apply ( target , thisArg , transformArgs ( args ) ) ;
96+ } ,
97+ } ) ;
98+ Reflect . set ( app , method , patchedRegistration ) ;
99+ }
0 commit comments