From 4fa6d047b028d3255057f681205c485d39ba2206 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:15:49 +0530 Subject: [PATCH 1/9] fix(tracestate, traceparent): with_suppression_and_w3c Signed-off-by: Varsha GS --- src/instana/tracer.py | 2 +- src/instana/w3c_trace_context/traceparent.py | 4 ++-- tests/frameworks/test_flask.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/instana/tracer.py b/src/instana/tracer.py index a5bdf895..3fbe4741 100644 --- a/src/instana/tracer.py +++ b/src/instana/tracer.py @@ -230,6 +230,7 @@ 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), + tracestate=(parent_context.tracestate if parent_context else None) ) if parent_context is not None: @@ -239,7 +240,6 @@ def _create_span_context(self, parent_context: SpanContext) -> SpanContext: 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 diff --git a/src/instana/w3c_trace_context/traceparent.py b/src/instana/w3c_trace_context/traceparent.py index edfd7066..1435a2cf 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 diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py index 6c41bf82..34a0b0e3 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: + """https://github.ibm.com/instana/technical-documentation/tree/master/tracing/specification#incoming-level-0-plus-w3c-trace-context-specification-headers""" headers = { 'X-INSTANA-L':'0', 'traceparent': '00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01', @@ -224,6 +224,7 @@ def test_get_request_with_suppression_and_w3c(self) -> None: assert response.headers.get("X-INSTANA-L", None) == "0" 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 From bd714436fc1e7476b1c53e87b76e136bfb575573 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:19:00 +0530 Subject: [PATCH 2/9] fix: Test Case 28 of integration tests Signed-off-by: Varsha GS --- src/instana/propagators/base_propagator.py | 6 ++-- src/instana/util/ids.py | 37 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index 7286cce4..9428f062 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, header_to_32, header_to_16 from instana.w3c_trace_context.traceparent import Traceparent from instana.w3c_trace_context.tracestate import Tracestate @@ -242,8 +242,8 @@ def __determine_span_context( ctx_tracestate = tracestate 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=header_to_32(ctx_trace_id) if ctx_trace_id else INVALID_TRACE_ID, + span_id=header_to_16(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/util/ids.py b/src/instana/util/ids.py index afeb9805..c337369f 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: @@ -103,3 +103,34 @@ def hex_id(id: Union[int, str]) -> str: 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)}" + + +def header_to_32(header): + if isinstance(header, int): + return header + + try: + if len(header) < 16: + # Left pad ID with zeros + header = header.zfill(16) + + return int(header, 16) + except ValueError: + return INVALID_TRACE_ID + +def header_to_16(header): + if isinstance(header, int): + return header + + try: + length = len(header) + if length < 16: + # Left pad ID with zeros + header = header.zfill(16) + elif length > 16: + # Phase 0: Discard everything but the last 16byte + header = header[-16:] + + return int(header, 16) + except ValueError: + return INVALID_SPAN_ID \ No newline at end of file From e7d7a1c9f628e3d41eea85f04a0c9ef260d74e95 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:20:30 +0530 Subject: [PATCH 3/9] fix: server timing, x-instana-t Signed-off-by: Varsha GS --- src/instana/propagators/http_propagator.py | 4 ++-- src/instana/util/ids.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/instana/propagators/http_propagator.py b/src/instana/propagators/http_propagator.py index cd615b62..3017e925 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_16 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_16(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/util/ids.py b/src/instana/util/ids.py index c337369f..e3dbce17 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -99,10 +99,24 @@ def hex_id(id: Union[int, str]) -> str: hex_id = hex_id.zfill(16) return hex_id +def hex_id_16(id: Union[int, str]) -> str: + """ + Returns the hexadecimal representation of the given ID. + """ + + hex_id = hex(int(id))[2:] + length = len(hex_id) + if length < 16: + 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 + 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_16(trace_id)}" def header_to_32(header): From a22747c8f0d454d1ce49580554fd66b3ae6e4894 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:24:16 +0530 Subject: [PATCH 4/9] fix span context entries - SpanContext uses a Tuple hence cannot be modified after creation Signed-off-by: Varsha GS --- src/instana/propagators/base_propagator.py | 4 ++-- src/instana/tracer.py | 16 +++++++--------- tests/frameworks/test_flask.py | 4 ++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index 9428f062..d3b12e6b 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, header_to_32, header_to_16 +from instana.util.ids import header_to_id, header_to_long_id, hex_id, header_to_32, header_to_16, hex_id_16 from instana.w3c_trace_context.traceparent import Traceparent from instana.w3c_trace_context.tracestate import Tracestate @@ -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_16(tp_trace_id) ctx_span_id = tp_parent_id ctx_synthetic = synthetic ctx_trace_parent = True diff --git a/src/instana/tracer.py b/src/instana/tracer.py index 3fbe4741..9bc214c9 100644 --- a/src/instana/tracer.py +++ b/src/instana/tracer.py @@ -230,17 +230,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), - tracestate=(parent_context.tracestate if parent_context else None) + 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 - return span_context def inject( diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py index 34a0b0e3..b040abf8 100644 --- a/tests/frameworks/test_flask.py +++ b/tests/frameworks/test_flask.py @@ -223,6 +223,10 @@ 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" From 559f47e66cffd01c2b95ec78f4a4745ea447efc1 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:25:27 +0530 Subject: [PATCH 5/9] fix: handle Instana headers with 128 bit trace ID Signed-off-by: Varsha GS --- src/instana/propagators/base_propagator.py | 2 +- src/instana/span/base_span.py | 3 ++- src/instana/util/ids.py | 6 ++++-- src/instana/w3c_trace_context/traceparent.py | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index d3b12e6b..8ff9e59c 100644 --- a/src/instana/propagators/base_propagator.py +++ b/src/instana/propagators/base_propagator.py @@ -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_16(span_context.trace_id), hex_id(span_context.span_id)) return traceparent, tracestate def __determine_span_context( diff --git a/src/instana/span/base_span.py b/src/instana/span/base_span.py index fbdb4c42..ee14c040 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.util.ids import hex_id_16, header_to_32 if TYPE_CHECKING: from opentelemetry.trace import Span @@ -21,7 +22,7 @@ def __repr__(self) -> str: def __init__(self, span: Type["Span"], source, **kwargs) -> None: # pylint: disable=invalid-name - self.t = span.context.trace_id + self.t = header_to_32(hex_id_16(span.context.trace_id)) self.p = span.parent_id self.s = span.context.span_id self.ts = round(span.start_time / 10**6) diff --git a/src/instana/util/ids.py b/src/instana/util/ids.py index e3dbce17..f65b765d 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -97,6 +97,8 @@ def hex_id(id: Union[int, str]) -> str: hex_id = hex(int(id))[2:] if len(hex_id) < 16: hex_id = hex_id.zfill(16) + elif len(hex_id) > 16 and len(hex_id) < 32: + hex_id = hex_id.zfill(32) return hex_id def hex_id_16(id: Union[int, str]) -> str: @@ -119,7 +121,7 @@ def define_server_timing(trace_id: Union[int, str]) -> str: return f"intid;desc={hex_id_16(trace_id)}" -def header_to_32(header): +def header_to_32(header) -> int: if isinstance(header, int): return header @@ -132,7 +134,7 @@ def header_to_32(header): except ValueError: return INVALID_TRACE_ID -def header_to_16(header): +def header_to_16(header) -> int: if isinstance(header, int): return header diff --git a/src/instana/w3c_trace_context/traceparent.py b/src/instana/w3c_trace_context/traceparent.py index 1435a2cf..315bdd30 100644 --- a/src/instana/w3c_trace_context/traceparent.py +++ b/src/instana/w3c_trace_context/traceparent.py @@ -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 From 022c8595c15a3a3f64c33a69eee1078f83ac96b5 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:30:23 +0530 Subject: [PATCH 6/9] fix: format `span.lt` before sending to agent - `span_context.traceid` logic try - fix: receive `span.crid` and `span.crtp` on non-recording spans as well Signed-off-by: Varsha GS --- src/instana/collector/utils.py | 3 +++ src/instana/propagators/base_propagator.py | 4 +++- src/instana/tracer.py | 4 ---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/instana/collector/utils.py b/src/instana/collector/utils.py index 7292cca4..ffe62c7d 100644 --- a/src/instana/collector/utils.py +++ b/src/instana/collector/utils.py @@ -5,6 +5,8 @@ from opentelemetry.trace.span import format_span_id from opentelemetry.trace import SpanKind +from instana.util.ids import hex_id, header_to_32 + if TYPE_CHECKING: from instana.span.base_span import BaseSpan @@ -22,6 +24,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(header_to_32(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 8ff9e59c..b88e93d1 100644 --- a/src/instana/propagators/base_propagator.py +++ b/src/instana/propagators/base_propagator.py @@ -242,7 +242,9 @@ def __determine_span_context( ctx_tracestate = tracestate return SpanContext( - trace_id=header_to_32(ctx_trace_id) if ctx_trace_id else INVALID_TRACE_ID, + # 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=header_to_32(hex_id_16(header_to_32(ctx_trace_id))) if ctx_trace_id else INVALID_TRACE_ID, span_id=header_to_16(ctx_span_id) if ctx_span_id else INVALID_SPAN_ID, is_remote=False, level=ctx_level, diff --git a/src/instana/tracer.py b/src/instana/tracer.py index 9bc214c9..9f0c7449 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, From 7e7a85d01f6693e2747e271da7f2fa545f9efc32 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:31:42 +0530 Subject: [PATCH 7/9] fix: synthetic - set `span.sy` only for entry spans when `synthetic=True` Signed-off-by: Varsha GS --- src/instana/span/base_span.py | 3 ++- src/instana/tracer.py | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/instana/span/base_span.py b/src/instana/span/base_span.py index ee14c040..a91679c9 100644 --- a/src/instana/span/base_span.py +++ b/src/instana/span/base_span.py @@ -6,6 +6,7 @@ from instana.log import logger from instana.util import DictionaryOfStan from instana.util.ids import hex_id_16, header_to_32 +from instana.span.kind import ENTRY_SPANS if TYPE_CHECKING: from opentelemetry.trace import Span @@ -32,7 +33,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 9f0c7449..28876070 100644 --- a/src/instana/tracer.py +++ b/src/instana/tracer.py @@ -134,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) From 0ee29063bd2bc0712e60b902593d33e0231560af Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 16 Oct 2024 20:46:57 +0530 Subject: [PATCH 8/9] fix: aws/01_lambda failures - fix: handle `str` internal ids with all digit chars - rename the methods to handle internal ids Signed-off-by: Varsha GS --- src/instana/collector/utils.py | 4 +- .../instrumentation/aws/lambda_inst.py | 3 +- src/instana/propagators/base_propagator.py | 24 ++++-- src/instana/propagators/http_propagator.py | 4 +- src/instana/span/base_span.py | 3 +- src/instana/util/ids.py | 77 ++++++++++++------- tests/propagators/test_http_propagator.py | 33 ++++---- tests_aws/01_lambda/test_lambda.py | 16 ++-- 8 files changed, 97 insertions(+), 67 deletions(-) diff --git a/src/instana/collector/utils.py b/src/instana/collector/utils.py index ffe62c7d..4c02935c 100644 --- a/src/instana/collector/utils.py +++ b/src/instana/collector/utils.py @@ -5,7 +5,7 @@ from opentelemetry.trace.span import format_span_id from opentelemetry.trace import SpanKind -from instana.util.ids import hex_id, header_to_32 +from instana.util.ids import hex_id, internal_id if TYPE_CHECKING: from instana.span.base_span import BaseSpan @@ -24,7 +24,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(header_to_32(span.lt)) if hasattr(span, "lt") else None + span.lt = hex_id(internal_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/instrumentation/aws/lambda_inst.py b/src/instana/instrumentation/aws/lambda_inst.py index 1dc5c959..c57dce0b 100644 --- a/src/instana/instrumentation/aws/lambda_inst.py +++ b/src/instana/instrumentation/aws/lambda_inst.py @@ -11,6 +11,7 @@ import wrapt from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.trace.span import format_span_id from instana import get_aws_lambda_handler from instana.instrumentation.aws.triggers import enrich_lambda_span, get_context @@ -44,7 +45,7 @@ def lambda_handler_with_instana( result = wrapped(*args, **kwargs) if isinstance(result, dict): - server_timing_value = define_server_timing(span.context.trace_id) + server_timing_value = define_server_timing(format_span_id(span.context.trace_id)) if "headers" in result: result["headers"]["Server-Timing"] = server_timing_value elif "multiValueHeaders" in result: diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index b88e93d1..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, header_to_32, header_to_16, hex_id_16 +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_16(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 = hex_id_16(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,11 +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=header_to_32(hex_id_16(header_to_32(ctx_trace_id))) if ctx_trace_id else INVALID_TRACE_ID, - span_id=header_to_16(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 3017e925..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, hex_id_16 +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, hex_id_16(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 a91679c9..0d8491c2 100644 --- a/src/instana/span/base_span.py +++ b/src/instana/span/base_span.py @@ -5,7 +5,6 @@ from instana.log import logger from instana.util import DictionaryOfStan -from instana.util.ids import hex_id_16, header_to_32 from instana.span.kind import ENTRY_SPANS if TYPE_CHECKING: @@ -23,7 +22,7 @@ def __repr__(self) -> str: def __init__(self, span: Type["Span"], source, **kwargs) -> None: # pylint: disable=invalid-name - self.t = header_to_32(hex_id_16(span.context.trace_id)) + self.t = span.context.trace_id self.p = span.parent_id self.s = span.context.span_id self.ts = round(span.start_time / 10**6) diff --git a/src/instana/util/ids.py b/src/instana/util/ids.py index f65b765d..af1c59ea 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -92,61 +92,82 @@ 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: + length = len(hex_id) + # Left pad ID with zeros + if length < 16: hex_id = hex_id.zfill(16) - elif len(hex_id) > 16 and len(hex_id) < 32: + elif length > 16 and length < 32: hex_id = hex_id.zfill(32) return hex_id -def hex_id_16(id: Union[int, str]) -> str: +def hex_id_limited(id: Union[int, str]) -> str: """ Returns the hexadecimal representation of the given ID. + Limit longer IDs to 16 characters """ - - hex_id = hex(int(id))[2:] - length = len(hex_id) - if length < 16: - 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 - + 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: # 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_16(trace_id)}" + return f"intid;desc={hex_id_limited(trace_id)}" -def header_to_32(header) -> int: - if isinstance(header, int): - return header +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(header) < 16: + if len(id) < 16: # Left pad ID with zeros - header = header.zfill(16) + id = id.zfill(16) - return int(header, 16) + # hex string -> int + return int(id, 16) except ValueError: return INVALID_TRACE_ID -def header_to_16(header) -> int: - if isinstance(header, int): - return header +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(header) + length = len(id) if length < 16: # Left pad ID with zeros - header = header.zfill(16) + id = id.zfill(16) elif length > 16: # Phase 0: Discard everything but the last 16byte - header = header[-16:] + id = id[-16:] - return int(header, 16) + # hex string -> int + return int(id, 16) except ValueError: - return INVALID_SPAN_ID \ No newline at end of file + return INVALID_SPAN_ID diff --git a/tests/propagators/test_http_propagator.py b/tests/propagators/test_http_propagator.py index ae4af3b6..b7ee864b 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,8 +91,8 @@ 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, @@ -106,8 +105,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 +117,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 +198,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 +208,16 @@ 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: 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 +228,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 +303,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_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'))}" From 6338ef6e2aa4f1ce26cb3ed80c4c0bfe0721bf81 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Thu, 17 Oct 2024 17:06:42 +0530 Subject: [PATCH 9/9] fix(tests): failing tests after changes Signed-off-by: Varsha GS --- src/instana/collector/utils.py | 5 ++- .../instrumentation/aws/lambda_inst.py | 3 +- src/instana/util/ids.py | 22 ++++++------ tests/frameworks/test_flask.py | 2 +- tests/propagators/test_http_propagator.py | 2 ++ tests/span/test_base_span.py | 6 ++-- tests/w3c_trace_context/test_traceparent.py | 36 +++++++++---------- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/instana/collector/utils.py b/src/instana/collector/utils.py index 4c02935c..1da5892b 100644 --- a/src/instana/collector/utils.py +++ b/src/instana/collector/utils.py @@ -5,8 +5,7 @@ from opentelemetry.trace.span import format_span_id from opentelemetry.trace import SpanKind -from instana.util.ids import hex_id, internal_id - +from instana.util.ids import hex_id if TYPE_CHECKING: from instana.span.base_span import BaseSpan @@ -24,7 +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(internal_id(span.lt)) if hasattr(span, "lt") 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/instrumentation/aws/lambda_inst.py b/src/instana/instrumentation/aws/lambda_inst.py index c57dce0b..1dc5c959 100644 --- a/src/instana/instrumentation/aws/lambda_inst.py +++ b/src/instana/instrumentation/aws/lambda_inst.py @@ -11,7 +11,6 @@ import wrapt from opentelemetry.semconv.trace import SpanAttributes -from opentelemetry.trace.span import format_span_id from instana import get_aws_lambda_handler from instana.instrumentation.aws.triggers import enrich_lambda_span, get_context @@ -45,7 +44,7 @@ def lambda_handler_with_instana( result = wrapped(*args, **kwargs) if isinstance(result, dict): - server_timing_value = define_server_timing(format_span_id(span.context.trace_id)) + server_timing_value = define_server_timing(span.context.trace_id) if "headers" in result: result["headers"]["Server-Timing"] = server_timing_value elif "multiValueHeaders" in result: diff --git a/src/instana/util/ids.py b/src/instana/util/ids.py index af1c59ea..391b6f80 100644 --- a/src/instana/util/ids.py +++ b/src/instana/util/ids.py @@ -94,15 +94,17 @@ 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:] - 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 + 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: """ @@ -119,7 +121,7 @@ def hex_id_limited(id: Union[int, str]) -> str: # Phase 0: Discard everything but the last 16byte hex_id = hex_id[-16:] return hex_id - except ValueError: # ValueError: invalid literal for int() with base 10: + except ValueError: # Handles ValueError: invalid literal for int() with base 10: return id def define_server_timing(trace_id: Union[int, str]) -> str: diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py index b040abf8..876fd2ba 100644 --- a/tests/frameworks/test_flask.py +++ b/tests/frameworks/test_flask.py @@ -212,7 +212,7 @@ def test_get_request_with_suppression(self) -> None: assert spans == [] def test_get_request_with_suppression_and_w3c(self) -> None: - """https://github.ibm.com/instana/technical-documentation/tree/master/tracing/specification#incoming-level-0-plus-w3c-trace-context-specification-headers""" + """Incoming Level 0 Plus W3C Trace Context Specification Headers""" headers = { 'X-INSTANA-L':'0', 'traceparent': '00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01', diff --git a/tests/propagators/test_http_propagator.py b/tests/propagators/test_http_propagator.py index b7ee864b..25b36635 100644 --- a/tests/propagators/test_http_propagator.py +++ b/tests/propagators/test_http_propagator.py @@ -98,6 +98,7 @@ def test_extract_carrier_list( _traceparent: str, _tracestate: str, ) -> None: + _trace_id = str(_trace_id) carrier = [ ("user-agent", "python-requests/2.23.0"), ("accept-encoding", "gzip, deflate"), @@ -213,6 +214,7 @@ def test_extract_carrier_dict_level_header_not_splitable( _traceparent: str, _tracestate: str, ) -> None: + _trace_id = str(_trace_id) carrier = { "traceparent": _traceparent, "tracestate": _tracestate, 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))