Skip to content

chore(storage): support DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment variable flag#17248

Merged
chandra-siri merged 7 commits into
googleapis:mainfrom
chandra-siri:feat/gcs-aco-disable-env-flag
Jun 4, 2026
Merged

chore(storage): support DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment variable flag#17248
chandra-siri merged 7 commits into
googleapis:mainfrom
chandra-siri:feat/gcs-aco-disable-env-flag

Conversation

@chandra-siri
Copy link
Copy Markdown
Contributor

@chandra-siri chandra-siri commented May 26, 2026

This PR introduces the DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment flag to dynamically disable injecting Cloud Storage bucket metadata destination attributes (gcp.resource.destination.id and gcp.resource.destination.location) inside OTel spans.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the DISABLE_BUCKET_MD_IN_OTEL environment variable to allow users to explicitly disable GCS destination annotations in OpenTelemetry traces. While the implementation successfully achieves this, the current approach evaluates the environment variable on every single API request and trace span helper call, which introduces unnecessary overhead. To optimize performance, these checks should be inlined into the conditional blocks to leverage Python's short-circuit evaluation. Additionally, the system test should be refactored to use pytest's monkeypatch fixture instead of manual environment variable manipulation to ensure robust cleanup.

Comment thread packages/google-cloud-storage/google/cloud/storage/_http.py Outdated
Comment thread packages/google-cloud-storage/google/cloud/storage/_helpers.py Outdated
Comment thread packages/google-cloud-storage/tests/system/test_aco_observability.py Outdated
@chandra-siri chandra-siri force-pushed the feat/gcs-aco-disable-env-flag branch from 7dadd37 to 0866ac4 Compare May 27, 2026 09:42
and client._bucket_metadata_cache
and not (
os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower()
in ("1", "true", "yes", "on")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for all values, can't we just document the usage of this environment variable instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept consistent with what already existing for Otel in python -

return str(val).strip().lower() in {"1", "true", "yes", "on"}

the way it was checked lacked readablity. I've now made it a bit more readable.

Comment thread packages/google-cloud-storage/google/cloud/storage/_http.py Outdated
and hasattr(client, "_bucket_metadata_cache")
and client._bucket_metadata_cache
and not (
os.environ.get("DISABLE_BUCKET_MD_IN_OTEL", "").lower()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related to the feature guarded by ENABLE_GCS_PYTHON_CLIENT_OTEL_TRACES? If so, should we use consistent naming?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@chandra-siri chandra-siri changed the title chore(storage): support DISABLE_BUCKET_MD_IN_OTEL environment variable flag chore(storage): support DISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA environment variable flag Jun 4, 2026
@chandra-siri chandra-siri merged commit e4a207d into googleapis:main Jun 4, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants