This page provides requirements and an overview of the instrumentation process for Node.js functions.Before You Begin
After you have subscribed to Serverless APM for AWS Lambda and set up your environment variables, you can begin instrumentation. Ensure that your setup meets the following requirements:
Download the Node.js Serverless Tracer
To install the tracer, navigate to the directory where the package.json
file resides and run the following npm
command:
npm install appdynamics-lambda-tracer --save
JS
The command downloads the tracer dependency into a node_modules/
folder.
Add the Require Statement
To add the tracer to your application, add a require
statement in your application code's primary file that includes the AWS Lambda handler
function:
const tracer = require('appdynamics-lambda-tracer');
JS
Remember to add the tracer's require
statement before any other require
statement.
Instrument the Serverless Function with the Node.js Tracer
Initialize the Node.js Serverless Tracer below the require
statement, by calling the tracer.init
method.
To complete instrumentation, call tracer.mainModule(module)
as the last line of your code.
The code snippet below demonstrates how to instrument a serverless function with the tracer:
const tracer = require('appdynamics-lambda-tracer');
//Initialize the tracer
tracer.init();
// Your AWS Lambda handler function code here, for example:
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
//Complete the instrumentation
tracer.mainModule(module);
JS
By default, the Node.js Serverless Tracer automatically discovers exit calls passed over HTTP or inter-AWS Lambda calls. You need to create an exit call if your function does not use these protocols. See Node.js Serverless Tracer API.
Next Steps
You are now ready to Verify the Serverless Tracer Instrumentation.
You can then Integrate the Node.js Tracer with End User Monitoring or use the Node.js Serverless Tracer API.