Instrument with CommonJS
-
To install the tracer, navigate to the directory where the
package.json
file resides.Run the following
npm
command:npm install appdynamics-lambda-tracer --save
The command downloads the tracer dependency into a
node_modules/
folder. -
Initialize the Node.js Serverless Tracer below the require statement, by
calling the
tracer.init
method.tracer = require('appdynamics-lambda-tracer'); //Initialize the tracer tracer.init();
-
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:
// 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);