Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot integration with Datadog

I have a simple springboot application and trying to integrate datadog agent with that but couldn't run the application with Javaagent. Have done the following steps.

Added dependency in the pom.


    <dependency>
    <groupId>com.datadoghq</groupId>
    <artifactId>dd-java-agent</artifactId>
    <version>0.83.2</version>
    </dependency>

unpack datadog dependencies and added classes -----------

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>dd-java-agent</includeArtifactIds>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
added premain class of datadog agent -----

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.5</version>
    <configuration>
    <archive>
    <manifestEntries>
    <Premain-Class>datadog.trace.bootstrap.AgentBootstrap</Premain-Class>
    <Can-Redefine-Classes>true</Can-Redefine-Classes>
    <Can-Retransform-Classes>true</Can-Retransform-Classes>
    </manifestEntries>
    </archive>
    </configuration>
    </plugin>

Added To make spring repackager plugin to find springboot main class-----------

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<mainClass>com.user.info.userInfoApplication</mainClass>
</configuration>
</plugin>

        
Finally when issuing below command fails 

    java -javaagent:user-info-0.0.1-SNAPSHOT.jar -jar user-info-0.0.1-SNAPSHOT.jar
    
    Exception in thread "main" java.lang.ClassNotFoundException: datadog.trace.bootstrap.AgentBootstrap
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
            at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:431)
            at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
    FATAL ERROR in native method: processing of -javaagent failed

```````````````````````````````````````````````````````````````````````````````````````````






like image 457
Sasivarnan Manickam Avatar asked Oct 26 '25 14:10

Sasivarnan Manickam


1 Answers

Spring Boot 2.x supports the integration with DataDog. Just add the dependency in your pom.xml:

    <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-datadog</artifactId>
        </dependency>

Then follow this page: https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.export.datadog

like image 154
heq99 Avatar answered Oct 29 '25 02:10

heq99



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!