pinojs/pino-http

customProps always logs duplicate keys

オープン

#216 opened on 2022/05/05

 (37 件のコメント) (15 件のリアクション) (0 人の担当者)JavaScript (128 件のフォーク)github user discovery
buggood first issue

Repository metrics

Stars
 (694 個のスター)
PR merge metrics
 (平均マージ 1m) (30d で 2 merged PRs)

説明

customProps always logs duplicate keys.

I am working with google cloud logging and it doesn't play nicely with the duplicate keys:

    customProps(req) {
      // adds a custom object to all http logs that stackdriver
      // uses to make logs more informative and visible at a glance
      // see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest
      // for the details of the structured log messages
      return {
        httpRequest: {
          requestMethod: req.method,
          requestUrl: req.url,
          userAgent: req.headers['user-agent'],
          remoteIp:
            req.headers['x-forwarded-for']?.split(',').shift() ||
            req.socket?.remoteAddress,
        },
      };
    },

For instance: custom props cause the following log: "{ "httpRequest": {"method":"GET"},"httpRequest": {"method":"GET"}}"

ends up in stackdriver/google cloud logging looking like: {httpRequest: { method: 'GETGET' }}

related to https://github.com/pinojs/pino-http/pull/197

コントリビューターガイド