Instrument with CommonJS
-
To install the tracer, navigate to the directory where the
package.jsonfile resides.Run the following
npmcommand:npm install appdynamics-lambda-tracer --saveThe command downloads the tracer dependency into a
node_modules/folder. -
Initialize the Node.js Serverless Tracer below the require statement, by
calling the
tracer.initmethod.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);