To fully instrument your serverless application with distributed tracing, your Java Lambda functions must be using the Java 8 Corretto (java8.al2), Java 11 (java11) or Java 17 (java17) runtime.
Install the Datadog Lambda Library locally by adding one of the following code blocks into pom.xml (Maven) or build.gradle (Gradle). Replace VERSION below with the latest release (omitting the preceding v):
Wrap your Lambda handler function using the wrapper provided by the Datadog Lambda Library:
publicclassHandlerimplementsRequestHandler<APIGatewayV2ProxyRequestEvent,APIGatewayV2ProxyResponseEvent>{publicIntegerhandleRequest(APIGatewayV2ProxyRequestEventrequest,Contextcontext){DDLambdaddl=newDDLambda(request,context);//Required to initialize the tracedo_some_stuff();make_some_http_requests();ddl.finish();//Required to finish the active span.returnnewApiGatewayResponse();}}
Cold starts occur when your serverless applications receive sudden increases in traffic, including when the function was previously inactive or when it was receiving a relatively constant number of requests. Users may perceive cold starts as slow response times or lag. Datadog recommends you configure a monitor on Java Lambda function cold starts, and use Datadog Serverless Insights to keep cold starts to a minimum.
To create a Datadog monitor on Java Lambda function cold starts, follow the monitor creation steps with the following criteria:
Metric Name: aws.lambda.enhanced.invocations
From: runtime:java* and cold_start:true
Alert Grouping: Multi Alert, trigger a separate alert for each function_arn
Although it is optional, Datadog recommends tagging your serverless applications with the reserved tags env, service, and version. For more information about reserved tags, see the Unified Service Tagging documentation.
Failing to use the correct Java runtime can result in errors, for example: Error opening zip file or JAR manifest missing : /opt/java/lib/dd-java-agent.jar. Make sure to use java8.al2 or java11 as your runtime, as described above.
The Apache Foundation has announced that log4j, a popular Java logging library, is vulnerable to remote code execution.
Some versions of datadog-lambda-java include a transitive dependency on log4j that may be vulnerable. The vulnerable versions are:
<=0.3.3
1.4.0
The latest version of datadog-lambda-java is . Use this version (omitting the preceeding v) when following the upgrading instructions below.
If you do not wish to upgrade to 1.4.x, 0.3.x is updated with the latest log4j security patches as well.
You may find the latest version of 0.3.x in the datadog-lambda-java repository.
The version of the datadog-lambda-java dependency in your Lambda function is set in pom.xml (Maven) or build.gradle (Gradle).
Replace VERSION with the latest version of datadog-lambda-java (available above).
Then redeploy your Lambda function.
If you are upgrading from 0.3.x to 1.4.x and you wish to use the dd-trace-java tracer, find the reference to the dd-trace-java Lambda layer and change it to: