diff --git a/src/main/java/io/opentelemetry/semconv/AttributeKeyTemplate.java b/src/main/java/io/opentelemetry/semconv/AttributeKeyTemplate.java index 9408b7c..efa6e54 100644 --- a/src/main/java/io/opentelemetry/semconv/AttributeKeyTemplate.java +++ b/src/main/java/io/opentelemetry/semconv/AttributeKeyTemplate.java @@ -16,7 +16,7 @@ public final class AttributeKeyTemplate { private final String prefix; private final Function> keyBuilder; - private ConcurrentMap> keysCache; + private final ConcurrentMap> keysCache = new ConcurrentHashMap<>(1);; AttributeKeyTemplate(String prefix, Function> keyBuilder) { this.prefix = prefix; @@ -73,9 +73,6 @@ private AttributeKey createAttributeKey(String keyName) { * @return An {@link AttributeKey} object for the given key. */ public AttributeKey getAttributeKey(String key) { - if (keysCache == null) { - keysCache = new ConcurrentHashMap<>(1); - } return keysCache.computeIfAbsent(key, this::createAttributeKey); } }