Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Request ID generators #670

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

slavafomin
Copy link

@slavafomin slavafomin commented Jul 26, 2021

When processing HTTP requests, it's a good practice to specify a unique request ID value for each log entry. This way, multiple log entries could be grouped together according to the specified request ID, which dramatically helps in debugging/analysing
requests processing.

This PR allows to specify custom request ID generation function for logger instances. Which opens a path for easy cls-rtracer integration. Please see the updated README for more details and examples.

This should be considered a non-breaking minor release.


  • added support for Request ID generators
  • introduced optional req_id property that can be passed to the logger constructor
  • added tests
  • updated README
  • updated .gitignore file to exclude IDEA files
  • arranged AUTHORS alphabetically
  • fixed "engines" property of the package manifest
  • added myself as an author

So I'm not sure regarding the maintenance status of this project, I've created and published a forked version of the library, so it could be used straight away if someone would want to.

- introduced optional `req_id` property that can be passed to the logger constructor
- added tests
- updated README
- updated .gitignore file to exclude IDEA files
- arranged AUTHORS alphabetically
- fixed "engines" property of the package manifest
- added myself as an author

Signed-off-by: Slava Fomin II <[email protected]>
Signed-off-by: Slava Fomin II <[email protected]>
Signed-off-by: Slava Fomin II <[email protected]>
@slavafomin
Copy link
Author

Hello @trentm, could you look into this, please?

@LewisCowlesMotive
Copy link

Feels like it should be separate to a logger, and bound to .child

@jmaver-plume
Copy link

Any updates on this?

@jmaver-plume
Copy link

For anyone who wants to use something similar, you can take advantage of the get accessor property.

const logger = bunyan.createLogger({ ...options })
Object.defineProperty(log.fields, 'traceId', {
  enumable: true,
  get: function () {
    return 'some-id' // e.g., you can retrieve it from AsyncLocalStorage
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants