Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,65 @@ functions:

Make sure to configure your GitHub App registration's webhook URL to `<your lambda's URL>/api/github/webhooks`.

## Logging invocation IDs

To include Lambda and request trace IDs in JSON logs, supply a Pino logger and
use `AsyncLocalStorage` to associate fields with each invocation. Install Pino
directly in your application:

```shell
npm install pino
```

```javascript
// handler.js
import { AsyncLocalStorage } from "node:async_hooks";
import pino from "pino";
import {
createLambdaFunction,
createProbot,
} from "@probot/adapter-aws-lambda-serverless";
import appFn from "./index.js";

const invocation = new AsyncLocalStorage();
const log = pino({
level: process.env.LOG_LEVEL || "warn",
mixin() {
return { ...invocation.getStore() };
},
});

const handle = createLambdaFunction(appFn, {
probot: createProbot({ defaults: { log } }),
});

export const lambdaFn = (event, context) => {
const headers = Object.fromEntries(
Object.entries(event.headers ?? {}).map(([name, value]) => [
name.toLowerCase(),
value,
]),
);

return invocation.run(
{
awsRequestId: context.awsRequestId,
apiGatewayRequestId: event.requestContext?.requestId,
traceId: headers["x-amzn-trace-id"],
cloudFrontRequestId: headers["x-amz-cf-id"],
},
() => handle(event, context),
);
};
```

The supplied Pino logger outputs JSON independently of `NODE_ENV` and
`LOG_FORMAT`. Probot adds the GitHub delivery ID as `id` to event-handler
logs. Invocation fields are available to logs created within the invocation's
async context, not to startup logs emitted before it. Some request fields may
be absent depending on the AWS integration. Log only selected headers rather
than all headers, which may contain secrets.

## Test deployment

For testing your Probot deployment without end to end (GitHub) integration, you can use this shell snippet:
Expand Down