Iqbal´s DLQ main Help

Tracing in native image - Datadog

After successfully launching the spring context, in Road to Native Image (Spring Boot 3+), I've sense checked API, and added more reflection data from the agent, mainly POJOs that the native image couldn't deserialize.

This article aims at restoring observability via Datadog, particularly for traces.

Datadog relies on java agent that gets passed to the JVM in runtime to instrument the app for traces, however, we are no longer running on the JVM, let's see how we can can build a native image that supports datadog's agent instrumentation:

Setup

What you'll need are 3 elements;

1. The Datadog agent:

Terminology is a bit loose here, this is not the java agent, it's an agent provided by Datadog as well that forwards your traces to the datadog endpoints:

Install :

Configure via the datadog.yaml file:

site: <site> api_key: <api_key> apm_config: enabled: true receiver_port: <port, defaults to 8126>

Check the agent status in the Datadog Agent Manager on http://localhost:5002

You should be able to see this :

Endpoints <datadog endpoint> - API Key ending with: - <last 5 characters of yoru api key>

2. The Java Jar agent:

Download the jar provided by DD:

3. The Datadog libraries for custom instrumentation (optional):

Spring Boot is fully supported through spring-web / spring-webflux

Build Native Image with Datadog Agent:

At properties level:

management: datadog: metrics: export: apiKey: '<api_key>' application-key: '<app_key>' enabled: true uri: '<datadog_site_endpoint>'

Pass it to native image plugin arguments:

<plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <configuration> <buildArgs> <arg>-Ob</arg> <arg>-J-javaagent:/path/to/agent/dd-java-agent.jar</arg> ...

Rebuild your native image :

mvn -Pnative package -DskipTests

Run with a custom service identifier for instance:

spring_profiles_active=local DD_SERVICE=native_traces ./target/executable-name.exe

Traces

Check if your traces are being sent to DD Agent on the Agent Manager:

traces_received.png

On the DD APM UI, check that you are receiving traces, here is a metric push example that was captured:

captured_trace_metric.png
Last modified: 22 January 2025