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.
Setting up Lambda monitoring
- From the Dynatrace web interface, select Deploy Dynatrace from the navigation menu.
- Click the Set up Serverless integraton button.
- Select Node.js on the following page.
- 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 npx dt-oneagent-tailor --AwsLambdaV4 # To prepare the package for Node.js 6 run npx dt-oneagent-tailor --AwsLambdaV6 # To prepare the package for Node.js 8 run npx dt-oneagent-tailor --AwsLambdaV8 # To get a list of all options run npx dt-oneagent-tailor
npx is bundled with recent versions of npm - if it is not yet installed, install it with
npm install -g npx)
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.
Tracing calls via AWS SDK
Starting with OneAgent version 1.147, SDK calls from Node.js and Java to Lambda are fully supported and traced end-to-end.