Skip to content

Commit 30af68f

Browse files
committed
refactor(tests): Adapt SDK spans to use the kind parameter
Signed-off-by: Varsha GS <varsha.gs@ibm.com>
1 parent a58982c commit 30af68f

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

tests/apps/app_django.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,16 @@ def not_found(request):
112112

113113
def complex(request):
114114
tracer = get_tracer()
115-
with tracer.start_as_current_span("asteroid") as pspan:
115+
with tracer.start_as_current_span("asteroid", kind=SpanKind.CLIENT) as pspan:
116116
pspan.set_attribute("component", "Python simple example app")
117-
pspan.set_attribute("span.kind", SpanKind.CLIENT)
118117
pspan.set_attribute("peer.hostname", "localhost")
119118
pspan.set_attribute(SpanAttributes.HTTP_URL, "/python/simple/one")
120119
pspan.set_attribute(SpanAttributes.HTTP_METHOD, "GET")
121120
pspan.set_attribute(SpanAttributes.HTTP_STATUS_CODE, 200)
122121
pspan.add_event(name="complex_request", attributes={"foo": "bar"})
123122
time.sleep(0.2)
124123

125-
with tracer.start_as_current_span("spacedust") as cspan:
126-
cspan.set_attribute("span.kind", SpanKind.CLIENT)
124+
with tracer.start_as_current_span("spacedust", kind=SpanKind.CLIENT) as cspan:
127125
cspan.set_attribute("peer.hostname", "localhost")
128126
cspan.set_attribute(SpanAttributes.HTTP_URL, "/python/simple/two")
129127
cspan.set_attribute(SpanAttributes.HTTP_METHOD, "POST")

tests/span/test_span_sdk.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# (c) Copyright IBM Corp. 2024
22

33
from typing import Generator, Tuple
4-
54
import pytest
5+
from opentelemetry.trace import SpanKind
66

77
from instana.recorder import StanRecorder
88
from instana.span.sdk_span import SDKSpan
@@ -24,12 +24,11 @@ def test_sdkspan(
2424
span_name = "test-sdk-span"
2525
service_name = "test-sdk"
2626
attributes = {
27-
"span.kind": "entry",
2827
"arguments": "--quiet",
2928
"return": "True",
3029
}
3130
self.span = InstanaSpan(
32-
span_name, span_context, span_processor, attributes=attributes
31+
span_name, span_context, span_processor, attributes=attributes, kind=SpanKind.SERVER
3332
)
3433
sdk_span = SDKSpan(self.span, None, service_name)
3534

@@ -40,9 +39,9 @@ def test_sdkspan(
4039
"service": service_name,
4140
"sdk": {
4241
"name": span_name,
43-
"type": attributes["span.kind"],
42+
"type": "entry",
4443
"custom": {
45-
"attributes": attributes,
44+
"tags": attributes,
4645
},
4746
"arguments": attributes["arguments"],
4847
"return": attributes["return"],
@@ -66,12 +65,15 @@ def test_sdkspan(
6665
"span_kind, expected_result",
6766
[
6867
(None, ("intermediate", 3)),
68+
(SpanKind.INTERNAL, ("intermediate", 3)),
6969
("entry", ("entry", 1)),
7070
("server", ("entry", 1)),
7171
("consumer", ("entry", 1)),
72+
(SpanKind.SERVER, ("entry", 1)),
7273
("exit", ("exit", 2)),
7374
("client", ("exit", 2)),
7475
("producer", ("exit", 2)),
76+
(SpanKind.CLIENT, ("exit", 2)),
7577
],
7678
)
7779
def test_sdkspan_get_span_kind(
@@ -81,19 +83,16 @@ def test_sdkspan_get_span_kind(
8183
span_kind: str,
8284
expected_result: Tuple[str, int],
8385
) -> None:
84-
attributes = {
85-
"span.kind": span_kind,
86-
}
8786
self.span = InstanaSpan(
88-
"test-sdk-span", span_context, span_processor, attributes=attributes
87+
"test-sdk-span", span_context, span_processor, kind=span_kind
8988
)
9089
sdk_span = SDKSpan(self.span, None, "test")
9190

9291
kind = sdk_span.get_span_kind(self.span)
9392

9493
assert expected_result == kind
9594

96-
def test_sdkspan_get_span_kind_with_no_attributes(
95+
def test_sdkspan_get_span_kind_default(
9796
self,
9897
span: InstanaSpan,
9998
) -> None:

0 commit comments

Comments
 (0)