Skip to content

Commit 123ed37

Browse files
committed
Fixing null handling
Since it about a 50/50 split between cases that use EMPTY vs null, when a null is passed I decided to just put the null handling back into the constructor. That makes the choice more explicit, and makes the PR easier to review / compare to the prior logic
1 parent bd6a418 commit 123ed37

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • dd-trace-core/src/main/java/datadog/trace/common/metrics

dd-trace-core/src/main/java/datadog/trace/common/metrics/MetricKey.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.common.metrics;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.UTF8BytesString.EMPTY;
4+
35
import datadog.trace.api.cache.DDCaches;
46
import datadog.trace.api.cache.DDCache;
57
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
@@ -47,15 +49,15 @@ public MetricKey(
4749
List<UTF8BytesString> peerTags,
4850
CharSequence httpMethod,
4951
CharSequence httpEndpoint) {
50-
this.resource = utf8(RESOURCE_CACHE, resource);
51-
this.service = utf8(SERVICE_CACHE, service);
52-
this.serviceSource = utf8(SERVICE_SOURCE_CACHE, serviceSource);
53-
this.operationName = utf8(OPERATION_CACHE, operationName);
52+
this.resource = resource == null ? EMPTY : utf8(RESOURCE_CACHE, resource);
53+
this.service = service == null ? EMPTY : utf8(SERVICE_CACHE, service);
54+
this.serviceSource = serviceSource == null ? null : utf8(SERVICE_SOURCE_CACHE, serviceSource);
55+
this.operationName = operationName == null ? EMPTY : utf8(OPERATION_CACHE, operationName);
5456
this.type = utf8(TYPE_CACHE, type);
5557
this.httpStatusCode = httpStatusCode;
5658
this.synthetics = synthetics;
5759
this.isTraceRoot = isTraceRoot;
58-
this.spanKind = utf8(KIND_CACHE, spanKind);
60+
this.spanKind = null == spanKind ? EMPTY : utf8(KIND_CACHE, spanKind);
5961
this.peerTags = peerTags == null ? Collections.emptyList() : peerTags;
6062
this.httpMethod = httpMethod == null ? null : utf8(HTTP_METHOD_CACHE, httpMethod);
6163
this.httpEndpoint = httpEndpoint == null ? null : utf8(HTTP_ENDPOINT_CACHE, httpEndpoint);
@@ -77,9 +79,7 @@ public MetricKey(
7779
}
7880

7981
static UTF8BytesString utf8(DDCache<String, UTF8BytesString> cache, CharSequence charSeq) {
80-
if ( charSeq == null ) {
81-
return UTF8BytesString.EMPTY;
82-
} else if ( charSeq instanceof UTF8BytesString ) {
82+
if ( charSeq instanceof UTF8BytesString ) {
8383
return (UTF8BytesString)charSeq;
8484
} else {
8585
return cache.computeIfAbsent(charSeq.toString(), UTF8BytesString::create);

0 commit comments

Comments
 (0)