Skip to content

Commit

Permalink
fix flaky trace and span ids
Browse files Browse the repository at this point in the history
Signed-off-by: Varsha GS <varsha.gs@ibm.com>
  • Loading branch information
GSVarsha committed Oct 29, 2024
1 parent c1d9c3b commit 84373e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/instana/util/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions tests_aws/01_lambda/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {
Expand Down

0 comments on commit 84373e7

Please sign in to comment.