Skip to content

Commit d5bc33f

Browse files
committed
Expanded span.kind support & tests.
1 parent 5a6e165 commit d5bc33f

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

instana/recorder.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import threading as t
44
import opentracing.ext.tags as ext
55
import socket
6-
import instana.span_data as sd
6+
import instana.span as sd
77
import Queue
88
import time
99

1010

1111
class InstanaRecorder(SpanRecorder):
1212
sensor = None
1313
registered_spans = ("memcache", "rpc-client", "rpc-server")
14+
entry_kind = ["entry", "server", "consumer"]
15+
exit_kind = ["exit", "client", "producer"]
1416
queue = Queue.Queue()
1517

1618
def __init__(self, sensor):
@@ -101,7 +103,13 @@ def build_sdk_span(self, span):
101103
)
102104

103105
if "span.kind" in span.tags:
104-
sdk_data.Type = span.tags["span.kind"]
106+
if span.tags["span.kind"] in self.entry_kind:
107+
sdk_data.Type = "entry"
108+
elif span.tags["span.kind"] in self.exit_kind:
109+
sdk_data.Type = "exit"
110+
else:
111+
sdk_data.Type = "local"
112+
105113

106114
data = sd.Data(service=self.get_service_name(span),
107115
sdk=sdk_data)

tests/test_ot_span.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,44 @@ def test_sdk_spans(self):
8585
assert_equals('entry', sdk_span.data.sdk.Type)
8686
assert sdk_span.data.sdk.Custom
8787
assert sdk_span.data.sdk.Custom.tags
88+
89+
def test_span_kind(self):
90+
recorder = opentracing.global_tracer.recorder
91+
92+
span = opentracing.global_tracer.start_span("custom_sdk_span")
93+
span.set_tag('span.kind', "consumer")
94+
span.finish()
95+
96+
span = opentracing.global_tracer.start_span("custom_sdk_span")
97+
span.set_tag('span.kind', "server")
98+
span.finish()
99+
100+
span = opentracing.global_tracer.start_span("custom_sdk_span")
101+
span.set_tag('span.kind', "producer")
102+
span.finish()
103+
104+
span = opentracing.global_tracer.start_span("custom_sdk_span")
105+
span.set_tag('span.kind', "client")
106+
span.finish()
107+
108+
span = opentracing.global_tracer.start_span("custom_sdk_span")
109+
span.set_tag('span.kind', "blah")
110+
span.finish()
111+
112+
spans = recorder.queued_spans()
113+
assert 5, len(spans)
114+
115+
span = spans[0]
116+
assert_equals('entry', span.data.sdk.Type)
117+
118+
span = spans[1]
119+
assert_equals('entry', span.data.sdk.Type)
120+
121+
span = spans[2]
122+
assert_equals('exit', span.data.sdk.Type)
123+
124+
span = spans[3]
125+
assert_equals('exit', span.data.sdk.Type)
126+
127+
span = spans[4]
128+
assert_equals('local', span.data.sdk.Type)

0 commit comments

Comments
 (0)