Skip to content

Commit 7618bbb

Browse files
committed
review
1 parent fc54a0b commit 7618bbb

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

dd-java-agent/instrumentation/wildfly-9/src/main/java/datadog/trace/instrumentation/wildfly/ResourceReferenceProcessorInstrumentation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public static class GetEnvironmentEntriesAdvice {
5151
public static void onExit(
5252
@Advice.Argument(value = 1) final ClassLoader classLoader,
5353
@Advice.Return final List<BindingConfiguration> configurations) {
54-
ClassloaderConfigurationOverrides.ContextualInfo info =
55-
ClassloaderConfigurationOverrides.getOrAddEmpty(classLoader);
54+
ClassloaderConfigurationOverrides.ContextualInfo info = null;
5655
ContextStore<EnvEntryInjectionSource, Object> contextStore =
5756
InstrumentationContext.get(EnvEntryInjectionSource.class, Object.class);
5857
for (BindingConfiguration bindingConfiguration : configurations) {
@@ -63,6 +62,9 @@ public static void onExit(
6362
&& bindingConfiguration
6463
.getName()
6564
.startsWith(ClassloaderConfigurationOverrides.DATADOG_TAGS_JNDI_PREFIX)) {
65+
if (info == null) {
66+
info = ClassloaderConfigurationOverrides.maybeCreateContextualInfo(classLoader);
67+
}
6668
info.addTag(
6769
bindingConfiguration
6870
.getName()

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ClassloaderConfigurationOverrides {
1919
static boolean CAN_SPLIT_SERVICE_NAME_BY_DEPLOYMENT =
2020
Config.get().isJeeSplitByDeployment() && !Config.get().isServiceNameSetByUser();
2121

22-
static class Lazy {
22+
static class Lazy {
2323
static final ClassloaderConfigurationOverrides INSTANCE =
2424
new ClassloaderConfigurationOverrides();
2525
}
@@ -54,13 +54,12 @@ public Map<String, Object> getTags() {
5454

5555
private ClassloaderConfigurationOverrides() {}
5656

57-
public static void addContextualInfo(
58-
@Nonnull ClassLoader classLoader, @Nonnull ContextualInfo contextualInfo) {
57+
public static void addContextualInfo(ClassLoader classLoader, ContextualInfo contextualInfo) {
5958
Lazy.INSTANCE.weakCache.put(classLoader, contextualInfo);
6059
}
6160

6261
@Nullable
63-
public static ContextualInfo maybeGetContextualInfo(@Nonnull ClassLoader classLoader) {
62+
public static ContextualInfo maybeGetContextualInfo(ClassLoader classLoader) {
6463
return Lazy.INSTANCE.weakCache.get(classLoader);
6564
}
6665

@@ -74,8 +73,7 @@ public static ContextualInfo maybeGetContextualInfo() {
7473
return maybeGetContextualInfo(Thread.currentThread().getContextClassLoader());
7574
}
7675

77-
@Nonnull
78-
public static ContextualInfo maybeCreateContextualInfo(@Nonnull ClassLoader classLoader) {
76+
public static ContextualInfo maybeCreateContextualInfo(ClassLoader classLoader) {
7977
return Lazy.INSTANCE.weakCache.computeIfAbsent(classLoader, EMPTY_CONTEXTUAL_INFO_ADDER);
8078
}
8179

@@ -95,14 +93,11 @@ public static void maybeEnrichSpan(
9593
if (contextualInfo == null) {
9694
return;
9795
}
98-
if (CAN_SPLIT_SERVICE_NAME_BY_DEPLOYMENT
99-
&& contextualInfo.serviceName != null
100-
&& !contextualInfo.getServiceName().isEmpty()) {
96+
final String serviceName = contextualInfo.getServiceName();
97+
if (CAN_SPLIT_SERVICE_NAME_BY_DEPLOYMENT && serviceName != null && !serviceName.isEmpty()) {
10198
final String currentServiceName = span.getServiceName();
10299
if (currentServiceName == null
103100
|| currentServiceName.equals(Lazy.INSTANCE.inferredServiceName)) {
104-
final String serviceName = contextualInfo.getServiceName();
105-
106101
span.setServiceName(serviceName);
107102
ServiceNameCollector.get().addService(serviceName);
108103
}

internal-api/src/test/groovy/datadog/trace/api/ClassloaderConfigurationOverridesTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ClassloaderConfigurationOverridesTest extends DDSpecification {
4545
def "enrich should set tags when present"() {
4646
def span = Mock(AgentSpan)
4747
when:
48-
ClassloaderConfigurationOverrides.getOrAddEmpty(Thread.currentThread().getContextClassLoader()).addTag("key", "value")
48+
ClassloaderConfigurationOverrides.maybeCreateContextualInfo(Thread.currentThread().getContextClassLoader()).addTag("key", "value")
4949
ClassloaderConfigurationOverrides.maybeEnrichSpan(span)
5050
then:
5151
1 * span.setTag("key", "value")

0 commit comments

Comments
 (0)