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

feat(lambda): log the lambda request id at the end of every request #1438

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/lambda/src/__test__/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ o.spec('LambdaFunction', () => {
const testFunc = LambdaFunction.wrap(asyncThrow, FakeLogger());

const spy = o.spy();
await testFunc({ httpMethod: 'GET' } as any, null as any, spy);
await testFunc({ httpMethod: 'GET' } as any, {} as any, spy);
o(spy.calls.length).equals(1);
const err = spy.args[0];
const res = spy.args[1] as ALBResult;
Expand All @@ -39,7 +39,7 @@ o.spec('LambdaFunction', () => {
const testFunc = LambdaFunction.wrap(asyncThrow, FakeLogger());

const spy = o.spy();
await testFunc({ Records: [{ cf: { request: { method: 'GET', headers: {} } } }] } as any, null as any, spy);
await testFunc({ Records: [{ cf: { request: { method: 'GET', headers: {} } } }] } as any, {} as any, spy);
o(spy.calls.length).equals(1);
const err = spy.args[0];
const res = spy.args[1] as CloudFrontResultResponse;
Expand Down Expand Up @@ -68,7 +68,7 @@ o.spec('LambdaFunction', () => {
}, fakeLogger);

const spy = o.spy();
await testFunc({ httpMethod: 'GET' } as any, null as any, spy);
await testFunc({ httpMethod: 'GET' } as any, {} as any, spy);
o(spy.calls.length).equals(1);
o(spy.args[1]).deepEquals(LambdaContext.toAlbResponse(albOk));

Expand Down
5 changes: 2 additions & 3 deletions packages/lambda/src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export class LambdaFunction {
// Trace cloudfront requests back to the cloudfront logs
const cloudFrontId = ctx.header(HttpHeaderAmazon.CloudfrontId);
const traceId = ctx.header(HttpHeaderAmazon.TraceId);
if (cloudFrontId != null || traceId != null) {
ctx.set('aws', { cloudFrontId, traceId });
}
const lambdaId = context.awsRequestId;
ctx.set('aws', { cloudFrontId, traceId, lambdaId });

ctx.set('package', { hash: process.env.GIT_HASH, version: process.env.GIT_VERSION });
ctx.set('method', ctx.method);
Expand Down