visit
We have been using
dd-trace-java
is a jar that contains APIs to automatically or manually
after you click ‘Next’, comes the most important part. You would be given the ‘agent setup’ instructions. My local machine is MacOSX, so I chose it appropriately. Please note down the DD_API_KEY and DD_SITE values, as they will be used in the subsequent steps.
For MacOS, you could install via
Customize the datadog-agent
as shown below
integrations
. You could add Java
, Docker
etc (as per your project needs).Download the dd-java-agent
jar from
For your Java application, make sure you’re using a version of Java that comes with an in-built FlightRecorder. This is needed for tracing. OpenJdK8 comes with an inbuilt FlightRecorder. If you’re using Oracle Java, you need a commercial license to use **FlightRecorder.**³
-javaagent:"/Users/home/Downloads/dd-java-agent.jar" -Ddd.profiling.enabled=true -Ddd.logs.injection=true -Ddd.agent.port=8126 -Ddd.service=ecommerce-service -Ddd.env=local -XX:FlightRecorderOptions=stackdepth=256
gradle
task, you can include the jvmArgs
as below:
jvmArgs = ["-javaagent:/Users/home/Downloads/dd-java-agent.jar", "-XX:FlightRecorderOptions=stackdepth=256", "-Ddd.profiling.enabled=true", "-Ddd.logs.injection=true", "-Ddd.agent.port=8126", "-Ddd.service=ecommerce-service", "-Ddd.env=local"]
macOS
— Config directory is ~/.datadog-agent/conf.d/java.d
and the file is present at ~/.datadog-agent/conf.d/java.d/conf.yaml
and now, the logs
should start flowing in Datadog.
Add appropriate debug
logs at the beginning and end of each method in your application. It’s very useful while debugging.
Add a mechanism to inject span id
and trace id
. It’s an amazing lifesaver and puts the logs in proper context.⁵
And voila! All of my end-to-end tests are passing now 🙂 Happy logging!
¹Alternatively, you could also download the
²Direct download the
³ Starting from JDK 11, we may use FlightRecorder
without activating anything. More details can be found
⁴More details are
⁵If your application is Java, you could you this library span_id
and trace_id
to the request.