Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#25,481 1 comentário 0 reações 1 responsável Ver no GitHub

Mantenedores costumam responder em até 1 dia

@s1gr1d já está trabalhando nisso.

Desde 19/10/2026.

  • #25482 de @itisrmk — fechado sem integrar
  • #25527 de @s1gr1d — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
88/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript, node.js, typescript

Direção de pesquisa

Comece por getRouteMetadata em packages/server-utils/src/integrations/hapi/hapi-utils.ts e pelo caminho de wrapRouteHandler mostrado no stack trace e execute a reprodução do issue com node --import ./instrument.mjs server.mjs. Verifique como o handler encapsulado recebe a requisição resolvida e como o método dela é usado para o nome do span e para http.request.method. Concluir significa que as rotas configuradas por array não lançam mais erros, que /single e /multi retornam 200 sob o ciclo de vida estático do trace e que os metadados do método permanecem corretos.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
TypeScript
Estrelas
8.8k
Forks
1.9k
Merge médio
1d 12h
PRs com merge (30d)
598

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de getsentry/sentry-javascript

Todas as issues de getsentry/sentry-javascript

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.