From 84373e7c62dd6ba4e41f1890f7f2dd33da411c53 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Mon, 28 Oct 2024 19:20:21 +0530 Subject: [PATCH] fix flaky trace and span ids Signed-off-by: Varsha GS --- src/instana/util/ids.py | 17 +++++++++++++---- tests_aws/01_lambda/test_lambda.py | 7 ++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/instana/util/ids.py b/src/instana/util/ids.py index 391b6f80..afbf8aa1 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -135,12 +135,17 @@ def internal_id(id: Union[int, str]) -> int: """ if isinstance(id, int): return id + + length = len(id) if isinstance(id, str) and id.isdigit(): - return int(id) + if length == 16: + return int(id, 16) + else: + return int(id) try: - if len(id) < 16: + if length < 16: # Left pad ID with zeros id = id.zfill(16) @@ -157,11 +162,15 @@ def internal_id_limited(id: Union[int, str]) -> int: if isinstance(id, int): return id + length = len(id) + if isinstance(id, str) and id.isdigit(): - return int(id) + if length == 16: + return int(id, 16) + else: + return int(id) try: - length = len(id) if length < 16: # Left pad ID with zeros id = id.zfill(16) diff --git a/tests_aws/01_lambda/test_lambda.py b/tests_aws/01_lambda/test_lambda.py index 961bea1a..de59d921 100644 --- a/tests_aws/01_lambda/test_lambda.py +++ b/tests_aws/01_lambda/test_lambda.py @@ -803,12 +803,13 @@ def __validate_result_and_payload_for_gateway_v2_trace(self, result: Dict[str, A span = payload["spans"].pop() assert span.n == "aws.lambda.entry" - assert span.t == hex_id("0000000000001234") + trace_id = "0000000000001234" + assert span.t == trace_id assert span.s - assert span.p == hex_id("0000000000004567") + assert span.p == "0000000000004567" assert span.ts - server_timing_value = f"intid;desc={hex_id(int('0000000000001234'))}" + server_timing_value = f"intid;desc={trace_id}" assert result["headers"]["Server-Timing"] == server_timing_value assert span.f == {