On this page:

Your Rating:
Results:
PatheticBadOKGoodOutstanding!
0 rates
This topic 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

In your function's package.json file, declare a dependency on the Node.js Serverless Tracer, appdynamics-lambda-tracer. The name, version, and dependencies fields are required. 

{
  "name": "my-test-package",
  "version": "0.0.1", 
  "main": "handler.js",
  "dependencies": {
    "appdynamics-lambda-tracer": "latest" 
  }
}


To install the agent, navigate to the directory where the package.json file resides and run the npm installation command:

npm install 

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');

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);

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 Customize the Node.js Serverless Tracer.

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 Customize the Node.js Serverless Tracer

  • No labels