Enabling X-Ray Traces for DynamoDB
This tutorial references the code in the aws-connectedcar-dotnet-serverless repository. If you're new to this course, see the introduction for information about setting up your workstation and getting the sample code.
For both API Gateway and Lambda you can enable X-Ray traces with configuration alone, as covered in the previous lesson. To enable tracing into DynamoDB there’s no configuration required but you do have to add some extra client code, which is what we’ll step through here.
Enabling X-Ray Tracing for DynamoDB in C#
Let’s start with the constructor of the BaseFunctions.cs class in the C# sample code. To enable tracing with C# you have to add the call to the static method shown on line 23 below. This method, once called, ensures that all subsequent calls to the DynamoDB client interface will send trace data to CloudWatch:
Along with the extra line of code, shown above, you have to add two X-Ray-related libraries to the project references. These are shown below, on lines 11-12, from the ConnectedCar.Lambda.csproj file:
Enabling X-Ray Tracing for DynamoDB in Java
For Java, you have to instantiate a TracingInterceptor class in the DynamoDB client builder code, as shown below on lines 18-20. This is the TracingContext.java class from the aws-connectedcar-java-core repository. (The context classes are injected into the services, and provide access to configuration and client connectors at runtime):
Along with the Java code shown above, you need to add the three X-Ray maven dependencies to your project, as shown below from the pom.xml file for the services module in the same repository: