Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Hapi: `route.method.toUpperCase is not a function` for routes registered with an array of methods

Đang mở Phù hợp với người mới
#25,481 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@s1gr1d đang làm issue này rồi.

Từ ngày 19/10/2026.

  • #25482 của @itisrmk — đã đóng, không merge
  • #25527 của @s1gr1d — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
backend, observability

Hướng nghiên cứu

Bắt đầu với getRouteMetadata trong packages/server-utils/src/integrations/hapi/hapi-utils.ts và đường dẫn wrapRouteHandler được hiển thị trong stack trace, sau đó chạy bản tái hiện trong issue với node --import ./instrument.mjs server.mjs. Kiểm tra xem handler được bọc nhận request đã phân giải như thế nào và phương thức của request được dùng ra sao cho tên span và http.request.method. Hoàn tất nghĩa là các route được cấu hình bằng array không còn ném lỗi, cả /single và /multi đều trả về 200 dưới vòng đời trace tĩnh và metadata của phương thức vẫn đúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Hapi Waiting for: Product Owner
Is there an existing issue for this?
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

Ngôn ngữ chính
TypeScript
Star
8.8k
Fork
1.9k
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
598

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry-javascript

Tất cả issue của getsentry/sentry-javascript

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.