Skip to content

Commit fed1458

Browse files
Sushant Khannasushantkhanna
authored andcommitted
Add invocation id to Gsutil user agent
1 parent af1d779 commit fed1458

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

gslib/tests/test_Doption.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def test_minus_D_cat(self):
189189
self.assertIn('Content-Length: 0', request_fields_str)
190190
self.assertRegex(
191191
request_fields_str,
192-
'User-Agent: .*gsutil/%s.*interactive/False command/cat' %
193-
gslib.VERSION)
192+
'User-Agent: .*gsutil/%s.*interactive/False invocation-id/[a-z0-9-].+ command/cat'
193+
% gslib.VERSION)
194194
elif self.test_api == ApiSelector.JSON:
195195
if six.PY2:
196196
self.assertIn("md5Hash: u'eB5eJF1ptWaXm4bijSPyxw=='", stderr)
@@ -203,8 +203,9 @@ def test_minus_D_cat(self):
203203
stderr,
204204
'.*GET.*b/%s/o/%s' % (key_uri.bucket_name, key_uri.object_name))
205205
self.assertRegex(
206-
stderr, 'Python/%s.gsutil/%s.*interactive/False command/cat' %
207-
(platform.python_version(), gslib.VERSION))
206+
stderr,
207+
'Python/%s.gsutil/%s.*interactive/False invocation-id/[a-z0-9-].+ command/cat'
208+
% (platform.python_version(), gslib.VERSION))
208209

209210
if gslib.IS_PACKAGE_INSTALL:
210211
self.assertIn('PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS', stdout)

gslib/utils/user_agent_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import six
1818
import sys
19+
import uuid
1920
import gslib
2021
from gslib.utils import system_util
2122
from gslib.storage_url import StorageUrlFromString
@@ -36,6 +37,7 @@ def GetUserAgent(args, metrics_off=True):
3637
user_agent += ' (%s)' % sys.platform
3738
user_agent += ' analytics/%s' % ('disabled' if metrics_off else 'enabled')
3839
user_agent += ' interactive/%s' % system_util.IsRunningInteractively()
40+
user_agent += ' invocation-id/%s' % uuid.uuid4().hex
3941

4042
if len(args) > 0:
4143
user_agent += ' command/%s' % args[0]

0 commit comments

Comments
 (0)