awslabs / awslabs/aws-embedded-metrics-node
Metric log messages missing fields with JSON format logs
- Dominant language
- TypeScript
- Stars
- 263
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I'm having issues with my metrics after turning on JSON format logs for my Lambda. The documentation says:
> To ensure that your functions' EMF logs continue to be properly parsed by CloudWatch, update your [EMF](https://github.com/awslabs/aws-embedded-metrics-node) and [Powertools for AWS Lambda](https://github.com/aws-powertools/powertools-lambda-typescript) libraries to the latest versions.
https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html#nodejs-logging-advanced-emf
I have updated to the latest version of aws-embedded-metrics-node (4.2.0).
My basic code:
```
metricsClient.putMetric(MetricName, Value, Unit ?? undefined);
await metricsClient.flush();
```
However, my logs are missing a few fields mentioned in https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html, "Using structured JSON logs with Node.js" section of the doc says the following fields should be in the JSON, but they are missing from the JSON that aws embedded metrics node productes in the logs
```
"timestamp" - the time the log message was generated
"level" - the log level assigned to the message
"message" - the contents of the log message
"requestId" - the unique request ID for the function invocation
```
It would be nice if all 4 fields were in the logs for standardization.
But the big issue is `@requestId` is sent to the metric's log in plain text mode. But in JSON format mode, neither `@requestId` or `requestId` is logged. RequestID is useful for correlating a specific data point to a Lambda invocation. Also, example shows requestId: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html under "Using embedded metric format (EMF) client libraries with structured JSON logs".
Contributor guide
Research direction
Reproduce the reported output using the aws-embedded-metrics-node example with JSON-format Lambda logs and the shown putMetric/flush calls. Compare JSON and plain-text EMF output, then verify whether timestamp, level, message, and requestId are present and usable for correlating a metric with its invocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100