Skip to content

Commit 15fc801

Browse files
committed
Simplifying approach - just use final field in constructor
1 parent 4c2c1fc commit 15fc801

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public String apply(Class<?> clazz) {
4646

4747
private final TagMap.Entry traceAnalyticsEntry;
4848

49-
// Deliberately not volatile, reading null and repeating the calculation is safe
50-
private TagMap.Entry cachedComponentEntry = null;
49+
protected final TagMap.Entry componentEntry;
5150

5251
protected BaseDecorator() {
5352
final Config config = Config.get();
@@ -65,6 +64,8 @@ protected BaseDecorator() {
6564
this.traceAnalyticsEnabled
6665
? TagMap.Entry.create(DDTags.ANALYTICS_SAMPLE_RATE, traceAnalyticsSampleRate)
6766
: null;
67+
68+
this.componentEntry = TagMap.Entry.create(Tags.COMPONENT, component());
6869
}
6970

7071
protected abstract String[] instrumentationNames();
@@ -73,15 +74,6 @@ protected BaseDecorator() {
7374

7475
protected abstract CharSequence component();
7576

76-
/** Caches the component TagMap.Entry, so it isn't recreated for every trace */
77-
protected final TagMap.Entry componentEntry() {
78-
TagMap.Entry componentEntry = cachedComponentEntry;
79-
if (componentEntry == null) {
80-
cachedComponentEntry = componentEntry = TagMap.Entry.create(Tags.COMPONENT, component());
81-
}
82-
return componentEntry;
83-
}
84-
8577
protected boolean traceAnalyticsDefault() {
8678
return false;
8779
}
@@ -90,11 +82,9 @@ public AgentSpan afterStart(final AgentSpan span) {
9082
if (spanType() != null) {
9183
span.setSpanType(spanType());
9284
}
85+
86+
span.setTag(componentEntry);
9387

94-
span.setTag(componentEntry());
95-
96-
// DQH - Could retrieve the value from componentEntry and cast to avoid the virtual call,
97-
// unclear which option is better here
9888
final CharSequence component = component();
9989
span.context().setIntegrationName(component);
10090

0 commit comments

Comments
 (0)