How do I integrate Node.js Lambda Functions?

AWS Lambda lets you run code without provisioning or managing servers. This deployment model is sometimes also referred to as "Serverless" or "Function as a Service (FaaS)." Technically, a Lambda function runs in an application on a container managed by AWS. This lets you focus on writing code without worrying about the underlying application or infrastructure. Lambda functions are ephemeral. This means that the underlying container can be suspended or recycled when there is no request pending. Also, Lambda functions can only process one request at a time. When there are (n) concurrent requests, (n) containers are created. All this is completely transparent to the developer.

Lambda functions written in Node.js can be monitored with the OneAgent NPM module.

AWS Lambda support for Node.js is currently available via an Early Access Program. EAP features are considered in their final stages of development. They are not considered production ready and there is no official support for them at this time. Interested customers can request inclusion in the Early Access Program to sample and provide feedback related to this new functionality. Customers who want to join the EAP will be put in direct contact with the responsible Dynatrace Product Manager who will decide if the customer's environment is suitable for the EAP in question. See this post on Dynatrace Answers to learn how to join the early access program for AWS Lambda.

Setting up Lambda monitoring

  1. From the Dynatrace web interface, select Deploy Dynatrace from the navigation menu.
  2. Click the Set up Serverless integraton button.
  3. Select Node.js on the following page.
  4. Follow the displayed instructions

Optimizing the npm module for Lambda

The Dynatrace npm module contains instrumentation code for a variety of Node.js versions. As a Lambda function is always configured to run a specific version of Node.js, it makes sense to only bundle those parts of OneAgent that are applicable to this version.

To do this, go to the base directory of your application and execute

# To prepare the package for Node.js 4 run
./node_modules/\@dynatrace/oneagent/lib/pkgtailor.js --AwsLambdaV4

# To prepare the package for Node.js 6 run
./node_modules/\@dynatrace/oneagent/lib/pkgtailor.js --AwsLambdaV6

# To prepare the package for Node.js 8 run
./node_modules/\@dynatrace/oneagent/lib/pkgtailor.js --AwsLambdaV8

# To get a list of all options run

Transactional tracing of Lambda invocations

Lambda functions can be triggered by a variety of so called "Event Sources." For end-to-end monitoring, events coming from API Gateway or AWS SDK are the most relevant. Such calls will be traced through, continuing the transaction from the calling application.

Lambda calls from other event sources (like Alexa) will create a new transaction for each invocation.

Configuring the AWS API Gateway

The API Gateway needs to be configured to pass through the Dynatrace tag. To accomplish that, enable 'Use Lambda Proxy Integration' on the 'Integration Request' configuration page of the API Gateway. If the API Gateway is configured from the Lambda configuration page, this setting will be enabled by default. AWS Lambda proxy integration setting for API Gateway

Tracing calls via AWS SDK

Instrumentation of Lambda invocations via AWS SDK is not currently available.