-
Notifications
You must be signed in to change notification settings - Fork 878
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
Adding requestId prefix to lamda logs ahead of json #648
Comments
Line 122 in 248be4e
Pino is writing directly to the |
I think you could do something like: const pino = require('pino')()
exports.handler = function(event, context, callback) {
console.log('remaining time =', context.getRemainingTimeInMillis());
console.log('functionName =', context.functionName);
console.log('AWSrequestID =', context.awsRequestId);
const logger = pino.child({
awsRequestId: context.awsRequestId,
})
logger.info('hello world');
callback(null, context.functionName);
}; |
@mcollina Can you explain why the snippet would work? It's not super obvious to me. @jsumners Custom stream sounds like a good approach. I assume if we were to write directly console.log then sonic stream is not needed at all right? |
|
@tonyxiao that's entirely up to you. I'm not suggesting implementation details. I'm merely providing an idea. |
@tonyxiao, did you settle on a solution? |
@bfelbo yea I ended up doing console.log. Works well
|
I think we should have a Tbh, I think It would mean losing some features - for instance you wouldn't be able to pretty print. But honestly that is a bad idea on serverless (or server) anyway.. so... |
I'm not opposed. |
I’m +1. However we need a bit more API parity between the two.
Il giorno sab 14 set 2019 alle 21:02 James Sumners <[email protected]>
ha scritto:
… I'm not opposed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#648?email_source=notifications&email_token=AAAMXY55RQY5JYLK2CJZMBDQJUYLPA5CNFSM4HKIKTWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XCBYY#issuecomment-531505379>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAMXY547SZNLVIR3OAY6IDQJUYLPANCNFSM4HKIKTWA>
.
|
yeah.. also there's things in browser that don't apply to serverless, e.g. transmit option I think we could extract most of Then optionally |
For what it's worth, we have a library built on top of Pino that we use for logging in a lambda context at Cazoo: https://www.npmjs.com/package/cazoo-logger |
The above solutions didn't quite fit the native Cloudwatch format, so I created a drop in wrapper that preserves the native cloudwatch format. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
In lambda, when using console log aws automatically prepends the line with timestamp and request Id. However when using Pino this behavior is lost which makes it harder to find logs by aws
@requestId
in cloudwatch log insights. In fact in serverless / lambda console, pino logs for a given invocation do not even show up because they are missing this prefix.See example above. Question is - how to replicate lambda's behavior with pino logs?
The text was updated successfully, but these errors were encountered: