简体   繁体   中英

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

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






Spring boot with statsd client sending metrics and logs to a local agent.

https://github.com/ebett/spring-boot-datadog

Hope it can help you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM