Skip to content

feat: track invocation id for retry metrics #741

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

Merged
merged 11 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from hashlib import md5
import os
from urllib.parse import urlsplit
from uuid import uuid4

from google import resumable_media
from google.auth import environment_vars
Expand Down Expand Up @@ -599,7 +600,7 @@ def _get_default_headers(
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"User-Agent": user_agent,
"x-goog-api-client": user_agent,
"x-goog-api-client": user_agent + " gccl-invocation-id/" + uuid4(),
"content-type": content_type,
"x-upload-content-type": x_upload_content_type or content_type,
}
6 changes: 6 additions & 0 deletions google/cloud/storage/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import functools
import os
from uuid import uuid4
import pkg_resources

from google.cloud import _http
Expand Down Expand Up @@ -68,6 +69,11 @@ def __init__(self, client, client_info=None, api_endpoint=None):

def api_request(self, *args, **kwargs):
retry = kwargs.pop("retry", None)
headers = {
**kwargs.pop("headers", {}),
"x-goog-api-client": self._connection.user_agent + " gccl-invocation-id: " + uuid4(),
}
kwargs["headers"] = headers
call = functools.partial(super(Connection, self).api_request, *args, **kwargs)
if retry:
# If this is a ConditionalRetryPolicy, check conditions.
Expand Down