diff --git a/src/instana/collector/utils.py b/src/instana/collector/utils.py index 7292cca4..1da5892b 100644 --- a/src/instana/collector/utils.py +++ b/src/instana/collector/utils.py @@ -5,6 +5,7 @@ from opentelemetry.trace.span import format_span_id from opentelemetry.trace import SpanKind +from instana.util.ids import hex_id if TYPE_CHECKING: from instana.span.base_span import BaseSpan @@ -22,6 +23,7 @@ def format_span( span.t = format_span_id(span.t) span.s = format_span_id(span.s) span.p = format_span_id(span.p) if span.p else None + span.lt = hex_id(span.lt) if hasattr(span, "lt") else None if isinstance(span.k, SpanKind): span.k = span.k.value if not span.k is SpanKind.INTERNAL else 3 spans.append(span) diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index 7286cce4..4f6b95dd 100644 --- a/src/instana/propagators/base_propagator.py +++ b/src/instana/propagators/base_propagator.py @@ -8,7 +8,7 @@ from instana.log import logger from instana.span_context import SpanContext -from instana.util.ids import header_to_id, header_to_long_id, hex_id +from instana.util.ids import header_to_id, header_to_long_id, hex_id, internal_id, internal_id_limited, hex_id_limited from instana.w3c_trace_context.traceparent import Traceparent from instana.w3c_trace_context.tracestate import Tracestate @@ -149,7 +149,7 @@ def _get_participating_trace_context(self, span_context: SpanContext): if span_context.suppression: return traceparent, tracestate - tracestate = self._ts.update_tracestate(tracestate, hex_id(span_context.trace_id), hex_id(span_context.span_id)) + tracestate = self._ts.update_tracestate(tracestate, hex_id_limited(span_context.trace_id), hex_id(span_context.span_id)) return traceparent, tracestate def __determine_span_context( @@ -219,7 +219,7 @@ def __determine_span_context( instana_ancestor = self._ts.get_instana_ancestor(tracestate) if disable_traceparent == "": - ctx_trace_id = tp_trace_id + ctx_trace_id = hex_id_limited(tp_trace_id) ctx_span_id = tp_parent_id ctx_synthetic = synthetic ctx_trace_parent = True @@ -241,9 +241,21 @@ def __determine_span_context( ctx_traceparent = traceparent ctx_tracestate = tracestate + if ctx_trace_id: + if isinstance(ctx_trace_id, int): + # check if ctx_trace_id is a valid internal trace id + if (ctx_trace_id <= 2**64 - 1): + trace_id = ctx_trace_id + else: + trace_id = internal_id(hex_id_limited(ctx_trace_id)) + else: + trace_id = internal_id(ctx_trace_id) + else: + trace_id = INVALID_TRACE_ID + return SpanContext( - trace_id=int(ctx_trace_id) if ctx_trace_id else INVALID_TRACE_ID, - span_id=int(ctx_span_id) if ctx_span_id else INVALID_SPAN_ID, + trace_id=trace_id, + span_id=internal_id_limited(ctx_span_id) if ctx_span_id else INVALID_SPAN_ID, is_remote=False, level=ctx_level, synthetic=ctx_synthetic, diff --git a/src/instana/propagators/http_propagator.py b/src/instana/propagators/http_propagator.py index cd615b62..76ca3114 100644 --- a/src/instana/propagators/http_propagator.py +++ b/src/instana/propagators/http_propagator.py @@ -4,7 +4,7 @@ from instana.log import logger from instana.propagators.base_propagator import BasePropagator -from instana.util.ids import define_server_timing +from instana.util.ids import define_server_timing, hex_id_limited from opentelemetry.trace.span import format_span_id @@ -55,7 +55,7 @@ def inject_key_value(carrier, key, value): if span_context.suppression: return - inject_key_value(carrier, self.HEADER_KEY_T, format_span_id(trace_id)) + inject_key_value(carrier, self.HEADER_KEY_T, hex_id_limited(trace_id)) inject_key_value(carrier, self.HEADER_KEY_S, format_span_id(span_id)) inject_key_value( carrier, self.HEADER_KEY_SERVER_TIMING, define_server_timing(trace_id) diff --git a/src/instana/span/base_span.py b/src/instana/span/base_span.py index fbdb4c42..0d8491c2 100644 --- a/src/instana/span/base_span.py +++ b/src/instana/span/base_span.py @@ -5,6 +5,7 @@ from instana.log import logger from instana.util import DictionaryOfStan +from instana.span.kind import ENTRY_SPANS if TYPE_CHECKING: from opentelemetry.trace import Span @@ -31,7 +32,7 @@ def __init__(self, span: Type["Span"], source, **kwargs) -> None: self.data = DictionaryOfStan() self.stack = span.stack - if span.synthetic is True: + if span.synthetic is True and span.name in ENTRY_SPANS: self.sy = span.synthetic self.__dict__.update(kwargs) diff --git a/src/instana/tracer.py b/src/instana/tracer.py index a5bdf895..28876070 100644 --- a/src/instana/tracer.py +++ b/src/instana/tracer.py @@ -123,10 +123,6 @@ def start_span( if parent_context and not isinstance(parent_context, SpanContext): raise TypeError("parent_context must be an Instana SpanContext or None.") - if parent_context and not parent_context.is_valid and not parent_context.suppression: - # We probably have an INVALID_SPAN_CONTEXT. - parent_context = None - span_context = self._create_span_context(parent_context) span = InstanaSpan( name, @@ -138,9 +134,6 @@ def start_span( # events: Sequence[Event] = None, ) - if parent_context is not None: - span.synthetic = parent_context.synthetic - if name in EXIT_SPANS: self._add_stack(span) @@ -230,17 +223,15 @@ def _create_span_context(self, parent_context: SpanContext) -> SpanContext: is_remote=is_remote, level=(parent_context.level if parent_context else 1), synthetic=(parent_context.synthetic if parent_context else False), + trace_parent=(parent_context.trace_parent if parent_context else None), + instana_ancestor=(parent_context.instana_ancestor if parent_context else None), + long_trace_id=(parent_context.long_trace_id if parent_context else None), + correlation_type=(parent_context.correlation_type if parent_context else None), + correlation_id=(parent_context.correlation_id if parent_context else None), + traceparent=(parent_context.traceparent if parent_context else None), + tracestate=(parent_context.tracestate if parent_context else None), ) - if parent_context is not None: - span_context.long_trace_id = parent_context.long_trace_id - span_context.trace_parent = parent_context.trace_parent - span_context.instana_ancestor = parent_context.instana_ancestor - span_context.correlation_type = parent_context.correlation_type - span_context.correlation_id = parent_context.correlation_id - span_context.traceparent = parent_context.traceparent - span_context.tracestate = parent_context.tracestate - return span_context def inject( diff --git a/src/instana/util/ids.py b/src/instana/util/ids.py index afeb9805..391b6f80 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -6,7 +6,7 @@ import random from typing import Union -from opentelemetry.trace.span import _SPAN_ID_MAX_VALUE, INVALID_SPAN_ID +from opentelemetry.trace.span import _SPAN_ID_MAX_VALUE, INVALID_SPAN_ID, INVALID_TRACE_ID _rnd = random.Random() _current_pid = 0 @@ -42,7 +42,7 @@ def header_to_long_id(header: Union[bytes, str]) -> int: header = header.decode('utf-8') if not isinstance(header, str): - return INVALID_SPAN_ID + return INVALID_TRACE_ID if header.isdecimal(): return header @@ -54,7 +54,7 @@ def header_to_long_id(header: Union[bytes, str]) -> int: return int(header, 16) except ValueError: - return INVALID_SPAN_ID + return INVALID_TRACE_ID def header_to_id(header: Union[bytes, str]) -> int: @@ -92,14 +92,84 @@ def header_to_id(header: Union[bytes, str]) -> int: def hex_id(id: Union[int, str]) -> str: """ Returns the hexadecimal representation of the given ID. + Left pad with zeros when the length is not equal to 16 """ - - hex_id = hex(int(id))[2:] - if len(hex_id) < 16: - hex_id = hex_id.zfill(16) - return hex_id - + try: + hex_id = hex(int(id))[2:] + length = len(hex_id) + # Left pad ID with zeros + if length < 16: + hex_id = hex_id.zfill(16) + elif length > 16 and length < 32: + hex_id = hex_id.zfill(32) + return hex_id + except ValueError: # Handles ValueError: invalid literal for int() with base 10: + return id + +def hex_id_limited(id: Union[int, str]) -> str: + """ + Returns the hexadecimal representation of the given ID. + Limit longer IDs to 16 characters + """ + try: + hex_id = hex(int(id))[2:] + length = len(hex_id) + if length < 16: + # Left pad ID with zeros + hex_id = hex_id.zfill(16) + elif length > 16: + # Phase 0: Discard everything but the last 16byte + hex_id = hex_id[-16:] + return hex_id + except ValueError: # Handles ValueError: invalid literal for int() with base 10: + return id def define_server_timing(trace_id: Union[int, str]) -> str: # Note: The key `intid` is short for Instana Trace ID. - return f"intid;desc={hex_id(trace_id)}" + return f"intid;desc={hex_id_limited(trace_id)}" + + +def internal_id(id: Union[int, str]) -> int: + """ + Returns a valid id to be used internally. Handles both str and int types. + """ + if isinstance(id, int): + return id + + if isinstance(id, str) and id.isdigit(): + return int(id) + + try: + if len(id) < 16: + # Left pad ID with zeros + id = id.zfill(16) + + # hex string -> int + return int(id, 16) + except ValueError: + return INVALID_TRACE_ID + +def internal_id_limited(id: Union[int, str]) -> int: + """ + Returns a valid id to be used internally. Handles both str and int types. + Note: Limits the hex string to 16 chars before conversion. + """ + if isinstance(id, int): + return id + + if isinstance(id, str) and id.isdigit(): + return int(id) + + try: + length = len(id) + if length < 16: + # Left pad ID with zeros + id = id.zfill(16) + elif length > 16: + # Phase 0: Discard everything but the last 16byte + id = id[-16:] + + # hex string -> int + return int(id, 16) + except ValueError: + return INVALID_SPAN_ID diff --git a/src/instana/w3c_trace_context/traceparent.py b/src/instana/w3c_trace_context/traceparent.py index edfd7066..315bdd30 100644 --- a/src/instana/w3c_trace_context/traceparent.py +++ b/src/instana/w3c_trace_context/traceparent.py @@ -10,7 +10,7 @@ ) from instana.log import logger -from instana.util.ids import header_to_id +from instana.util.ids import header_to_id, header_to_long_id # See https://www.w3.org/TR/trace-context-2/#trace-flags for details on the bitmasks. SAMPLED_BITMASK = 0b1; @@ -48,7 +48,7 @@ def get_traceparent_fields(traceparent: str) -> Tuple[Optional[str], Optional[in try: traceparent_properties = traceparent.split("-") version = traceparent_properties[0] - trace_id = header_to_id(traceparent_properties[1]) + trace_id = header_to_long_id(traceparent_properties[1]) parent_id = header_to_id(traceparent_properties[2]) flags = int(traceparent_properties[3], 16) sampled_flag = (flags & SAMPLED_BITMASK) == SAMPLED_BITMASK @@ -99,5 +99,10 @@ def update_traceparent( flags = level & SAMPLED_BITMASK flags = format(flags, "0>2x") - traceparent = f"{self.SPECIFICATION_VERSION}-{format_trace_id(trace_id)}-{format_span_id(parent_id)}-{flags}" + if isinstance(trace_id, str): + trace_id_out = trace_id + else: + trace_id_out = format_trace_id(trace_id) + + traceparent = f"{self.SPECIFICATION_VERSION}-{trace_id_out}-{format_span_id(parent_id)}-{flags}" return traceparent diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py index 6c41bf82..876fd2ba 100644 --- a/tests/frameworks/test_flask.py +++ b/tests/frameworks/test_flask.py @@ -211,8 +211,8 @@ def test_get_request_with_suppression(self) -> None: # Assert that there are no spans in the recorded list assert spans == [] - @unittest.skip("Handled when type of trace and span ids are modified to str") def test_get_request_with_suppression_and_w3c(self) -> None: + """Incoming Level 0 Plus W3C Trace Context Specification Headers""" headers = { 'X-INSTANA-L':'0', 'traceparent': '00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01', @@ -223,7 +223,12 @@ def test_get_request_with_suppression_and_w3c(self) -> None: spans = self.recorder.queued_spans() assert response.headers.get("X-INSTANA-L", None) == "0" + # if X-INSTANA-L=0 then both X-INSTANA-T and X-INSTANA-S should not be present + assert not response.headers.get("X-INSTANA-T", None) + assert not response.headers.get("X-INSTANA-S", None) + assert response.headers.get("traceparent", None) is not None + assert response.headers["traceparent"].startswith("00-0af7651916cd43dd8448eb211c80319c") assert response.headers["traceparent"][-1] == "0" # The tracestate has to be present assert response.headers.get("tracestate", None) is not None diff --git a/tests/propagators/test_http_propagator.py b/tests/propagators/test_http_propagator.py index ae4af3b6..25b36635 100644 --- a/tests/propagators/test_http_propagator.py +++ b/tests/propagators/test_http_propagator.py @@ -14,7 +14,7 @@ from instana.propagators.http_propagator import HTTPPropagator from instana.span_context import SpanContext -from instana.util.ids import header_to_id +from instana.util.ids import header_to_long_id, internal_id class TestHTTPPropagator: @@ -62,7 +62,6 @@ def test_extract_carrier_dict( span_id: int, _instana_long_tracer_id: str, _instana_span_id: str, - _long_tracer_id: int, _trace_id: int, _span_id: int, _traceparent: str, @@ -82,7 +81,7 @@ def test_extract_carrier_dict( assert ctx.correlation_type == "web" assert not ctx.instana_ancestor assert ctx.level == 1 - assert ctx.long_trace_id == header_to_id(_instana_long_tracer_id) + assert ctx.long_trace_id == header_to_long_id(_instana_long_tracer_id) assert ctx.span_id == _span_id assert not ctx.synthetic assert ctx.trace_id == _trace_id @@ -92,13 +91,14 @@ def test_extract_carrier_dict( def test_extract_carrier_list( self, - trace_id: int, - span_id: int, + _trace_id: int, + _span_id: int, _instana_long_tracer_id: str, _instana_span_id: str, _traceparent: str, _tracestate: str, ) -> None: + _trace_id = str(_trace_id) carrier = [ ("user-agent", "python-requests/2.23.0"), ("accept-encoding", "gzip, deflate"), @@ -106,8 +106,8 @@ def test_extract_carrier_list( ("connection", "keep-alive"), ("traceparent", _traceparent), ("tracestate", _tracestate), - ("X-INSTANA-T", f"{trace_id}"), - ("X-INSTANA-S", f"{span_id}"), + ("X-INSTANA-T", f"{_trace_id}"), + ("X-INSTANA-S", f"{_span_id}"), ("X-INSTANA-L", "1"), ] @@ -118,9 +118,9 @@ def test_extract_carrier_list( assert not ctx.instana_ancestor assert ctx.level == 1 assert not ctx.long_trace_id - assert ctx.span_id == span_id + assert ctx.span_id == _span_id assert not ctx.synthetic - assert ctx.trace_id == trace_id + assert ctx.trace_id == internal_id(_trace_id) assert not ctx.trace_parent assert ctx.traceparent == f"00-{_instana_long_tracer_id}-{_instana_span_id}-01" assert ctx.tracestate == _tracestate @@ -199,7 +199,7 @@ def test_extract_carrier_dict_corrupted_level_header( assert ctx.correlation_type == "web" assert not ctx.instana_ancestor assert ctx.level == 1 - assert ctx.long_trace_id == header_to_id(_instana_long_tracer_id) + assert ctx.long_trace_id == header_to_long_id(_instana_long_tracer_id) assert ctx.span_id == _span_id assert not ctx.synthetic assert ctx.trace_id == _trace_id @@ -209,16 +209,17 @@ def test_extract_carrier_dict_corrupted_level_header( def test_extract_carrier_dict_level_header_not_splitable( self, - trace_id: int, - span_id: int, + _trace_id: int, + _span_id: int, _traceparent: str, _tracestate: str, ) -> None: + _trace_id = str(_trace_id) carrier = { "traceparent": _traceparent, "tracestate": _tracestate, - "X-INSTANA-T": f"{trace_id}", - "X-INSTANA-S": f"{span_id}", + "X-INSTANA-T": f"{_trace_id}", + "X-INSTANA-S": f"{_span_id}", "X-INSTANA-L": ["1"], } @@ -229,9 +230,9 @@ def test_extract_carrier_dict_level_header_not_splitable( assert not ctx.instana_ancestor assert ctx.level == 1 assert not ctx.long_trace_id - assert ctx.span_id == span_id + assert ctx.span_id == _span_id assert not ctx.synthetic - assert ctx.trace_id == trace_id + assert ctx.trace_id == internal_id(_trace_id) assert not ctx.trace_parent assert ctx.traceparent == _traceparent assert ctx.tracestate == _tracestate @@ -304,7 +305,7 @@ def test_w3c_off_x_instana_l_0( # Assert that the traceparent is propagated when it is enabled if "traceparent" in carrier_header.keys(): assert ctx.traceparent - tp_trace_id = header_to_id(carrier_header["traceparent"].split("-")[1]) + tp_trace_id = header_to_long_id(carrier_header["traceparent"].split("-")[1]) else: assert not ctx.traceparent tp_trace_id = ctx.trace_id diff --git a/tests/span/test_base_span.py b/tests/span/test_base_span.py index 3b2302cf..2e0fbf43 100644 --- a/tests/span/test_base_span.py +++ b/tests/span/test_base_span.py @@ -59,7 +59,8 @@ def test_basespan_with_synthetic_source_and_kwargs( assert trace_id == base_span.t assert span_id == base_span.s - assert base_span.sy + # synthetic should be true only for entry spans + assert not base_span.sy assert source == base_span.f assert _kwarg1 == base_span.arg1 @@ -101,7 +102,8 @@ def test_populate_extra_span_attributes_with_values( assert trace_id == base_span.t assert span_id == base_span.s - assert base_span.sy + # synthetic should be true only for entry spans + assert not base_span.sy assert base_span.tp assert "IDK" == base_span.ia assert long_id == base_span.lt diff --git a/tests/w3c_trace_context/test_traceparent.py b/tests/w3c_trace_context/test_traceparent.py index 3eb83a4e..beec0341 100644 --- a/tests/w3c_trace_context/test_traceparent.py +++ b/tests/w3c_trace_context/test_traceparent.py @@ -1,31 +1,31 @@ # (c) Copyright IBM Corp. 2021 # (c) Copyright Instana Inc. 2021 -import pytest from instana.w3c_trace_context.traceparent import Traceparent import unittest - +from instana.util.ids import header_to_long_id, header_to_id class TestTraceparent(unittest.TestCase): def setUp(self): self.tp = Traceparent() + self.w3cTraceId = "4bf92f3577b34da6a3ce929d0e0e4736" def test_validate_valid(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-01" self.assertEqual(traceparent, self.tp.validate(traceparent)) def test_validate_newer_version(self): # Although the incoming traceparent header sports a newer version number, we should still be able to parse the # parts that we understand (and consider it valid). - traceparent = "fe-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-12345-abcd" + traceparent = f"fe-{self.w3cTraceId}-00f067aa0ba902b7-01-12345-abcd" self.assertEqual(traceparent, self.tp.validate(traceparent)) def test_validate_unknown_flags(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-ee" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-ee" self.assertEqual(traceparent, self.tp.validate(traceparent)) def test_validate_invalid_traceparent_version(self): - traceparent = "ff-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" + traceparent = f"ff-{self.w3cTraceId}-00f067aa0ba902b7-01" self.assertIsNone(self.tp.validate(traceparent)) def test_validate_invalid_traceparent(self): @@ -37,32 +37,32 @@ def test_validate_traceparent_None(self): self.assertIsNone(self.tp.validate(traceparent)) def test_get_traceparent_fields(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-01" version, trace_id, parent_id, sampled_flag = self.tp.get_traceparent_fields(traceparent) - self.assertEqual(trace_id, 11803532876627986230) + self.assertEqual(trace_id, header_to_long_id(self.w3cTraceId)) self.assertEqual(parent_id, 67667974448284343) self.assertTrue(sampled_flag) def test_get_traceparent_fields_unsampled(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-00" version, trace_id, parent_id, sampled_flag = self.tp.get_traceparent_fields(traceparent) - self.assertEqual(trace_id, 11803532876627986230) + self.assertEqual(trace_id, header_to_long_id(self.w3cTraceId)) self.assertEqual(parent_id, 67667974448284343) self.assertFalse(sampled_flag) def test_get_traceparent_fields_newer_version(self): # Although the incoming traceparent header sports a newer version number, we should still be able to parse the # parts that we understand (and consider it valid). - traceparent = "fe-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-12345-abcd" + traceparent = f"fe-{self.w3cTraceId}-00f067aa0ba902b7-01-12345-abcd" version, trace_id, parent_id, sampled_flag = self.tp.get_traceparent_fields(traceparent) - self.assertEqual(trace_id, 11803532876627986230) + self.assertEqual(trace_id, header_to_long_id(self.w3cTraceId)) self.assertEqual(parent_id, 67667974448284343) self.assertTrue(sampled_flag) def test_get_traceparent_fields_unknown_flags(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-ff" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-ff" version, trace_id, parent_id, sampled_flag = self.tp.get_traceparent_fields(traceparent) - self.assertEqual(trace_id, 11803532876627986230) + self.assertEqual(trace_id, header_to_long_id(self.w3cTraceId)) self.assertEqual(parent_id, 67667974448284343) self.assertTrue(sampled_flag) @@ -80,20 +80,18 @@ def test_get_traceparent_fields_string_input_no_dash(self): self.assertIsNone(parent_id) self.assertFalse(sampled_flag) - @pytest.mark.skip("Handled when type of trace and span ids are modified to str") def test_update_traceparent(self): - traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" + traceparent = f"00-{self.w3cTraceId}-00f067aa0ba902b7-01" in_trace_id = "1234d0e0e4736234" in_span_id = "1234567890abcdef" level = 1 expected_traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-1234567890abcdef-01" - self.assertEqual(expected_traceparent, self.tp.update_traceparent(traceparent, in_trace_id, in_span_id, level)) + self.assertEqual(expected_traceparent, self.tp.update_traceparent(traceparent, in_trace_id, header_to_id(in_span_id), level)) - @pytest.mark.skip("Handled when type of trace and span ids are modified to str") def test_update_traceparent_None(self): traceparent = None in_trace_id = "1234d0e0e4736234" in_span_id = "7890abcdef" level = 0 expected_traceparent = "00-00000000000000001234d0e0e4736234-0000007890abcdef-00" - self.assertEqual(expected_traceparent, self.tp.update_traceparent(traceparent, in_trace_id, in_span_id, level)) + self.assertEqual(expected_traceparent, self.tp.update_traceparent(traceparent, in_trace_id, header_to_id(in_span_id), level)) diff --git a/tests_aws/01_lambda/test_lambda.py b/tests_aws/01_lambda/test_lambda.py index b32e1295..961bea1a 100644 --- a/tests_aws/01_lambda/test_lambda.py +++ b/tests_aws/01_lambda/test_lambda.py @@ -221,9 +221,9 @@ def test_custom_service_name(self, trace_id: int, span_id: int) -> None: span = payload["spans"].pop() assert span.n == "aws.lambda.entry" - assert span.t == hex(trace_id)[2:] + assert span.t == hex_id(trace_id) assert span.s - assert span.p == hex(span_id)[2:] + assert span.p == hex_id(span_id) assert span.ts server_timing_value = f"intid;desc={hex_id(trace_id)}" @@ -293,9 +293,9 @@ def test_api_gateway_trigger_tracing(self, trace_id: int, span_id: int) -> None: span = payload["spans"].pop() assert span.n == "aws.lambda.entry" - assert span.t == hex(trace_id)[2:] + assert span.t == hex_id(trace_id) assert span.s - assert span.p == hex(span_id)[2:] + assert span.p == hex_id(span_id) assert span.ts server_timing_value = f"intid;desc={hex_id(trace_id)}" @@ -405,9 +405,9 @@ def test_application_lb_trigger_tracing(self, trace_id: int, span_id: int) -> No span = payload["spans"].pop() assert span.n == "aws.lambda.entry" - assert span.t == hex(trace_id)[2:] + assert span.t == hex_id(trace_id) assert span.s - assert span.p == hex(span_id)[2:] + assert span.p == hex_id(span_id) assert span.ts server_timing_value = f"intid;desc={hex_id(trace_id)}" @@ -803,9 +803,9 @@ 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(int("0000000000001234"))[2:].zfill(16) + assert span.t == hex_id("0000000000001234") assert span.s - assert span.p == hex(int("0000000000004567"))[2:].zfill(16) + assert span.p == hex_id("0000000000004567") assert span.ts server_timing_value = f"intid;desc={hex_id(int('0000000000001234'))}"