From ff8ed27d20319206dffa1852fe5b846fcdf16c97 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 1 Apr 2026 17:59:26 +0530 Subject: [PATCH 1/2] refactor(sdk_span): Adapt `SDK` spans to use the `kind` parameter Signed-off-by: Varsha GS --- src/instana/span/sdk_span.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/instana/span/sdk_span.py b/src/instana/span/sdk_span.py index 9a4be35b..ec5a81c4 100644 --- a/src/instana/span/sdk_span.py +++ b/src/instana/span/sdk_span.py @@ -51,12 +51,10 @@ def get_span_kind(self, span) -> Tuple[str, int]: :param span: The span to search for the `span.kind` attribute :return: Tuple (String, Int) """ - kind = ("intermediate", 3) - if "span.kind" in span.attributes: - if span.attributes["span.kind"] in ENTRY_KIND: - kind = ("entry", 1) - elif span.attributes["span.kind"] in EXIT_KIND: - kind = ("exit", 2) + if span.kind in ENTRY_KIND: + kind = ("entry", 1) + elif span.kind in EXIT_KIND: + kind = ("exit", 2) + else: + kind = ("intermediate", 3) return kind - - From b44de6e05314c39a68a0b61be0b70f324246e571 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Wed, 1 Apr 2026 18:00:07 +0530 Subject: [PATCH 2/2] refactor(tests): Adapt `SDK` spans to use the `kind` parameter Signed-off-by: Varsha GS --- tests/apps/app_django.py | 6 ++---- tests/span/test_span_sdk.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/apps/app_django.py b/tests/apps/app_django.py index 545abc96..635d4e52 100755 --- a/tests/apps/app_django.py +++ b/tests/apps/app_django.py @@ -112,9 +112,8 @@ def not_found(request): def complex(request): tracer = get_tracer() - with tracer.start_as_current_span("asteroid") as pspan: + with tracer.start_as_current_span("asteroid", kind=SpanKind.CLIENT) as pspan: pspan.set_attribute("component", "Python simple example app") - pspan.set_attribute("span.kind", SpanKind.CLIENT) pspan.set_attribute("peer.hostname", "localhost") pspan.set_attribute(SpanAttributes.HTTP_URL, "/python/simple/one") pspan.set_attribute(SpanAttributes.HTTP_METHOD, "GET") @@ -122,8 +121,7 @@ def complex(request): pspan.add_event(name="complex_request", attributes={"foo": "bar"}) time.sleep(0.2) - with tracer.start_as_current_span("spacedust") as cspan: - cspan.set_attribute("span.kind", SpanKind.CLIENT) + with tracer.start_as_current_span("spacedust", kind=SpanKind.CLIENT) as cspan: cspan.set_attribute("peer.hostname", "localhost") cspan.set_attribute(SpanAttributes.HTTP_URL, "/python/simple/two") cspan.set_attribute(SpanAttributes.HTTP_METHOD, "POST") diff --git a/tests/span/test_span_sdk.py b/tests/span/test_span_sdk.py index 5256f7fb..c922d856 100644 --- a/tests/span/test_span_sdk.py +++ b/tests/span/test_span_sdk.py @@ -1,8 +1,8 @@ # (c) Copyright IBM Corp. 2024 from typing import Generator, Tuple - import pytest +from opentelemetry.trace import SpanKind from instana.recorder import StanRecorder from instana.span.sdk_span import SDKSpan @@ -24,12 +24,11 @@ def test_sdkspan( span_name = "test-sdk-span" service_name = "test-sdk" attributes = { - "span.kind": "entry", "arguments": "--quiet", "return": "True", } self.span = InstanaSpan( - span_name, span_context, span_processor, attributes=attributes + span_name, span_context, span_processor, attributes=attributes, kind=SpanKind.SERVER ) sdk_span = SDKSpan(self.span, None, service_name) @@ -40,9 +39,9 @@ def test_sdkspan( "service": service_name, "sdk": { "name": span_name, - "type": attributes["span.kind"], + "type": "entry", "custom": { - "attributes": attributes, + "tags": attributes, }, "arguments": attributes["arguments"], "return": attributes["return"], @@ -66,12 +65,15 @@ def test_sdkspan( "span_kind, expected_result", [ (None, ("intermediate", 3)), + (SpanKind.INTERNAL, ("intermediate", 3)), ("entry", ("entry", 1)), ("server", ("entry", 1)), ("consumer", ("entry", 1)), + (SpanKind.SERVER, ("entry", 1)), ("exit", ("exit", 2)), ("client", ("exit", 2)), ("producer", ("exit", 2)), + (SpanKind.CLIENT, ("exit", 2)), ], ) def test_sdkspan_get_span_kind( @@ -81,11 +83,8 @@ def test_sdkspan_get_span_kind( span_kind: str, expected_result: Tuple[str, int], ) -> None: - attributes = { - "span.kind": span_kind, - } self.span = InstanaSpan( - "test-sdk-span", span_context, span_processor, attributes=attributes + "test-sdk-span", span_context, span_processor, kind=span_kind ) sdk_span = SDKSpan(self.span, None, "test") @@ -93,7 +92,7 @@ def test_sdkspan_get_span_kind( assert expected_result == kind - def test_sdkspan_get_span_kind_with_no_attributes( + def test_sdkspan_get_span_kind_default( self, span: InstanaSpan, ) -> None: