From 12e95c9eafd4b519e098e6e950958a4924184493 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Tue, 16 Apr 2024 22:31:51 +0000 Subject: [PATCH] Switch to ConcurrentMap for thread-safety --- .../cloud/opentelemetry/detection/GCPMetadataConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java index 09cf39f4..a11384b5 100644 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java +++ b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java @@ -22,8 +22,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Retrieves Google Cloud project-id and a limited set of instance attributes from Metadata server. @@ -36,7 +36,7 @@ final class GCPMetadataConfig { private static final String DEFAULT_URL = "http://metadata.google.internal/computeMetadata/v1/"; private final String url; - private final Map cachedAttributes = new HashMap<>(); + private final Map cachedAttributes = new ConcurrentHashMap<>(); private GCPMetadataConfig() { this.url = DEFAULT_URL;