Instrumenting Java Applications
Rapport de recherche Datadog : Bilan sur l'adoption de l'informatique sans serveur Rapport : Bilan sur l'adoption de l'informatique sans serveur

Instrumenting Java Applications

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

After you have installed the AWS integration and the Datadog Forwarder, follow the steps below to instrument your application to send metrics, logs, and traces to Datadog.


Install the Datadog Lambda Library

You can install the Datadog Lambda Library locally by running one of the following commands based on your project’s configuration. For latest version, see the latest release.

Include the following dependency in your pom.xml:


Include the following in your build.gradle:

repositories {
  maven { url "" }
dependencies {
  implementation 'com.datadoghq:datadog-lambda-java:0.0.5'

Configure the Function

  1. Enable AWS X-Ray active tracing for your Lambda function.

Subscribe the Datadog Forwarder to the Log Groups

You need to subscribe the Datadog Forwarder Lambda function to each of your function’s log groups, in order to send metrics, traces and logs to Datadog.

  1. Install the Datadog Forwarder if you haven’t.
  2. Ensure the option DdFetchLambdaTags is enabled.
  3. Subscribe the Datadog Forwarder to your function’s log groups.

Explore Datadog Serverless Monitoring

After you have configured your function following the steps above, you should be able to view metrics, logs and traces on the Serverless Homepage.

If you would like to submit a custom metric, see the sample code below:

public class Handler implements RequestHandler<APIGatewayV2ProxyRequestEvent, APIGatewayV2ProxyResponseEvent> {
    public Integer handleRequest(APIGatewayV2ProxyRequestEvent request, Context context){
        DDLambda dd = new DDLambda(request, lambda);

        Map<String,String> myTags = new HashMap<String, String>();
            myTags.put("product", "latte");
        // Submit a custom metric
            "coffee_house.order_value", // Metric name
            12.45,                      // Metric value
            myTags);                    // Associated tags

        URL url = new URL("");
        HttpURLConnection hc = (HttpURLConnection)url.openConnection();

        // Add the datadog distributed tracing headers
        hc = (HttpURLConnection) dd.addTraceHeaders(hc);