This is one step of enabling New Relic's AWS Lambda monitoring.
New Relic provides working minimal examples as a starting point for instrumenting your own serverless functions, so that you can become familiar with the necessary elements, test the account link, and use them as a reference for your own instrumentation.
While there are many ways to manage and deploy Lambda functions, AWS CloudFormation is the mechanism we use for our examples. It requires minimal tooling, has first-party support, and underpins many of the third party deployment options as well.
Each of our basic examples is functionally identical, and illustrates the following New Relic features:
- Sending invocation telemetry to New Relic, via the New Relic Lambda Extension
- Adding custom attributes to the invocation event
- Adding custom events to the telemetry
In addition, each demonstrates:
- Using the New Relic Lambda layer with your function
- Adding permissions to the function to access the AWS Secrets Manager and retrieve the New Relic license key
- Runtime-specific techinques for wrapping your handler, so that New Relic can capture telemetry
- Managing function log retention in CloudWatch
- Optionally, forwarding function logs to New Relic's logging product via the Lambda Extension
Our examples are published, alongside the New Relic Lambda Extension, in this GitHub repository. There's one for each Lambda runtime that New Relic can instrument:
As you test the examples, you may notice that telemetry isn't always sent right away. The AWS Lambda lifecycle places certain constraints on the execution of our agent and Lambda Extension. In addition, valuable platform telemetry is only available after an invocation has completed. The New Relic Extension balances overall performance against the need for timely telemetry delivery by buffering telemetry for a period of time, and delivering it to New Relic in batches, during a subsequent invocation (or during shutdown).
In a production function, we find this works very well. When manually testing, it's often necessary to wait seven seconds, and then invoke a function again to give it an opportunity to deliver previously buffered telemetry.
While we make an effort to keep the templates in our examples up to date, you can always find the latest New Relic Lambda layer for your region and runtime at our layers site. This site also offers an API, which you're welcome to use in your CI/CD pipeline to keep your own templates up to date.
In addition to our basic examples, we offer an example of how to integrate distributed tracing into a non-trivial serverless application in our distributed tracing example. It illustrates manual trace propagation for SQS and SNS, two of the more popular services that might invoke Lambda functions, with Node, Python and Java functions.
While you wait for your data to come in...
Did this doc help you install?