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

Log AWS and Custom Fields to AWS CloudWatch Log #115

Open
matthewdfuller opened this issue Jan 8, 2023 · 1 comment
Open

Log AWS and Custom Fields to AWS CloudWatch Log #115

matthewdfuller opened this issue Jan 8, 2023 · 1 comment

Comments

@matthewdfuller
Copy link

matthewdfuller commented Jan 8, 2023

I'm creating a Probot app using the sample code, like so:

const {
    createLambdaFunction,
    createProbot,
} = require("@probot/adapter-aws-lambda-serverless");
const appFn = require("./");

exports.handler = createLambdaFunction(appFn, {
    probot: createProbot(),
});

My NODE_ENV is set to production, which sets the pino logging output to JSON, which is logged to AWS CloudWatch.

Update: The environment variable is set, but the logging is not JSON; it's still pretty print.

However, the logs are missing some key pieces of information that I'd like to inject. Specifically: the AWS Request ID, CloudFront (or API Gateway) headers/trace IDs, and GitHub event IDs.

I found this issue that proposes something like:

const logger = pino.child({
      awsRequestId: context.awsRequestId,
})

But I can't figure out where to overwrite (or modify) the pino logger that Probot has already created.

Any ideas on where we could inject this additional info to make Lambda logs more useful?

@matthewdfuller
Copy link
Author

matthewdfuller commented Jan 8, 2023

In case it's helpful for other folks searching for similar issues, I was able to get the following mostly working:

const pino = require('pino')({
    prettyPrint: false,
    level: process.env['LOG_LEVEL']
});

const {
    createLambdaFunction,
    createProbot,
} = require("@probot/adapter-aws-lambda-serverless");
const appFn = require("./");

exports.handler = createLambdaFunction(appFn, {
    probot: createProbot({
        defaults: { 
            log: pino
        }
    }),
});

For some reason, the logger was not respecting the NODE_ENV environment variable and I had to set prettyPrint: false explicitly.

I'm still unsure how to inject the Lambda RequestID, since the above is creating the handler globally (i.e. not per invocation), so the typical Lambda context and event objects are not accessible.

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

No branches or pull requests

1 participant