22
33import static datadog .trace .bootstrap .instrumentation .api .UTF8BytesString .EMPTY ;
44
5- import datadog .trace .api .cache .DDCaches ;
65import datadog .trace .api .cache .DDCache ;
6+ import datadog .trace .api .cache .DDCaches ;
77import datadog .trace .bootstrap .instrumentation .api .UTF8BytesString ;
88import datadog .trace .util .HashingUtils ;
9-
109import java .util .Collections ;
1110import java .util .List ;
1211import java .util .Objects ;
1514public final class MetricKey {
1615 static final DDCache <String , UTF8BytesString > RESOURCE_CACHE = DDCaches .newFixedSizeCache (32 );
1716 static final DDCache <String , UTF8BytesString > SERVICE_CACHE = DDCaches .newFixedSizeCache (8 );
18- static final DDCache <String , UTF8BytesString > SERVICE_SOURCE_CACHE = DDCaches .newFixedSizeCache (16 );
17+ static final DDCache <String , UTF8BytesString > SERVICE_SOURCE_CACHE =
18+ DDCaches .newFixedSizeCache (16 );
1919 static final DDCache <String , UTF8BytesString > OPERATION_CACHE = DDCaches .newFixedSizeCache (64 );
2020 static final DDCache <String , UTF8BytesString > TYPE_CACHE = DDCaches .newFixedSizeCache (8 );
2121 static final DDCache <String , UTF8BytesString > KIND_CACHE = DDCaches .newFixedSizeCache (8 );
2222 static final DDCache <String , UTF8BytesString > HTTP_METHOD_CACHE = DDCaches .newFixedSizeCache (8 );
23- static final DDCache <String , UTF8BytesString > HTTP_ENDPOINT_CACHE = DDCaches .newFixedSizeCache (32 );
24-
23+ static final DDCache <String , UTF8BytesString > HTTP_ENDPOINT_CACHE =
24+ DDCaches .newFixedSizeCache (32 );
25+
2526 private final UTF8BytesString resource ;
2627 private final UTF8BytesString service ;
2728 private final UTF8BytesString serviceSource ;
@@ -49,19 +50,19 @@ public MetricKey(
4950 List <UTF8BytesString > peerTags ,
5051 CharSequence httpMethod ,
5152 CharSequence httpEndpoint ) {
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 );
56- this .type = utf8 (TYPE_CACHE , type );
53+ this .resource = null == resource ? EMPTY : utf8 (RESOURCE_CACHE , resource );
54+ this .service = null == service ? EMPTY : utf8 (SERVICE_CACHE , service );
55+ this .serviceSource = null == serviceSource ? null : utf8 (SERVICE_SOURCE_CACHE , serviceSource );
56+ this .operationName = null == operationName ? EMPTY : utf8 (OPERATION_CACHE , operationName );
57+ this .type = null == type ? EMPTY : utf8 (TYPE_CACHE , type );
5758 this .httpStatusCode = httpStatusCode ;
5859 this .synthetics = synthetics ;
5960 this .isTraceRoot = isTraceRoot ;
6061 this .spanKind = null == spanKind ? EMPTY : utf8 (KIND_CACHE , spanKind );
6162 this .peerTags = peerTags == null ? Collections .emptyList () : peerTags ;
6263 this .httpMethod = httpMethod == null ? null : utf8 (HTTP_METHOD_CACHE , httpMethod );
6364 this .httpEndpoint = httpEndpoint == null ? null : utf8 (HTTP_ENDPOINT_CACHE , httpEndpoint );
64-
65+
6566 int tmpHash = 0 ;
6667 tmpHash = HashingUtils .addToHash (tmpHash , this .isTraceRoot );
6768 tmpHash = HashingUtils .addToHash (tmpHash , this .spanKind );
@@ -77,13 +78,13 @@ public MetricKey(
7778 tmpHash = HashingUtils .addToHash (tmpHash , this .httpMethod );
7879 this .hash = tmpHash ;
7980 }
80-
81+
8182 static UTF8BytesString utf8 (DDCache <String , UTF8BytesString > cache , CharSequence charSeq ) {
82- if ( charSeq instanceof UTF8BytesString ) {
83- return (UTF8BytesString )charSeq ;
84- } else {
85- return cache .computeIfAbsent (charSeq .toString (), UTF8BytesString ::create );
86- }
83+ if (charSeq instanceof UTF8BytesString ) {
84+ return (UTF8BytesString ) charSeq ;
85+ } else {
86+ return cache .computeIfAbsent (charSeq .toString (), UTF8BytesString ::create );
87+ }
8788 }
8889
8990 public UTF8BytesString getResource () {
0 commit comments