Skip to content

Commit 4ff3736

Browse files
authored
Spring boot: autodetect service name from environment (#6663)
* Spring boot: autodetect service name from environment * update tests * use new instrumenter module * make spring-boot service name guessing disabled by default * collect new service name when updated
1 parent f709af0 commit 4ff3736

23 files changed

Lines changed: 520 additions & 40 deletions

File tree

dd-java-agent/agent-tooling/src/main/resources/datadog/trace/agent/tooling/bytebuddy/matcher/ignored_class_name.trie

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
0 org.springframework.beans.factory.support.AbstractBeanFactory
259259
0 org.springframework.beans.factory.support.DefaultListableBeanFactory
260260
0 org.springframework.beans.factory.support.DisposableBeanAdapter
261+
0 org.springframework.boot.SpringApplicationRunListeners
261262
1 org.springframework.boot.SpringApplicationShutdownHook$Handlers
262263
1 org.springframework.boot.autoconfigure.ssl.FileWatcher$WatcherThread
263264
2 org.springframework.boot.*
@@ -274,6 +275,8 @@
274275
0 org.springframework.boot.web.embedded.tomcat.TomcatWebServer$1
275276
0 org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
276277
0 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext
278+
0 org.springframework.boot.web.servlet.support.SpringBootServletInitializer
279+
0 org.springframework.boot.web.support.SpringBootServletInitializer
277280
2 org.springframework.cache.*
278281
2 org.springframework.cglib.*
279282
# LoadingCache.createEntry constructs FutureTasks which it executes synchronously,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ext {
2+
latestDepTestMinJavaVersionForTests = JavaVersion.VERSION_17
3+
latestDepForkedTestMinJavaVersionForTests = JavaVersion.VERSION_17
4+
boot3TestMinJavaVersionForTests = JavaVersion.VERSION_17
5+
boot3ForkedTestMinJavaVersionForTests = JavaVersion.VERSION_17
6+
}
7+
muzzle {
8+
pass {
9+
group = 'org.springframework.boot'
10+
module = 'spring-boot'
11+
versions = "[1.3.0.RELEASE,3)"
12+
}
13+
pass {
14+
group = 'org.springframework.boot'
15+
module = 'spring-boot'
16+
versions = "[3,)"
17+
javaVersion = "17"
18+
}
19+
}
20+
21+
apply from: "$rootDir/gradle/java.gradle"
22+
23+
addTestSuiteForDir("boot1LatestDepTest", "test")
24+
addTestSuiteForDir("boot2Test", "test")
25+
addTestSuiteForDir("boot2LatestDepTest", "test")
26+
addTestSuiteForDir("boot3Test", "test")
27+
addTestSuiteForDir("latestDepTest", "test")
28+
addTestSuiteExtendingForDir("boot1LatestDepForkedTest", "boot1LatestDepTest", "test")
29+
addTestSuiteExtendingForDir("boot2ForkedTest", "boot2Test", "test")
30+
addTestSuiteExtendingForDir("boot2LatestDepForkedTest", "boot2LatestDepTest", "test")
31+
addTestSuiteExtendingForDir("boot3ForkedTest", "boot3Test", "test")
32+
addTestSuiteExtendingForDir("latestDepForkedTest", "latestDepTest", "test")
33+
34+
[compileLatestDepTestGroovy, compileBoot3TestGroovy].each {
35+
it.javaLauncher = getJavaLauncherFor(17)
36+
}
37+
38+
dependencies {
39+
compileOnly group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.0.RELEASE'
40+
testImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.0.RELEASE'
41+
boot1LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
42+
boot1LatestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
43+
boot2TestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.0.0.RELEASE'
44+
boot2ForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.0.0.RELEASE'
45+
boot2LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
46+
boot2LatestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
47+
boot3TestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '3.0.0'
48+
boot3ForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '3.0.0'
49+
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '+'
50+
latestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '+'
51+
latestDepTestImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.8' // otherwise clashes with RootLogLevelConfigurator
52+
latestDepForkedTestImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.8'
53+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# This is a Gradle generated file for dependency locking.
2+
# Manual edits can break the build and are not advised.
3+
# This file is expected to be part of source control.
4+
cafe.cryptography:curve25519-elisabeth:0.1.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
5+
cafe.cryptography:ed25519-elisabeth:0.1.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
6+
ch.qos.logback:logback-classic:1.2.3=testCompileClasspath,testRuntimeClasspath
7+
ch.qos.logback:logback-core:1.2.3=testCompileClasspath,testRuntimeClasspath
8+
com.beust:jcommander:1.78=testRuntimeClasspath
9+
com.blogspot.mydailyjava:weak-lock-free:0.17=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
10+
com.datadoghq.okhttp3:okhttp:3.12.15=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
11+
com.datadoghq.okio:okio:1.17.6=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
com.datadoghq:dd-javac-plugin-client:0.1.7=compileClasspath,instrumentPluginClasspath,muzzleBootstrap,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
13+
com.datadoghq:java-dogstatsd-client:4.2.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
14+
com.datadoghq:sketches-java:0.8.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
15+
com.github.javaparser:javaparser-core:3.25.1=testCompileClasspath,testRuntimeClasspath
16+
com.github.jnr:jffi:1.3.12=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
17+
com.github.jnr:jnr-a64asm:1.0.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
18+
com.github.jnr:jnr-constants:0.10.4=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
19+
com.github.jnr:jnr-enxio:0.32.16=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
20+
com.github.jnr:jnr-ffi:2.2.15=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
21+
com.github.jnr:jnr-posix:3.1.18=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
22+
com.github.jnr:jnr-unixsocket:0.38.21=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
23+
com.github.jnr:jnr-x86asm:1.0.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
24+
com.github.spotbugs:spotbugs-annotations:4.2.0=compileClasspath,testCompileClasspath,testRuntimeClasspath
25+
com.github.spotbugs:spotbugs-annotations:4.7.3=spotbugs
26+
com.github.spotbugs:spotbugs:4.7.3=spotbugs
27+
com.github.stefanbirkner:system-rules:1.19.0=testCompileClasspath,testRuntimeClasspath
28+
com.google.auto.service:auto-service-annotations:1.0-rc7=annotationProcessor,compileClasspath,testAnnotationProcessor,testCompileClasspath
29+
com.google.auto.service:auto-service:1.0-rc7=annotationProcessor,testAnnotationProcessor
30+
com.google.auto:auto-common:0.10=annotationProcessor,testAnnotationProcessor
31+
com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,compileClasspath,spotbugs,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
32+
com.google.code.gson:gson:2.9.1=spotbugs
33+
com.google.errorprone:error_prone_annotations:2.2.0=annotationProcessor,testAnnotationProcessor
34+
com.google.guava:failureaccess:1.0.1=annotationProcessor,testAnnotationProcessor
35+
com.google.guava:guava:20.0=testCompileClasspath,testRuntimeClasspath
36+
com.google.guava:guava:27.0.1-jre=annotationProcessor,testAnnotationProcessor
37+
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,testAnnotationProcessor
38+
com.google.j2objc:j2objc-annotations:1.1=annotationProcessor,testAnnotationProcessor
39+
com.google.re2j:re2j:1.7=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
40+
com.squareup.moshi:moshi:1.11.0=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
41+
com.squareup.okhttp3:logging-interceptor:3.12.12=testCompileClasspath,testRuntimeClasspath
42+
com.squareup.okhttp3:okhttp:3.12.12=testCompileClasspath,testRuntimeClasspath
43+
com.squareup.okio:okio:1.17.5=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
44+
com.thoughtworks.qdox:qdox:1.12.1=testRuntimeClasspath
45+
commons-codec:commons-codec:1.15=spotbugs
46+
commons-fileupload:commons-fileupload:1.5=testCompileClasspath,testRuntimeClasspath
47+
commons-io:commons-io:2.11.0=testCompileClasspath,testRuntimeClasspath
48+
commons-logging:commons-logging:1.1.1=compileClasspath
49+
de.thetaphi:forbiddenapis:3.1=compileClasspath
50+
info.picocli:picocli:4.6.3=testRuntimeClasspath
51+
io.sqreen:libsqreen:8.0.0=testRuntimeClasspath
52+
javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath
53+
jaxen:jaxen:1.2.0=spotbugs
54+
jline:jline:2.14.6=testRuntimeClasspath
55+
junit:junit-dep:4.11=testCompileClasspath,testRuntimeClasspath
56+
junit:junit:4.13.2=testCompileClasspath,testRuntimeClasspath
57+
net.bytebuddy:byte-buddy-agent:1.14.9=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
58+
net.bytebuddy:byte-buddy:1.14.9=compileClasspath,instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
59+
net.java.dev.jna:jna-platform:5.8.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
60+
net.java.dev.jna:jna:5.8.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
61+
net.jcip:jcip-annotations:1.0=compileClasspath,spotbugs,testCompileClasspath,testRuntimeClasspath
62+
net.sf.saxon:Saxon-HE:11.4=spotbugs
63+
org.apache.ant:ant-antlr:1.10.12=testRuntimeClasspath
64+
org.apache.ant:ant-antlr:1.9.15=codenarc
65+
org.apache.ant:ant-junit:1.10.12=testRuntimeClasspath
66+
org.apache.ant:ant-junit:1.9.15=codenarc
67+
org.apache.ant:ant-launcher:1.10.12=testRuntimeClasspath
68+
org.apache.ant:ant:1.10.12=testCompileClasspath,testRuntimeClasspath
69+
org.apache.bcel:bcel:6.5.0=spotbugs
70+
org.apache.commons:commons-lang3:3.12.0=spotbugs
71+
org.apache.commons:commons-text:1.10.0=spotbugs
72+
org.apache.httpcomponents.client5:httpclient5:5.1.3=spotbugs
73+
org.apache.httpcomponents.core5:httpcore5-h2:5.1.3=spotbugs
74+
org.apache.httpcomponents.core5:httpcore5:5.1.3=spotbugs
75+
org.apache.logging.log4j:log4j-api:2.19.0=spotbugs
76+
org.apache.logging.log4j:log4j-core:2.19.0=spotbugs
77+
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testRuntimeClasspath
78+
org.checkerframework:checker-qual:2.5.2=annotationProcessor,testAnnotationProcessor
79+
org.codehaus.groovy:groovy-all:3.0.17=testCompileClasspath,testRuntimeClasspath
80+
org.codehaus.groovy:groovy-ant:2.5.14=codenarc
81+
org.codehaus.groovy:groovy-ant:3.0.17=testCompileClasspath,testRuntimeClasspath
82+
org.codehaus.groovy:groovy-astbuilder:3.0.17=testCompileClasspath,testRuntimeClasspath
83+
org.codehaus.groovy:groovy-cli-picocli:3.0.17=testCompileClasspath,testRuntimeClasspath
84+
org.codehaus.groovy:groovy-console:3.0.17=testCompileClasspath,testRuntimeClasspath
85+
org.codehaus.groovy:groovy-datetime:3.0.17=testCompileClasspath,testRuntimeClasspath
86+
org.codehaus.groovy:groovy-docgenerator:3.0.17=testCompileClasspath,testRuntimeClasspath
87+
org.codehaus.groovy:groovy-groovydoc:2.5.14=codenarc
88+
org.codehaus.groovy:groovy-groovydoc:3.0.17=testCompileClasspath,testRuntimeClasspath
89+
org.codehaus.groovy:groovy-groovysh:3.0.17=testCompileClasspath,testRuntimeClasspath
90+
org.codehaus.groovy:groovy-jmx:3.0.17=testCompileClasspath,testRuntimeClasspath
91+
org.codehaus.groovy:groovy-json:2.5.14=codenarc
92+
org.codehaus.groovy:groovy-json:3.0.17=testCompileClasspath,testRuntimeClasspath
93+
org.codehaus.groovy:groovy-jsr223:3.0.17=testCompileClasspath,testRuntimeClasspath
94+
org.codehaus.groovy:groovy-macro:3.0.17=testCompileClasspath,testRuntimeClasspath
95+
org.codehaus.groovy:groovy-nio:3.0.17=testCompileClasspath,testRuntimeClasspath
96+
org.codehaus.groovy:groovy-servlet:3.0.17=testCompileClasspath,testRuntimeClasspath
97+
org.codehaus.groovy:groovy-sql:3.0.17=testCompileClasspath,testRuntimeClasspath
98+
org.codehaus.groovy:groovy-swing:3.0.17=testCompileClasspath,testRuntimeClasspath
99+
org.codehaus.groovy:groovy-templates:2.5.14=codenarc
100+
org.codehaus.groovy:groovy-templates:3.0.17=testCompileClasspath,testRuntimeClasspath
101+
org.codehaus.groovy:groovy-test-junit5:3.0.17=testCompileClasspath,testRuntimeClasspath
102+
org.codehaus.groovy:groovy-test:3.0.17=testCompileClasspath,testRuntimeClasspath
103+
org.codehaus.groovy:groovy-testng:3.0.17=testCompileClasspath,testRuntimeClasspath
104+
org.codehaus.groovy:groovy-xml:2.5.14=codenarc
105+
org.codehaus.groovy:groovy-xml:3.0.17=testCompileClasspath,testRuntimeClasspath
106+
org.codehaus.groovy:groovy:2.5.14=codenarc
107+
org.codehaus.groovy:groovy:3.0.17=testCompileClasspath,testRuntimeClasspath
108+
org.codehaus.mojo:animal-sniffer-annotations:1.17=annotationProcessor,testAnnotationProcessor
109+
org.codenarc:CodeNarc:2.2.0=codenarc
110+
org.dom4j:dom4j:2.1.3=spotbugs
111+
org.eclipse.jetty:jetty-http:9.2.30.v20200428=testCompileClasspath,testRuntimeClasspath
112+
org.eclipse.jetty:jetty-io:9.2.30.v20200428=testCompileClasspath,testRuntimeClasspath
113+
org.eclipse.jetty:jetty-server:9.2.30.v20200428=testCompileClasspath,testRuntimeClasspath
114+
org.eclipse.jetty:jetty-util:9.2.30.v20200428=testCompileClasspath,testRuntimeClasspath
115+
org.gmetrics:GMetrics:1.1=codenarc
116+
org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
117+
org.hamcrest:hamcrest:2.2=testCompileClasspath,testRuntimeClasspath
118+
org.jctools:jctools-core:3.3.0=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
119+
org.junit.jupiter:junit-jupiter-api:5.9.2=testCompileClasspath,testRuntimeClasspath
120+
org.junit.jupiter:junit-jupiter-engine:5.9.2=testRuntimeClasspath
121+
org.junit.platform:junit-platform-commons:1.9.0=testCompileClasspath
122+
org.junit.platform:junit-platform-commons:1.9.2=testRuntimeClasspath
123+
org.junit.platform:junit-platform-engine:1.9.0=testCompileClasspath
124+
org.junit.platform:junit-platform-engine:1.9.2=testRuntimeClasspath
125+
org.junit.platform:junit-platform-launcher:1.9.2=testRuntimeClasspath
126+
org.junit.platform:junit-platform-runner:1.9.2=testRuntimeClasspath
127+
org.junit.platform:junit-platform-suite-api:1.9.2=testRuntimeClasspath
128+
org.junit.platform:junit-platform-suite-commons:1.9.2=testRuntimeClasspath
129+
org.junit:junit-bom:5.9.0=testCompileClasspath
130+
org.junit:junit-bom:5.9.1=spotbugs
131+
org.junit:junit-bom:5.9.2=testRuntimeClasspath
132+
org.objenesis:objenesis:3.3=testCompileClasspath,testRuntimeClasspath
133+
org.opentest4j:opentest4j:1.2.0=testCompileClasspath,testRuntimeClasspath
134+
org.ow2.asm:asm-analysis:9.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
135+
org.ow2.asm:asm-analysis:9.4=spotbugs
136+
org.ow2.asm:asm-commons:9.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
137+
org.ow2.asm:asm-commons:9.4=spotbugs
138+
org.ow2.asm:asm-tree:9.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
139+
org.ow2.asm:asm-tree:9.4=spotbugs
140+
org.ow2.asm:asm-util:9.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
141+
org.ow2.asm:asm-util:9.4=spotbugs
142+
org.ow2.asm:asm:9.2=instrumentPluginClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
143+
org.ow2.asm:asm:9.4=spotbugs
144+
org.slf4j:jcl-over-slf4j:1.7.30=testCompileClasspath,testRuntimeClasspath
145+
org.slf4j:jul-to-slf4j:1.7.30=testCompileClasspath,testRuntimeClasspath
146+
org.slf4j:log4j-over-slf4j:1.7.30=testCompileClasspath,testRuntimeClasspath
147+
org.slf4j:slf4j-api:1.7.30=compileClasspath,instrumentPluginClasspath,muzzleBootstrap,muzzleTooling,runtimeClasspath,testCompileClasspath
148+
org.slf4j:slf4j-api:1.7.32=testRuntimeClasspath
149+
org.slf4j:slf4j-api:2.0.0=spotbugs,spotbugsSlf4j
150+
org.slf4j:slf4j-simple:2.0.0=spotbugsSlf4j
151+
org.spockframework:spock-core:2.2-groovy-3.0=testCompileClasspath,testRuntimeClasspath
152+
org.spockframework:spock-junit4:2.2-groovy-3.0=testCompileClasspath,testRuntimeClasspath
153+
org.springframework:spring-asm:3.1.0.RELEASE=compileClasspath
154+
org.springframework:spring-beans:3.1.0.RELEASE=compileClasspath
155+
org.springframework:spring-core:3.1.0.RELEASE=compileClasspath
156+
org.testng:testng:7.5=testRuntimeClasspath
157+
org.webjars:jquery:3.5.1=testRuntimeClasspath
158+
org.xmlresolver:xmlresolver:4.4.3=spotbugs
159+
xml-apis:xml-apis:1.4.01=spotbugs
160+
empty=spotbugsPlugins
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package datadog.trace.instrumentation.springboot;
2+
3+
public final class DeploymentHelper {
4+
public static volatile boolean runningFromWar = false;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package datadog.trace.instrumentation.springboot;
2+
3+
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
4+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
5+
6+
import com.google.auto.service.AutoService;
7+
import datadog.trace.agent.tooling.Instrumenter;
8+
import datadog.trace.agent.tooling.InstrumenterModule;
9+
import datadog.trace.api.Config;
10+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
11+
import net.bytebuddy.asm.Advice;
12+
import org.springframework.core.env.ConfigurableEnvironment;
13+
14+
/**
15+
* An instrumentation that set the service name according to what defined as
16+
* `spring.application.name`
17+
*/
18+
@AutoService(Instrumenter.class)
19+
public class SpringApplicationInstrumentation extends InstrumenterModule.Tracing
20+
implements Instrumenter.ForSingleType {
21+
public SpringApplicationInstrumentation() {
22+
super("spring-boot");
23+
}
24+
25+
@Override
26+
public String instrumentedType() {
27+
return "org.springframework.boot.SpringApplicationRunListeners";
28+
}
29+
30+
@Override
31+
protected boolean defaultEnabled() {
32+
return false;
33+
}
34+
35+
@Override
36+
public String[] helperClassNames() {
37+
return new String[] {
38+
packageName + ".DeploymentHelper",
39+
};
40+
}
41+
42+
@Override
43+
public void methodAdvice(MethodTransformer transformer) {
44+
transformer.applyAdvice(
45+
named("environmentPrepared")
46+
.and(takesArgument(0, named("org.springframework.core.env.ConfigurableEnvironment"))),
47+
getClass().getName() + "$EnvironmentReadyV1Advice");
48+
// >= 2.4.0
49+
transformer.applyAdvice(
50+
named("environmentPrepared")
51+
.and(takesArgument(1, named("org.springframework.core.env.ConfigurableEnvironment"))),
52+
getClass().getName() + "$EnvironmentReadyV2Advice");
53+
}
54+
55+
public static class EnvironmentReadyV1Advice {
56+
@Advice.OnMethodExit(suppress = Throwable.class)
57+
public static void afterEnvironmentPostProcessed(
58+
@Advice.Argument(0) final ConfigurableEnvironment environment) {
59+
if (environment == null
60+
|| DeploymentHelper.runningFromWar
61+
|| Config.get().isServiceNameSetByUser()) {
62+
return;
63+
}
64+
65+
final String applicationName = environment.getProperty("spring.application.name");
66+
if (applicationName != null && !applicationName.isEmpty()) {
67+
AgentTracer.get().updatePreferredServiceName(applicationName);
68+
}
69+
}
70+
}
71+
72+
public static class EnvironmentReadyV2Advice {
73+
@Advice.OnMethodExit(suppress = Throwable.class)
74+
public static void afterEnvironmentPostProcessed(
75+
@Advice.Argument(1) final ConfigurableEnvironment environment) {
76+
if (environment == null
77+
|| DeploymentHelper.runningFromWar
78+
|| Config.get().isServiceNameSetByUser()) {
79+
return;
80+
}
81+
82+
final String applicationName = environment.getProperty("spring.application.name");
83+
if (applicationName != null && !applicationName.isEmpty()) {
84+
AgentTracer.get().updatePreferredServiceName(applicationName);
85+
}
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)