From 13c7af555374f1c88a0f873aba88f0845f674097 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Tue, 26 May 2026 11:49:41 +0000 Subject: [PATCH 1/7] chore(storage): support DISABLE_BUCKET_MD_IN_OTEL environment variable flag --- .../google/cloud/storage/_helpers.py | 11 +++++- .../google/cloud/storage/_http.py | 12 +++++- .../tests/system/test_aco_observability.py | 39 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/packages/google-cloud-storage/google/cloud/storage/_helpers.py b/packages/google-cloud-storage/google/cloud/storage/_helpers.py index ffa9fe177ea3..5c15b127a451 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_helpers.py +++ b/packages/google-cloud-storage/google/cloud/storage/_helpers.py @@ -150,8 +150,17 @@ def _validate_name(name): def create_trace_span_helper(client, bucket_name, name, attributes=None, **kwargs): span_attrs = dict(attributes) if attributes else {} + # Check if GCS destination annotations are explicitly disabled via environment + disable_bucket_md = os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() in ( + "1", + "true", + "yes", + "on", + ) + if ( - bucket_name + not disable_bucket_md + and bucket_name and isinstance(bucket_name, str) and client and hasattr(client, "_bucket_metadata_cache") diff --git a/packages/google-cloud-storage/google/cloud/storage/_http.py b/packages/google-cloud-storage/google/cloud/storage/_http.py index ca7c90e2061a..8ea4c46fe846 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_http.py +++ b/packages/google-cloud-storage/google/cloud/storage/_http.py @@ -16,6 +16,7 @@ import functools import logging +import os import re from google.api_core import exceptions as api_exceptions @@ -82,9 +83,18 @@ def api_request(self, *args, **kwargs): span_attributes = { "gccl-invocation-id": invocation_id, } + # Check if GCS destination annotations are explicitly disabled via environment + disable_bucket_md = os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() in ( + "1", + "true", + "yes", + "on", + ) client = self._client + if ( - HAS_OPENTELEMETRY + not disable_bucket_md + and HAS_OPENTELEMETRY and enable_otel_traces and hasattr(client, "_bucket_metadata_cache") and client._bucket_metadata_cache diff --git a/packages/google-cloud-storage/tests/system/test_aco_observability.py b/packages/google-cloud-storage/tests/system/test_aco_observability.py index b1de4ae87025..fc31c83daaae 100644 --- a/packages/google-cloud-storage/tests/system/test_aco_observability.py +++ b/packages/google-cloud-storage/tests/system/test_aco_observability.py @@ -16,6 +16,7 @@ import threading import time +import os import pytest from google.api_core import exceptions @@ -549,3 +550,41 @@ def monitored_update(*args, **kwargs): assert attrs["gcp.resource.destination.location"] == "global" finally: storage_client._bucket_metadata_cache.update_cache = original_update + + +def test_disable_bucket_md_env_flag(storage_client, exporter, buckets_to_delete): + """Verifies that setting DISABLE_BUCKET_MD_IN_OTEL=true disables GCS + destination annotations, even on cache hits.""" + # Clear cache and OTel exporter logs + storage_client._bucket_metadata_cache.clear() + exporter.clear() + + bucket_name = _helpers.unique_name("aco-disable") + bucket = storage_client.bucket(bucket_name) + storage_client.create_bucket(bucket) + buckets_to_delete.append(bucket) + + blob_name = "test_blob.txt" + blob = bucket.blob(blob_name) + blob.upload_from_string("hello") + + # Warm cache directly via GCS creation warming (client.create_bucket already primes the cache) + assert storage_client._bucket_metadata_cache.get(bucket_name) is not None + + # Enable the DISABLE_BUCKET_MD_IN_OTEL environment variable + os.environ["DISABLE_BUCKET_MD_IN_OTEL"] = "true" + + try: + # Download (normally would be a cache hit with GCS annotations) + blob.download_as_bytes() + + # Verify that ACO attributes are NOT present in the OTel span! + spans = exporter.get_finished_spans() + dl_spans = [s for s in spans if s.name == "Storage.Blob.downloadAsBytes"] + assert len(dl_spans) == 1 + attrs = dl_spans[0].attributes + assert "gcp.resource.destination.id" not in attrs + assert "gcp.resource.destination.location" not in attrs + finally: + # Restore env var + os.environ.pop("DISABLE_BUCKET_MD_IN_OTEL", None) From 0866ac4ab5918c6140aded0ca3b3354d75603eb6 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Wed, 27 May 2026 09:42:00 +0000 Subject: [PATCH 2/7] chore(storage): optimize environment variable checks via short-circuiting and refactor system tests to use pytest monkeypatch --- .../google/cloud/storage/_helpers.py | 15 +++------ .../google/cloud/storage/_http.py | 15 +++------ .../tests/system/test_aco_observability.py | 31 +++++++++---------- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/packages/google-cloud-storage/google/cloud/storage/_helpers.py b/packages/google-cloud-storage/google/cloud/storage/_helpers.py index 5c15b127a451..4d7b8b77ee5c 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_helpers.py +++ b/packages/google-cloud-storage/google/cloud/storage/_helpers.py @@ -150,21 +150,16 @@ def _validate_name(name): def create_trace_span_helper(client, bucket_name, name, attributes=None, **kwargs): span_attrs = dict(attributes) if attributes else {} - # Check if GCS destination annotations are explicitly disabled via environment - disable_bucket_md = os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() in ( - "1", - "true", - "yes", - "on", - ) - if ( - not disable_bucket_md - and bucket_name + bucket_name and isinstance(bucket_name, str) and client and hasattr(client, "_bucket_metadata_cache") and client._bucket_metadata_cache + and not ( + os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() + in ("1", "true", "yes", "on") + ) ): try: if name in ( diff --git a/packages/google-cloud-storage/google/cloud/storage/_http.py b/packages/google-cloud-storage/google/cloud/storage/_http.py index 8ea4c46fe846..ddf281a16b32 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_http.py +++ b/packages/google-cloud-storage/google/cloud/storage/_http.py @@ -83,21 +83,16 @@ def api_request(self, *args, **kwargs): span_attributes = { "gccl-invocation-id": invocation_id, } - # Check if GCS destination annotations are explicitly disabled via environment - disable_bucket_md = os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() in ( - "1", - "true", - "yes", - "on", - ) client = self._client - if ( - not disable_bucket_md - and HAS_OPENTELEMETRY + HAS_OPENTELEMETRY and enable_otel_traces and hasattr(client, "_bucket_metadata_cache") and client._bucket_metadata_cache + and not ( + os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() + in ("1", "true", "yes", "on") + ) ): path = kwargs.get("path") or "" match = re.search(r"/b/([^/?#]+)", path) diff --git a/packages/google-cloud-storage/tests/system/test_aco_observability.py b/packages/google-cloud-storage/tests/system/test_aco_observability.py index fc31c83daaae..90db98500792 100644 --- a/packages/google-cloud-storage/tests/system/test_aco_observability.py +++ b/packages/google-cloud-storage/tests/system/test_aco_observability.py @@ -16,7 +16,6 @@ import threading import time -import os import pytest from google.api_core import exceptions @@ -552,7 +551,9 @@ def monitored_update(*args, **kwargs): storage_client._bucket_metadata_cache.update_cache = original_update -def test_disable_bucket_md_env_flag(storage_client, exporter, buckets_to_delete): +def test_disable_bucket_md_env_flag( + storage_client, exporter, buckets_to_delete, monkeypatch +): """Verifies that setting DISABLE_BUCKET_MD_IN_OTEL=true disables GCS destination annotations, even on cache hits.""" # Clear cache and OTel exporter logs @@ -571,20 +572,16 @@ def test_disable_bucket_md_env_flag(storage_client, exporter, buckets_to_delete) # Warm cache directly via GCS creation warming (client.create_bucket already primes the cache) assert storage_client._bucket_metadata_cache.get(bucket_name) is not None - # Enable the DISABLE_BUCKET_MD_IN_OTEL environment variable - os.environ["DISABLE_BUCKET_MD_IN_OTEL"] = "true" + # Enable the DISABLE_BUCKET_MD_IN_OTEL environment variable using monkeypatch + monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "true") - try: - # Download (normally would be a cache hit with GCS annotations) - blob.download_as_bytes() + # Download (normally would be a cache hit with GCS annotations) + blob.download_as_bytes() - # Verify that ACO attributes are NOT present in the OTel span! - spans = exporter.get_finished_spans() - dl_spans = [s for s in spans if s.name == "Storage.Blob.downloadAsBytes"] - assert len(dl_spans) == 1 - attrs = dl_spans[0].attributes - assert "gcp.resource.destination.id" not in attrs - assert "gcp.resource.destination.location" not in attrs - finally: - # Restore env var - os.environ.pop("DISABLE_BUCKET_MD_IN_OTEL", None) + # Verify that ACO attributes are NOT present in the OTel span! + spans = exporter.get_finished_spans() + dl_spans = [s for s in spans if s.name == "Storage.Blob.downloadAsBytes"] + assert len(dl_spans) == 1 + attrs = dl_spans[0].attributes + assert "gcp.resource.destination.id" not in attrs + assert "gcp.resource.destination.location" not in attrs From 9f06cc650b99b53869585f6a3fe1b4b3b713c63e Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Thu, 4 Jun 2026 05:10:48 +0000 Subject: [PATCH 3/7] chore(storage): address PR comments by extracting env var check to helper --- .../google/cloud/storage/_helpers.py | 6 ++---- .../google/cloud/storage/_http.py | 7 ++----- .../cloud/storage/_opentelemetry_tracing.py | 6 ++++++ .../tests/unit/test__opentelemetry_tracing.py | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/packages/google-cloud-storage/google/cloud/storage/_helpers.py b/packages/google-cloud-storage/google/cloud/storage/_helpers.py index 4d7b8b77ee5c..04039971ef41 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_helpers.py +++ b/packages/google-cloud-storage/google/cloud/storage/_helpers.py @@ -34,6 +34,7 @@ from google.cloud.storage._opentelemetry_tracing import ( create_trace_span as _base_create_trace_span, + _is_bucket_metadata_disabled, ) from google.cloud.storage.constants import _DEFAULT_TIMEOUT from google.cloud.storage.retry import ( @@ -156,10 +157,7 @@ def create_trace_span_helper(client, bucket_name, name, attributes=None, **kwarg and client and hasattr(client, "_bucket_metadata_cache") and client._bucket_metadata_cache - and not ( - os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() - in ("1", "true", "yes", "on") - ) + and not _is_bucket_metadata_disabled() ): try: if name in ( diff --git a/packages/google-cloud-storage/google/cloud/storage/_http.py b/packages/google-cloud-storage/google/cloud/storage/_http.py index ddf281a16b32..bfe2bf3843af 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_http.py +++ b/packages/google-cloud-storage/google/cloud/storage/_http.py @@ -16,7 +16,6 @@ import functools import logging -import os import re from google.api_core import exceptions as api_exceptions @@ -28,6 +27,7 @@ HAS_OPENTELEMETRY, create_trace_span, enable_otel_traces, + _is_bucket_metadata_disabled, ) logger = logging.getLogger(__name__) @@ -89,10 +89,7 @@ def api_request(self, *args, **kwargs): and enable_otel_traces and hasattr(client, "_bucket_metadata_cache") and client._bucket_metadata_cache - and not ( - os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower() - in ("1", "true", "yes", "on") - ) + and not _is_bucket_metadata_disabled() ): path = kwargs.get("path") or "" match = re.search(r"/b/([^/?#]+)", path) diff --git a/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py b/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py index 173fa090fcb5..7601542e704e 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py +++ b/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py @@ -27,6 +27,7 @@ ENABLE_OTEL_TRACES_ENV_VAR = "ENABLE_GCS_PYTHON_CLIENT_OTEL_TRACES" _DEFAULT_ENABLE_OTEL_TRACES_VALUE = False +DISABLE_BUCKET_MD_ENV_VAR = "DISABLE_BUCKET_MD_IN_OTEL" def _parse_bool_env(name: str, default: bool = False) -> bool: @@ -36,11 +37,16 @@ def _parse_bool_env(name: str, default: bool = False) -> bool: return str(val).strip().lower() in {"1", "true", "yes", "on"} +def _is_bucket_metadata_disabled() -> bool: + return _parse_bool_env(DISABLE_BUCKET_MD_ENV_VAR, False) + + enable_otel_traces = _parse_bool_env( ENABLE_OTEL_TRACES_ENV_VAR, _DEFAULT_ENABLE_OTEL_TRACES_VALUE ) logger = logging.getLogger(__name__) + try: from opentelemetry import trace diff --git a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py index 9a17281906e7..6464c93fb207 100644 --- a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py +++ b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py @@ -321,3 +321,24 @@ def test__parse_bool_env(monkeypatch, env_value, default, expected): result = _opentelemetry_tracing._parse_bool_env(env_var_name, default) assert result is expected + + +def test__is_bucket_metadata_disabled(monkeypatch): + # Test default (not set) + monkeypatch.delenv("DISABLE_BUCKET_MD_IN_OTEL", raising=False) + assert not _opentelemetry_tracing._is_bucket_metadata_disabled() + + # Test truthy + monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "true") + assert _opentelemetry_tracing._is_bucket_metadata_disabled() + + monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "1") + assert _opentelemetry_tracing._is_bucket_metadata_disabled() + + # Test falsy + monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "false") + assert not _opentelemetry_tracing._is_bucket_metadata_disabled() + + monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "0") + assert not _opentelemetry_tracing._is_bucket_metadata_disabled() + From 6ce891f82f4bc861745a0d98e1eb45be04dcbf98 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Thu, 4 Jun 2026 08:28:41 +0000 Subject: [PATCH 4/7] chore(storage): rename DISABLE_BUCKET_MD_IN_OTEL to DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA --- .../google/cloud/storage/_opentelemetry_tracing.py | 2 +- .../tests/system/test_aco_observability.py | 6 +++--- .../tests/unit/test__opentelemetry_tracing.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py b/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py index 7601542e704e..1d9e4b88270b 100644 --- a/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py +++ b/packages/google-cloud-storage/google/cloud/storage/_opentelemetry_tracing.py @@ -27,7 +27,7 @@ ENABLE_OTEL_TRACES_ENV_VAR = "ENABLE_GCS_PYTHON_CLIENT_OTEL_TRACES" _DEFAULT_ENABLE_OTEL_TRACES_VALUE = False -DISABLE_BUCKET_MD_ENV_VAR = "DISABLE_BUCKET_MD_IN_OTEL" +DISABLE_BUCKET_MD_ENV_VAR = "DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA" def _parse_bool_env(name: str, default: bool = False) -> bool: diff --git a/packages/google-cloud-storage/tests/system/test_aco_observability.py b/packages/google-cloud-storage/tests/system/test_aco_observability.py index 90db98500792..3e8daa97bb89 100644 --- a/packages/google-cloud-storage/tests/system/test_aco_observability.py +++ b/packages/google-cloud-storage/tests/system/test_aco_observability.py @@ -554,7 +554,7 @@ def monitored_update(*args, **kwargs): def test_disable_bucket_md_env_flag( storage_client, exporter, buckets_to_delete, monkeypatch ): - """Verifies that setting DISABLE_BUCKET_MD_IN_OTEL=true disables GCS + """Verifies that setting DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA=true disables GCS destination annotations, even on cache hits.""" # Clear cache and OTel exporter logs storage_client._bucket_metadata_cache.clear() @@ -572,8 +572,8 @@ def test_disable_bucket_md_env_flag( # Warm cache directly via GCS creation warming (client.create_bucket already primes the cache) assert storage_client._bucket_metadata_cache.get(bucket_name) is not None - # Enable the DISABLE_BUCKET_MD_IN_OTEL environment variable using monkeypatch - monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "true") + # Enable the DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment variable using monkeypatch + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "true") # Download (normally would be a cache hit with GCS annotations) blob.download_as_bytes() diff --git a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py index 6464c93fb207..b1459d3df9ea 100644 --- a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py +++ b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py @@ -325,20 +325,20 @@ def test__parse_bool_env(monkeypatch, env_value, default, expected): def test__is_bucket_metadata_disabled(monkeypatch): # Test default (not set) - monkeypatch.delenv("DISABLE_BUCKET_MD_IN_OTEL", raising=False) + monkeypatch.delenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", raising=False) assert not _opentelemetry_tracing._is_bucket_metadata_disabled() # Test truthy - monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "true") + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "true") assert _opentelemetry_tracing._is_bucket_metadata_disabled() - monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "1") + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "1") assert _opentelemetry_tracing._is_bucket_metadata_disabled() # Test falsy - monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "false") + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "false") assert not _opentelemetry_tracing._is_bucket_metadata_disabled() - monkeypatch.setenv("DISABLE_BUCKET_MD_IN_OTEL", "0") + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "0") assert not _opentelemetry_tracing._is_bucket_metadata_disabled() From d25591aaa4c77c8b3fff0c5f27a57f5de07f0898 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Thu, 4 Jun 2026 08:35:13 +0000 Subject: [PATCH 5/7] test(storage): add unit and system tests for other truthy env values --- .../tests/system/test_aco_observability.py | 7 ++++--- .../tests/unit/test__opentelemetry_tracing.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/google-cloud-storage/tests/system/test_aco_observability.py b/packages/google-cloud-storage/tests/system/test_aco_observability.py index 3e8daa97bb89..280a7d05badb 100644 --- a/packages/google-cloud-storage/tests/system/test_aco_observability.py +++ b/packages/google-cloud-storage/tests/system/test_aco_observability.py @@ -551,10 +551,11 @@ def monitored_update(*args, **kwargs): storage_client._bucket_metadata_cache.update_cache = original_update +@pytest.mark.parametrize("env_value", ["true", "1", "yes", "on"]) def test_disable_bucket_md_env_flag( - storage_client, exporter, buckets_to_delete, monkeypatch + storage_client, exporter, buckets_to_delete, monkeypatch, env_value ): - """Verifies that setting DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA=true disables GCS + """Verifies that setting DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA to a truthy value disables GCS destination annotations, even on cache hits.""" # Clear cache and OTel exporter logs storage_client._bucket_metadata_cache.clear() @@ -573,7 +574,7 @@ def test_disable_bucket_md_env_flag( assert storage_client._bucket_metadata_cache.get(bucket_name) is not None # Enable the DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment variable using monkeypatch - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "true") + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", env_value) # Download (normally would be a cache hit with GCS annotations) blob.download_as_bytes() diff --git a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py index b1459d3df9ea..6277dace3b0d 100644 --- a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py +++ b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py @@ -335,6 +335,12 @@ def test__is_bucket_metadata_disabled(monkeypatch): monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "1") assert _opentelemetry_tracing._is_bucket_metadata_disabled() + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "yes") + assert _opentelemetry_tracing._is_bucket_metadata_disabled() + + monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "on") + assert _opentelemetry_tracing._is_bucket_metadata_disabled() + # Test falsy monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "false") assert not _opentelemetry_tracing._is_bucket_metadata_disabled() From ee6c1adaa4c98542865ddf9e5a058f1ff4d7ce9b Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Thu, 4 Jun 2026 08:51:49 +0000 Subject: [PATCH 6/7] test(storage): parametrize test__is_bucket_metadata_disabled unit test --- .../tests/unit/test__opentelemetry_tracing.py | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py index 6277dace3b0d..700d69557d3e 100644 --- a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py +++ b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py @@ -323,28 +323,33 @@ def test__parse_bool_env(monkeypatch, env_value, default, expected): assert result is expected -def test__is_bucket_metadata_disabled(monkeypatch): - # Test default (not set) - monkeypatch.delenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", raising=False) - assert not _opentelemetry_tracing._is_bucket_metadata_disabled() - - # Test truthy - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "true") - assert _opentelemetry_tracing._is_bucket_metadata_disabled() - - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "1") - assert _opentelemetry_tracing._is_bucket_metadata_disabled() - - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "yes") - assert _opentelemetry_tracing._is_bucket_metadata_disabled() - - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "on") - assert _opentelemetry_tracing._is_bucket_metadata_disabled() - - # Test falsy - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "false") - assert not _opentelemetry_tracing._is_bucket_metadata_disabled() - - monkeypatch.setenv("DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA", "0") - assert not _opentelemetry_tracing._is_bucket_metadata_disabled() +@pytest.mark.parametrize( + "env_value, expected", + [ + # Test default (not set) + (None, False), + # Test truthy values + ("true", True), + ("1", True), + ("yes", True), + ("on", True), + ("TRUE", True), + (" Yes ", True), + # Test falsy values + ("false", False), + ("0", False), + ("no", False), + ("off", False), + ("any_other_string", False), + ("", False), + ], +) +def test__is_bucket_metadata_disabled(monkeypatch, env_value, expected): + env_var_name = "DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA" + if env_value is not None: + monkeypatch.setenv(env_var_name, str(env_value)) + else: + monkeypatch.delenv(env_var_name, raising=False) + + assert _opentelemetry_tracing._is_bucket_metadata_disabled() is expected From ab27a09c3d9bd98ff60d0b3015e63013afd9b38e Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Thu, 4 Jun 2026 09:39:32 +0000 Subject: [PATCH 7/7] style(storage): remove trailing blank line to fix lint failure --- .../tests/unit/test__opentelemetry_tracing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py index 700d69557d3e..70722bb0b0f8 100644 --- a/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py +++ b/packages/google-cloud-storage/tests/unit/test__opentelemetry_tracing.py @@ -352,4 +352,3 @@ def test__is_bucket_metadata_disabled(monkeypatch, env_value, expected): monkeypatch.delenv(env_var_name, raising=False) assert _opentelemetry_tracing._is_bucket_metadata_disabled() is expected -