Skip to content

Commit 005aa33

Browse files
dougqhdevflow.devflow-routing-intake
andauthored
Caching the primaryInstrumentationName (#10477)
Caching the primaryInstrumentationName Caching the primaryInstrumentationName to avoid repeatedly calling instrumentationNames() and constantly allocating a String[] Merge branch 'master' into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Switched to storing into final field Realized that the caching is unnecessary complication Just use a final field instead Merge branch 'master' into dougqh/cache-primary-instrumentation-name Fixing visibility Merge branch 'dougqh/cache-primary-instrumentation-name' of github.com:DataDog/dd-trace-java into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Merge branch 'master' into dougqh/cache-primary-instrumentation-name Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 2ec3a87 commit 005aa33

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE, REQUEST
8080
private final boolean traceClientIpResolverEnabled =
8181
Config.get().isTraceClientIpResolverEnabled();
8282

83+
private final String primaryInstrumentationName;
84+
85+
protected HttpServerDecorator() {
86+
String[] instrumentationNames = instrumentationNames();
87+
this.primaryInstrumentationName =
88+
instrumentationNames != null && instrumentationNames.length > 0
89+
? instrumentationNames[0]
90+
: DEFAULT_INSTRUMENTATION_NAME;
91+
}
92+
93+
protected final String primaryInstrumentationName() {
94+
return primaryInstrumentationName;
95+
}
96+
8397
protected abstract AgentPropagation.ContextVisitor<REQUEST_CARRIER> getter();
8498

8599
protected abstract AgentPropagation.ContextVisitor<RESPONSE> responseGetter();
@@ -152,11 +166,7 @@ public Context extract(REQUEST_CARRIER carrier) {
152166
* @return A new context bundling the span, child of the given parent context.
153167
*/
154168
public Context startSpan(REQUEST_CARRIER carrier, Context parentContext) {
155-
String[] instrumentationNames = instrumentationNames();
156-
String instrumentationName =
157-
instrumentationNames != null && instrumentationNames.length > 0
158-
? instrumentationNames[0]
159-
: DEFAULT_INSTRUMENTATION_NAME;
169+
String instrumentationName = primaryInstrumentationName();
160170
AgentSpanContext extracted = getExtractedSpanContext(parentContext);
161171
// Call IG callbacks
162172
extracted = callIGCallbackStart(extracted);

0 commit comments

Comments
 (0)