Repository navigation
feat(storage): add OpenTelemetry standard metrics for HTTP media transfers - #18943
Draft
shradhakatyal wants to merge 10 commits into
Draft
shradhakatyal wants to merge 10 commits into
shradhakatyal wants to merge 10 commits into
Conversation
…d helpers Implement core OpenTelemetry standard metrics infrastructure for GCS: - Add _MetricsRecorder with the 9 standard metric instruments - Add custom latency (165 buckets) and byte-size (45 buckets) histogram views - Add classify_error_type for low-cardinality error.type mapping - Add normalize_url_template for bounded HTTP url.template routing - Add start_operation ContextVar for outermost logical operation tracking and nested call suppression [Generated-by: AI]
…branch coverage [Generated-by: AI]
…ncellations [Generated-by: AI]
- Add gcp.storage.client.retries counter and rename TTFB metric to gcp.storage.client.ttfb - Remove gcp.client.repo from _COMMON_ATTRIBUTES - Update _build_size_buckets to generate 48 buckets matching Go and Java SDKs - Align per-metric attributes across logical operation, RPC/HTTP attempt, error, retry, and TTFB recorders [Generated-by: AI]
…fy CONNECTION_ERROR - Scope histogram View registrations to meter_name="google.cloud.storage" - Guard normalize_url_template and _extract_server_address against malformed URIs and gRPC authority schemes - Consolidate CONNECTION_REFUSED, CONNECTION_RESET, and CONNECTIVITY error labels into CONNECTION_ERROR [Generated-by: AI]
…port - Wire _MetricsRecorder lifecycle, enable_metrics, and meter_provider into Client - Instrument Connection.api_request for per-attempt HTTP duration, TTFB, retries, and errors - Add _start_storage_operation, _PropertyMixin, and lazy HTTPIterator page metrics helpers - Skip per-attempt HTTP metrics while queuing sub-requests into Batch - Suppress internal background BucketMetadataCache lookups from emitting user-facing metrics
… and resource APIs - Instrument logical operations on Client and Bucket metadata, IAM, lifecycle, and list APIs - Record Batch.finish() logical operation metrics while deferring queued sub-requests - Instrument BucketACL, DefaultObjectACL, ObjectACL, HMACKeyMetadata, and BucketNotification
…ata APIs - Instrument Blob JSON metadata operations including reload, update, patch, delete, copy, rewrite, compose, and restore - Add logical operation metrics for Blob IAM policy and temporary/event-based hold helpers
…sfers - Instrument _media/requests downloads, simple/multipart/resumable uploads, and XML MPU operations - Record streaming download TTFB on first body chunk and logical payload body sizes once per operation - Instrument Blob download_to_*, download_as_*, and upload_from_* entrypoints - Preserve primary failure attribution when cleanup calls fail without mutating exception chains
This was referenced Nov 1, 2026
Draft
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements comprehensive OpenTelemetry standard metrics instrumentation across the Google Cloud Storage Python client. It introduces tracking for logical operations, network attempts, retries, payload sizes, and latency (TTFB) with custom histogram boundaries, canonical error classification, and route normalization. These metrics are integrated into core operations including downloads, uploads, ACLs, HMAC keys, notifications, and batch requests, supported by extensive unit tests. I have no feedback to provide as there are no review comments.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenTelemetry standard metrics support for HTTP media downloads, simple/multipart/resumable uploads, and XML multipart upload (
XMLMPU) operations ingoogle-cloud-storage.Key Changes
_media/requests/_request_helpers.py,download.py,upload.py): InstrumentsDownload,RawDownload,ChunkedDownload,RawChunkedDownload,SimpleUpload,MultipartUpload,ResumableUpload,XMLMPUContainer, andXMLMPUPartfor per-attempt HTTP duration, streaming first-bytegcp.storage.client.ttfb, retries, errors, and logical payload body sizes.blob.py): Instrumentsdownload_to_file,download_to_filename,download_as_bytes,download_as_text,upload_from_file,upload_from_filename, andupload_from_string._helpers.py,blob.py): Adds_record_primary_exceptionso primary download/upload failures are preserved on logical metrics even if subsequent cleanup raises, without mutating caller exception chains.Note:
Blob's internal download/upload helpers map existingcommand="tm.upload_many"/"tm.download_many"arguments (already passed bytransfer_manageronmain) tostorage.transfer_manager.*_manyhere soblob.pydoes not need to be modified again in PR 3c.