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

Metric log messages missing fields with JSON format logs #171

Open
codermpl opened this issue Feb 4, 2025 · 1 comment
Open

Metric log messages missing fields with JSON format logs #171

codermpl opened this issue Feb 4, 2025 · 1 comment

Comments

@codermpl
Copy link

codermpl commented Feb 4, 2025

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 and Powertools for AWS Lambda 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".

@gordonpn
Copy link
Member

gordonpn commented Mar 9, 2025

Do you have more some code snippets of what your setup looks like? Or how you've set up the logger? What was it before and after? What is the current output?

It's rather hard to help you debug with so much information lacking.

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

2 participants