@@ -170,7 +170,9 @@ for (const { name, prefix, origin } of SCENARIOS) {
170170}
171171
172172test . describe ( '.all() handler on sub-app (method ALL edge case)' , ( ) => {
173- test ( '.all() handler is instrumented and produces a span' , async ( { baseURL } ) => {
173+ test ( 'Node: OTel wraps .all() and produces a hono span' , async ( { baseURL } ) => {
174+ test . skip ( ! isNode , 'Node-specific: OTel wraps .all() at construction time' ) ;
175+
174176 const transactionPromise = waitForTransaction ( APP_NAME , event => {
175177 return (
176178 event . contexts ?. trace ?. op === 'http.server' && event . transaction === 'GET /test-subapp-middleware/all-handler'
@@ -186,29 +188,46 @@ test.describe('.all() handler on sub-app (method ALL edge case)', () => {
186188 const transaction = await transactionPromise ;
187189 const spans = transaction . spans || [ ] ;
188190
189- if ( isNode ) {
190- // On Node, OTel wraps .all() at construction time. Since the handler
191- // returns a Response, OTel classifies it as 'request_handler' (not
192- // middleware). patchRoute also wraps it but sees the anonymous OTel wrapper.
193- // Either way, the handler IS instrumented — verify any hono span exists.
194- const honoSpan = spans . find ( ( span : SpanJSON ) => span . op ?. endsWith ( '.hono' ) ) ;
195- expect ( honoSpan ) . toBeDefined ( ) ;
196- } else {
197- // On Bun/Cloudflare, patchRoute is the sole wrapper and sees the original
198- // function name. It wraps .all() handlers identically to .use() middleware
199- // because both produce method:'ALL' in Hono's route record.
200- const allHandlerSpan = spans . find (
201- ( span : SpanJSON ) => span . op === 'middleware.hono' && span . description === 'allCatchAll' ,
202- ) ;
191+ // On Node, OTel wraps .all() at construction time. Since the handler
192+ // returns a Response, OTel classifies it as 'request_handler' (not
193+ // middleware). patchRoute also wraps it but sees the anonymous OTel wrapper.
194+ // Either way, the handler IS instrumented — verify any hono span exists.
195+ const honoSpan = spans . find ( ( span : SpanJSON ) => span . op ?. endsWith ( '.hono' ) ) ;
196+ expect ( honoSpan ) . toBeDefined ( ) ;
197+ } ) ;
203198
204- expect ( allHandlerSpan ) . toEqual (
205- expect . objectContaining ( {
206- description : 'allCatchAll' ,
207- op : 'middleware.hono' ,
208- origin : MIDDLEWARE_ORIGIN ,
209- status : 'ok' ,
210- } ) ,
199+ test ( 'Bun/Cloudflare: patchRoute wraps .all() as middleware span' , async ( { baseURL } ) => {
200+ test . skip ( isNode , 'Bun/Cloudflare-specific: patchRoute is the sole wrapper' ) ;
201+
202+ const transactionPromise = waitForTransaction ( APP_NAME , event => {
203+ return (
204+ event . contexts ?. trace ?. op === 'http.server' && event . transaction === 'GET /test-subapp-middleware/all-handler'
211205 ) ;
212- }
206+ } ) ;
207+
208+ const response = await fetch ( `${ baseURL } /test-subapp-middleware/all-handler` ) ;
209+ expect ( response . status ) . toBe ( 200 ) ;
210+
211+ const body = await response . json ( ) ;
212+ expect ( body ) . toEqual ( { handler : 'all' } ) ;
213+
214+ const transaction = await transactionPromise ;
215+ const spans = transaction . spans || [ ] ;
216+
217+ // On Bun/Cloudflare, patchRoute is the sole wrapper and sees the original
218+ // function name. It wraps .all() handlers identically to .use() middleware
219+ // because both produce method:'ALL' in Hono's route record.
220+ const allHandlerSpan = spans . find (
221+ ( span : SpanJSON ) => span . op === 'middleware.hono' && span . description === 'allCatchAll' ,
222+ ) ;
223+
224+ expect ( allHandlerSpan ) . toEqual (
225+ expect . objectContaining ( {
226+ description : 'allCatchAll' ,
227+ op : 'middleware.hono' ,
228+ origin : MIDDLEWARE_ORIGIN ,
229+ status : 'ok' ,
230+ } ) ,
231+ ) ;
213232 } ) ;
214233} ) ;
0 commit comments