-
Notifications
You must be signed in to change notification settings - Fork 309
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
Inject trace ids into paperplane logs #633
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting is failing because of the console.*
statement. Feel free to disable this ESLint rule on the block since these are necessary for the tests.
} | ||
|
||
module.exports = { | ||
name: 'paperplane', | ||
versions: ['>=2.3'], | ||
versions: ['>=2.3.1'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the version bump?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this was needed to make log injection work for errors:
articulate/paperplane#46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support for 2.3.0 could be kept but would just be missing log injection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, that's a good point. Let me see if I can make that work (probably on Monday). When I do, should I document that difference somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see if I can make that work
You can find a good example of different feature support by version in the hapi plugin.
When I do, should I document that difference somewhere?
I would say to add a note in the docs, or simply add paperplane
to the list of supported loggers with >=2.3.1
as the version.
@rochdev, thanks for the heads up on the linting. I ran |
@rochdev, we realized that patching the However, I was able to continue support for |
@flintinatux Is it supported to use the logger outside the scope of For that to work, the logger (and thus |
That wasn't really an intended use case for us, mostly because I always thought you had to require the Are there plugins that can patch after-the-fact like that? |
Oh, but the answer to your first question: yes, we do use |
Loggers mostly 😅. It can work in some cases with other plugins as well, but the ones that we explicitly tested were loggers since to use them with the tracer they have to be imported beforehand. Do you think there's a way this could work with |
I wonder if some kind of check could be added if the logger was already patched, and patch it otherwise, in both the public API and the internal one. This would technically result in 2 different logger instances when patched after the fact, but in general that wouldn't cause issues. @flintinatux Do you think that would work? Another option could be to proxy the call in the index, so that it's just delegating to the underlying logger 🤔 Something like |
If I had to guess, it works for other loggers because they are OOP, so they can patch the That won't work for However, I think you could work around it with the magic of javascript variable scoping: // wrap it as a custom logger
const myLogger = x =>
paperplane.logger(x)
// init with your custom logger
const tracer = require('dd-trace').init({ logger: myLogger })
// then require paperplane after it's been patched
const paperplane = require('paperplane') |
Makes sense. This won't work for anything logged while the tracer is initializing, but I think that's a reasonable limitation. We could always solve this in the tracer by deferring the actual call to the logger to the next tick. |
What does this PR do?
Adds support for log injection in
paperplane
.Motivation
When I first made the plugin for
paperplane
, I followed the examples ofexpress
andhapi
. Those don't have built-in logging, butpaperplane
does, and I totally overlooked it. We'd like our logs to be correlated with traces in APM, so this PR aims to enable that.Plugin Checklist
Additional Notes
This does bump the supported version of
paperplane
tov2.3.1
. That's because log injection on error logs doesn't work before that version.