diff --git a/opentelemetry-resourcedetector-gcp/src/opentelemetry/resourcedetector/gcp_resource_detector/__init__.py b/opentelemetry-resourcedetector-gcp/src/opentelemetry/resourcedetector/gcp_resource_detector/__init__.py index 8645925e..6dd03a5d 100644 --- a/opentelemetry-resourcedetector-gcp/src/opentelemetry/resourcedetector/gcp_resource_detector/__init__.py +++ b/opentelemetry-resourcedetector-gcp/src/opentelemetry/resourcedetector/gcp_resource_detector/__init__.py @@ -23,6 +23,7 @@ "http://metadata.google.internal/computeMetadata/v1/?recursive=true" ) _GCP_METADATA_URL_HEADER = {"Metadata-Flavor": "Google"} +_TIMEOUT_SEC = 5 logger = logging.getLogger(__name__) @@ -30,7 +31,9 @@ def _get_google_metadata_and_common_attributes(): token = attach(set_value("suppress_instrumentation", True)) all_metadata = requests.get( - _GCP_METADATA_URL, headers=_GCP_METADATA_URL_HEADER + _GCP_METADATA_URL, + headers=_GCP_METADATA_URL_HEADER, + timeout=_TIMEOUT_SEC, ).json() detach(token) common_attributes = {