Skip to content
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

Fix flaky tests with inconsistent trace and span ids #664

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading