微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Boot 与 Datadog 的集成

如何解决Spring Boot 与 Datadog 的集成

我有一个简单的 springboot 应用程序,并尝试将 datadog 代理与其集成,但无法使用 Javaagent 运行该应用程序。已完成以下步骤。

在 pom 中添加了依赖项。


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

解压 datadog 依赖并添加类 -----------

<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>

添加使spring repackager插件找到springboot主类-----------

<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

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






版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。