-
Notifications
You must be signed in to change notification settings - Fork 21
Trace GCS upload/download duration and bytes #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+69
−12
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """GCS storage provider that emits one OTel span per upload/download so transfer duration is measurable.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import collections.abc | ||
| import contextlib | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.trace import StatusCode | ||
|
|
||
| from cloud_pipelines.orchestration.storage_providers import google_cloud_storage | ||
|
|
||
| _tracer = trace.get_tracer("tangle.storage") | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def _gcs_operation_span( | ||
| operation: str, uri: str | ||
| ) -> collections.abc.Iterator[trace.Span]: | ||
| with _tracer.start_as_current_span( | ||
| f"gcs.{operation}", | ||
| attributes={"gcs.operation": operation, "gcs.uri": uri}, | ||
| ) as span: | ||
| try: | ||
| yield span | ||
| except Exception as exception: | ||
| span.set_status(StatusCode.ERROR) | ||
| span.record_exception(exception) | ||
| raise | ||
|
|
||
|
|
||
| class TracingGoogleCloudStorageProvider( | ||
| google_cloud_storage.GoogleCloudStorageProvider | ||
| ): | ||
| def upload( | ||
| self, | ||
| source_path: str, | ||
| destination_uri: google_cloud_storage.GoogleCloudStorageUri, | ||
| ) -> None: | ||
| with _gcs_operation_span("upload", destination_uri.uri): | ||
| super().upload(source_path, destination_uri) | ||
|
|
||
| def upload_bytes( | ||
| self, data: bytes, destination_uri: google_cloud_storage.GoogleCloudStorageUri | ||
| ) -> None: | ||
| with _gcs_operation_span("upload_bytes", destination_uri.uri) as span: | ||
| span.set_attribute("gcs.bytes", len(data)) | ||
| super().upload_bytes(data, destination_uri) | ||
|
|
||
| def download( | ||
| self, | ||
| source_uri: google_cloud_storage.GoogleCloudStorageUri, | ||
| destination_path: str, | ||
| ) -> None: | ||
| with _gcs_operation_span("download", source_uri.uri): | ||
| super().download(source_uri, destination_path) | ||
|
|
||
| def download_bytes( | ||
| self, source_uri: google_cloud_storage.GoogleCloudStorageUri | ||
| ) -> bytes: | ||
| with _gcs_operation_span("download_bytes", source_uri.uri) as span: | ||
| data = super().download_bytes(source_uri) | ||
| span.set_attribute("gcs.bytes", len(data)) | ||
| return data | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review:
start_as_current_span()already records escaping exceptions and marks the span asERRORby default. Because this handler also callsset_status()andrecord_exception()before re-raising, each failed transfer emits two exception events (confirmed with an in-memory span exporter). Could we remove the manual exception handling, or explicitly disable the context manager’s automatic handling?