Skip to content

Commit 8760af6

Browse files
committed
Do not set contextual service name if jee-split-by-deployment is not enabled
1 parent e8e8281 commit 8760af6

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

dd-java-agent/instrumentation/jboss-modules/src/main/java/datadog/trace/instrumentation/jbossmodules/ModuleInstrumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ public static class CaptureModuleNameAdvice {
164164
public static void afterConstruct(@Advice.This final Module module) {
165165
final String name = ModuleNameHelper.extractDeploymentName(module.getClassLoader());
166166
if (name != null && !name.isEmpty()) {
167-
ClassloaderConfigurationOverrides.addContextualInfo(
168-
module.getClassLoader(), new ClassloaderConfigurationOverrides.ContextualInfo(name));
167+
ClassloaderConfigurationOverrides.withPinnedServiceName(module.getClassLoader(), name);
169168
}
170169
}
171170
}

dd-java-agent/instrumentation/liberty-20/src/main/java/datadog/trace/instrumentation/liberty20/ThreadContextClassloaderInstrumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public static class ThreadContextClassloaderAdvice {
4040
public static void afterConstruct(@Advice.This ThreadContextClassLoader self) {
4141
final String name = BundleNameHelper.extractDeploymentName(self);
4242
if (name != null && !name.isEmpty()) {
43-
ClassloaderConfigurationOverrides.addContextualInfo(
44-
self, new ClassloaderConfigurationOverrides.ContextualInfo(name));
43+
ClassloaderConfigurationOverrides.withPinnedServiceName(self, name);
4544
}
4645
}
4746
}

dd-java-agent/instrumentation/tomcat-classloading-9/src/main/java/datadog/trace/instrumentation/tomcat9/WebappClassLoaderInstrumentation.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import datadog.trace.agent.tooling.Instrumenter;
1010
import datadog.trace.agent.tooling.InstrumenterModule;
1111
import datadog.trace.api.ClassloaderConfigurationOverrides;
12+
import java.util.HashMap;
13+
import java.util.Map;
1214
import net.bytebuddy.asm.Advice;
1315
import org.apache.catalina.Context;
1416
import org.apache.catalina.WebResourceRoot;
@@ -47,14 +49,12 @@ public static void onContextAvailable(
4749

4850
final String contextName = context.getBaseName();
4951
if (contextName != null && !contextName.isEmpty()) {
50-
info = new ClassloaderConfigurationOverrides.ContextualInfo(contextName);
52+
info = ClassloaderConfigurationOverrides.withPinnedServiceName(classLoader, contextName);
5153
}
5254
if (context.getNamingResources() != null) {
5355
final ContextEnvironment[] envs = context.getNamingResources().findEnvironments();
5456
if (envs != null) {
55-
if (info == null) {
56-
info = new ClassloaderConfigurationOverrides.ContextualInfo(null);
57-
}
57+
final Map<String, String> tags = new HashMap<>();
5858
for (final ContextEnvironment env : envs) {
5959
// as a limitation here we simplify a lot the logic and we do not try to resolve the
6060
// typed value but we just take the string representation. It avoids implementing the
@@ -70,14 +70,17 @@ public static void onContextAvailable(
7070
name = env.getName().substring(DATADOG_TAGS_JNDI_PREFIX.length());
7171
}
7272
if (name != null && !name.isEmpty()) {
73-
info.addTag(name, env.getValue());
73+
tags.put(name, env.getValue());
74+
}
75+
}
76+
if (!tags.isEmpty()) {
77+
if (info == null) {
78+
info = ClassloaderConfigurationOverrides.maybeCreateContextualInfo(classLoader);
7479
}
80+
tags.forEach(info::addTag);
7581
}
7682
}
7783
}
78-
if (info != null) {
79-
ClassloaderConfigurationOverrides.addContextualInfo(classLoader, info);
80-
}
8184
}
8285
}
8386
}

internal-api/src/main/java/datadog/trace/api/ClassloaderConfigurationOverrides.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public static ContextualInfo maybeCreateContextualInfo(ClassLoader classLoader)
8181
}
8282
}
8383

84+
@Nullable
85+
public static ContextualInfo withPinnedServiceName(ClassLoader classLoader, String serviceName) {
86+
if (!CAN_SPLIT_SERVICE_NAME_BY_DEPLOYMENT) {
87+
return null;
88+
}
89+
final ContextualInfo contextualInfo = new ContextualInfo(serviceName);
90+
addContextualInfo(classLoader, contextualInfo);
91+
return contextualInfo;
92+
}
93+
8494
@Nullable
8595
public static ContextualInfo maybeGetContextualInfo(ClassLoader classLoader) {
8696
if (atLeastOneEntry) {

0 commit comments

Comments
 (0)