Hapi: `route.method.toUpperCase is not a function` for routes registered with an array of methods
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 88/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js, typescript
- 領域
- backend, observability
研究方向
先查看 packages/server-utils/src/integrations/hapi/hapi-utils.ts 中的 getRouteMetadata,以及 stack trace 中顯示的 wrapRouteHandler 路徑,然後執行 issue 中的 node --import ./instrument.mjs server.mjs 重現方式。檢查被包裝的 handler 如何接收已解析的請求,以及請求方法如何用於 span 名稱和 http.request.method。完成的標準是:透過 array 設定的路由不再拋出例外,/single 和 /multi 在靜態 trace 生命週期下都回傳 200,且方法 metadata 維持正確。
由索引模型根據 Issue 內容生成。
描述
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node - hapi
SDK Version
11.5.0; also present in 11.8.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
instrument.mjs:
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: 'https://[email protected]/1',
tracesSampleRate: 1,
traceLifecycle: 'static',
});
server.mjs:
import Hapi from '@hapi/hapi';
const server = Hapi.server({ port: 0 });
server.route({ method: ['GET', 'POST'], path: '/multi', handler: () => 'ok' });
server.route({ method: 'GET', path: '/single', handler: () => 'ok' });
await server.start();
for (const path of ['/single', '/multi']) {
const res = await fetch(server.info.uri + path);
console.log(path, res.status);
}
await server.stop();
Run node --import ./instrument.mjs server.mjs
Expected Result
Both requests return 200.
Actual Result
/single returns 200; /multi returns 500:
TypeError: route.method.toUpperCase is not a function
at getRouteMetadata (@sentry/server-utils/src/integrations/hapi/hapi-utils.ts:132:73)
at <anonymous> (@sentry/server-utils/src/integrations/hapi/hapi-utils.ts:202:24)
at exports.Manager.execute (@hapi/hapi/lib/toolkit.js:57:29)
at internals.handler (@hapi/hapi/lib/handler.js:46:48)
...
With the default traceLifecycle ('stream'), both return 200.
Additional Context
Hapi accepts method as a string or an array of strings. wrapRouteHandler passes the route config given to server.route() to getRouteMetadata. For non-streamed spans, that builds the span name as `${route.method.toUpperCase()} ${route.path}`, which assumes a string. The streamed-span branch only uses route.path, which is why the default lifecycle is unaffected. Either way, the array also ends up in the http.request.method attribute.
A possible fix: inside the wrapped handler, read the method from the request (request.method, which Hapi has already resolved to one lowercase method) rather than from the route config.
Priority
No response
- 主要語言
- TypeScript
- 星號
- 8.8k
- 分支
- 1.9k
- 平均合併
- 1 天 12 小時
- 30 天內合併 PR
- 598
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
getsentry/sentry-javascript 的其他 Issue
-
node:http client span never ends when the response is destroyed without an error (res.destroy())可能已有人在做 @4ktLuffy 於 1 天前認領。 未關閉Bug Node.js
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-javascript#25469 · 2 則留言 ·
維護者通常 1 天內回覆
-
Core Feature: Typescript Meta: Breaking
難度 2/5 1-3 小時 新手友好度 65/100
getsentry/sentry-javascript#25286 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 80/100
getsentry/sentry-javascript#24860 · 1 則留言 ·
維護者通常 1 天內回覆
-
javascript
難度 2/5 1-3 小時 新手友好度 75/100
getsentry/sentry-javascript#24200 · 2 則留言 ·
維護者通常 1 天內回覆
-
Cloudflare Workers javascript Tests
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-javascript#24051 · 1 則留言 ·
維護者通常 1 天內回覆
查看 getsentry/sentry-javascript 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 77/100
melgarafael/DeskcommCRM#3104 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug service: webapp
難度 2/5 1-3 小時 新手友好度 82/100
Ocelot-Social-Community/Ocelot-Social#10684 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
nicobailon/pi-subagents#2978 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 66/100
getsentry/sentry-conventions#732 · 1 則留言 ·
維護者通常 1 天內回覆