Skip to content
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
14 changes: 6 additions & 8 deletions src/instana/span/sdk_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


6 changes: 2 additions & 4 deletions tests/apps/app_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,16 @@ 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")
pspan.set_attribute(SpanAttributes.HTTP_STATUS_CODE, 200)
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")
Expand Down
19 changes: 9 additions & 10 deletions tests/span/test_span_sdk.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand All @@ -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"],
Expand All @@ -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(
Expand All @@ -81,19 +83,16 @@ 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")

kind = sdk_span.get_span_kind(self.span)

assert expected_result == kind

def test_sdkspan_get_span_kind_with_no_attributes(
def test_sdkspan_get_span_kind_default(
self,
span: InstanaSpan,
) -> None:
Expand Down
Loading