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

JSON logs are sent with cloudwatch log prefixes and not parsed #107

Closed
olanb7 opened this issue Mar 28, 2022 · 1 comment
Closed

JSON logs are sent with cloudwatch log prefixes and not parsed #107

olanb7 opened this issue Mar 28, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@olanb7
Copy link

olanb7 commented Mar 28, 2022

When writing JSON logs from the lambda (using, for example the AWS Power Tools Logger) the log message in New Relic is not parsed as JSON.

Description

The logs are not getting parsed as JSON because they are not being sent as JSON - they are including the cloudwatch log prefixes (timestamp, requestid, loglevel). The log message, when received in NewRelic looks like:

{
  "aws.lambda_request_id": "025f281a-8416-4f77-9271-27e90db13e12",
  "faas.execution": "025f281a-8416-4f77-9271-27e90db13e12",
  "faas.name": "test",
  "index": 859,
  "message": "2022-03-28T12:52:33.477Z\t025f281a-8416-4f77-9271-27e90db13e12\tINFO\t{\"cold_start\":false,\"function_arn\":\"arn:aws:lambda:eu-west-2:101:function:test\",...}\n",
  "newrelic.logPattern": "nr.DID_NOT_MATCH",
  "newrelic.source": "api.logs",
  "plugin": "newrelic-lambda-extension:2.1.0",
  "timestamp": 1648471953478
}

I was hoping that the newrelic lambda extension would allow me to take advantage of the JSON message parsing functionality, but due to the prefixes (and probably the trailing newline) this does not occur.

Steps to Reproduce

Sending any JSON to NewRelic via the lambda should recreate this problem.

console.log(JSON.stringify({"test": "this should be parsed by newrelic"})

Expected Behavior

JSON logs should be parsed using NewRelic's JSON message parsing functionality. Ideally there would be some configuration that could be toggled to let NewRelic know to expect JSON log messages, so it can remove leading/trailing characters.

I have looked through AWS's own documentation around this but have been unable to find anything that would allow configuration of the lambda console's output.

@olanb7 olanb7 added the bug Something isn't working label Mar 28, 2022
@olanb7
Copy link
Author

olanb7 commented Apr 8, 2022

Closing this, as it looks like this is an issue with the console.log implementation in lambda itself. For anyone else hitting this, the quick fix is to use something like pino or bunyan instead of console.log.

I've added some more detail to a bug ticket here: aws-powertools/powertools-lambda-typescript#747

Honeycomb have a note in their docs about this - might be useful to have something similar in the newrelic docs somewhere? https://docs.honeycomb.io/getting-data-in/integrations/aws/aws-lambda/#javascript

@olanb7 olanb7 closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant