hapijs / hapi-pino

🌲 Hapi plugin for the Pino logger
MIT License
148 stars 61 forks source link

Hapi proxy request error logged directly to console #108

Closed ncjones closed 4 years ago

ncjones commented 4 years ago

A bug in my Hapi H2o2 proxy mapUri function meant a header was being set as undefined and triggered an uncaught error internally in Hapi. This error was logged directly to the console without passing through Pino.

Example log message:

Debug: internal, implementation, error
    TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-Trace-Id"
    at ClientRequest.setHeader (_http_outgoing.js:536:3)
    at new ClientRequest (_http_client.js:249:14)
    at Object.request (http.js:46:10)
    at internals.Client._request (/work/node_modules/@hapi/wreck/lib/index.js:181:28)
    at internals.Client.request (/work/node_modules/@hapi/wreck/lib/index.js:75:26)
    at /work/node_modules/@hapi/h2o2/lib/index.js:164:45
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async exports.Manager.execute (/work/node_modules/@hapi/hapi/lib/toolkit.js:64:28)
    at async Object.internals.handler (/work/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at async exports.execute (/work/node_modules/@hapi/hapi/lib/handler.js:31:20)

The workaround is to disable Hapi debug mode (https://hapi.dev/api/?v=19.1.1#server.options.debug):

Hapi.server({
  host: 'localhost',
  port: 3000,
  debug: false,
})

Hapi-Pino should be writing all logs out as JSON without additional server config.

Versions:

@hapi/hapi@19.1.1 hapi-pino@8.0.0

mcollina commented 4 years ago

Is this possible to disable that debug mode programmatically? Would you like to send a PR to do so?

ncjones commented 4 years ago

I don't think so: https://github.com/hapijs/hapi/issues/2973