AWS Developer Blog

X-Ray support for the AWS SDK for Java V2

We’re pleased to announce that the AWS X-Ray SDK for Java now supports generating trace data for the AWS SDK for Java 2.2+.

Whenever you make a call to a downstream AWS service with an instrumented client, the SDK records information about the call in a subsegment. AWS services and the resources that you access within the services appear as downstream nodes on the service map to help you identify errors and throttling issues on individual connections.

Prerequisites

To enable generating trace data from API calls made by the AWS SDK for Java 2.2+ service clients you’ll first need your application to be configured to trace incoming requests. The AWS X-Ray SDK for Java also requires a minimum version of 2.2.0 for the AWS SDK for Java.

Automatic Instrumentation

Starting with release 2.2.0 of the AWS X-Ray SDK, you can now instrument your AWS SDK clients by including the aws-xray-recorder-sdk-aws-sdk-v2-instrumentor module in your build configuration. This will automatically instrument every AWS SDK service client.

Manual Instrumentation

In some cases it may be desirable to instrument downstream calls to a subset of AWS services. In this case, you can omit the aws-xray-recorder-sdk-aws-sdk-v2-instrumentor module from your build configuration, and include the aws-xray-recorder-sdk-aws-sdk-v2 module instead. Then you can instrument individual clients by configuring them with a TracingInterceptor. Let’s take a look at an example of how we would configure an AWS SDK Amazon DynamoDB client.

import com.amazonaws.xray.interceptors.TracingInterceptor;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;

//...

public class MyModel {
  private DynamoDbClient client = DynamoDbClient.builder()
    .region(Region.US_WEST_2)
    .overrideConfiguration(ClientOverrideConfiguration.builder()
      .addExecutionInterceptor(new TracingInterceptor())
      .build()
    )
    .build();

//...

}

Give It a Try!

Let us know what you think about this feature on GitHub or in the comments below!