question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

customProps always logs duplicate keys

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mcollinacommented, May 6, 2022

Your usecase is a bit far from mine.

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

1reaction
mpartelcommented, Sep 29, 2022

This seems to work:

const requestsSeen = new WeakSet();
// ...
customProps: (req) => {
  if (requestsSeen.has(req)) {
    return undefined;
  }
  requestsSeen.add(req);
  
  return { stuff };
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Template loop gives duplicate keys warning - Stack Overflow
Without unique information from the outer loop, the inner loop key will use the same set every time, so you end up with...
Read more >
Duplicate key name message during Sterling B2B Integrator ...
Problem. When starting Sterling B2B Integrator, similar messages as below are logged to the console: [Manager] getProperties(): Duplicate key ...
Read more >
Megalinks search engine - Spendy Market
MEGA provides free cloud storage with convenient and powerful always-on privacy. . ext. ... Log In Sign Up. me inurl:f/megalinks search terms. aka...
Read more >
gta 5 props list
The largest collection of vehicle customizations and custom props for GTA V. ... GTA 5 Cheats Xbox Series X. Craft, cooperation and team...
Read more >
All About "Do Not Duplicate" Keys - Door Locks Direct
Before buying any keyed locks, locksmiths always recommend that you check out the company's key duplication policy. If your locks are less ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found