Merge "When shortening span-ids, check if they're already short"
This commit is contained in:
commit
257fc81bc7
|
@ -153,8 +153,11 @@ def import_modules_from_package(package):
|
|||
|
||||
def shorten_id(span_id):
|
||||
"""Convert from uuid4 to 64 bit id for OpenTracing"""
|
||||
int64_max = (1 << 64) - 1
|
||||
if isinstance(span_id, six.integer_types):
|
||||
return span_id & int64_max
|
||||
try:
|
||||
short_id = uuid.UUID(span_id).int & (1 << 64) - 1
|
||||
short_id = uuid.UUID(span_id).int & int64_max
|
||||
except ValueError:
|
||||
# Return a new short id for this
|
||||
short_id = shorten_id(uuidutils.generate_uuid())
|
||||
|
|
|
@ -69,6 +69,13 @@ class ProfilerTestCase(test.TestCase):
|
|||
expected = "850409eb1d4b0dee"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_profiler_get_shorten_id_int(self):
|
||||
short_id_int = 42
|
||||
prof = profiler._Profiler("secret", base_id="1", parent_id="2")
|
||||
result = prof.get_shorten_id(short_id_int)
|
||||
expected = "2a"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_profiler_get_base_id(self):
|
||||
prof = profiler._Profiler("secret", base_id="1", parent_id="2")
|
||||
self.assertEqual(prof.get_base_id(), "1")
|
||||
|
|
Loading…
Reference in New Issue