feat(storage): add OpenTelemetry tracing support for Zonal Buckets - #18397
shradhakatyal wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces OpenTelemetry tracing support for zonal buckets (Rapid Storage) in async gRPC classes. It refactors tracing span creation to support both synchronous and asynchronous context managers, injects traceparent metadata into gRPC requests, and updates the bucket metadata cache to support asynchronous gRPC fetches. The review feedback recommends defensively checking for __aenter__ and __aexit__ in _TraceSpanHelperContext to ensure compatibility with synchronous context managers (such as mocked spans in unit tests) and refactoring the project number extraction in update_from_bucket to use getattr more idiomatically.
| async def __aenter__(self): | ||
| self._prepare_base_cm() | ||
| return await self._base_cm.__aenter__() | ||
|
|
||
| async def __aexit__(self, exc_type, exc_val, exc_tb): | ||
| if exc_val is not None and isinstance( | ||
| exc_val, (NotFound, api_exceptions.NotFound) | ||
| ): | ||
| self._handle_not_found() | ||
| if self._base_cm is not None: | ||
| return await self._base_cm.__aexit__(exc_type, exc_val, exc_tb) | ||
| return False |
There was a problem hiding this comment.
To ensure robustness against synchronous context managers (which are commonly returned when mocking create_trace_span in existing unit tests), we should defensively check if the underlying context manager supports __aenter__ and __aexit__. If it does not, we should fall back to calling __enter__ and __exit__ synchronously.
async def __aenter__(self):
self._prepare_base_cm()
if hasattr(self._base_cm, "__aenter__"):
return await self._base_cm.__aenter__()
return self._base_cm.__enter__()
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_val is not None and isinstance(
exc_val, (NotFound, api_exceptions.NotFound)
):
self._handle_not_found()
if self._base_cm is not None:
if hasattr(self._base_cm, "__aexit__"):
return await self._base_cm.__aexit__(exc_type, exc_val, exc_tb)
return self._base_cm.__exit__(exc_type, exc_val, exc_tb)
return False…adata_cache.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…te leakage across unit tests
50474ec to
e572fb0
Compare
This PR adds OpenTelemetry tracing support for Zonal Buckets (Rapid Storage) across the asynchronous gRPC client and streaming classes (
AsyncGrpcClient,AsyncAppendableObjectWriter, andAsyncMultiRangeDownloader).The implementation aligns with existing regional bucket tracing conventions:
Storage.<Class>.<methodName>.ENABLE_GCS_PYTHON_CLIENT_OTEL_TRACESandDISABLE_GCS_PYTHON_CLIENT_OTEL_BUCKET_METADATA).rpc.system="grpc"and attaches App-Centric Observability (ACO) attributes (gcp.resource.destination.idandgcp.resource.destination.location).traceparentheaders directly into gRPC request metadata tuples.Fixes: b/489239033