-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Here are some notes about logging with the AWS request ID.
The goal
Be able to see all logs of a single invocation.
How? By filtering using the "request ID".
How? By storing that request ID in each log record.
Is it not there already? It's there when logging from a JS lambda for example.
When logging from PHP (by writing to stdout/stderr), only the START, END and REPORT log lines contain it (the lines written by Lambda itself).
NodeJS runtime
exports.handler = async () => {
console.log('Hello from Lambda!');
};This is what we see in CloudWatch:
This is the same thing in Insights:
Analysis: the request ID is added in a non-structured text line. Values are separated by tabs (\t). For example:
2020-03-13T21:21:56.341Z 0879de55-0817-4d5c-9f37-7ed2755a72e1 INFO Hello from Lambda!
Current Bref PHP runtime
echo 'Hello world';In CloudWatch:
In Insights:
Analysis: the @requestId field (or the request ID value itself) does not appear in that record.
Experiment 1
echo json_encode([
'message' => 'Hello world!',
'requestId' => $context->getAwsRequestId(),
'@requestId' => $context->getAwsRequestId(),
]) . PHP_EOL;In CloudWatch:
In Insights:
Analysis: it looked promising at first, but it turns out the @requestId field is escaped to @@requestId by CloudWatch (or Lambda?).
That means that we still have no @requestId field. For example, this query does not return the lines we logged in PHP:
fields @message
| filter @requestId = '6dc9b447-3898-4793-83cf-60730058c833'
Experiment 2
Based on the tabulated format from the JS runtime, could it be that CloudWatch interprets data that way?
echo "2020-03-13T21:21:56.341Z\t{$context->getAwsRequestId()}\tINFO\tHello world" . PHP_EOL;CloudWatch:
Insights:
Analysis: OMG it works!!!
The field is correctly recognized now:
Even serverless logs parsed the fields:









