Skip to content

Commit d57ae8d

Browse files
committed
Add django as registered span; break out span.kind handling
1 parent 355d21a commit d57ae8d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

instana/recorder.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class InstanaRecorder(SpanRecorder):
1212
sensor = None
13-
registered_spans = ("memcache", "rpc-client", "rpc-server")
13+
registered_spans = ("django", "memcache", "rpc-client", "rpc-server")
1414
entry_kind = ["entry", "server", "consumer"]
1515
exit_kind = ["exit", "client", "producer"]
1616
queue = Queue.Queue()
@@ -72,21 +72,20 @@ def record_span(self, span):
7272

7373
def build_registered_span(self, span):
7474
""" Takes a BasicSpan and converts it into a registered InstanaSpan """
75-
data = sd.Data(service=self.get_service_name(span),
76-
http=sd.HttpData(host=self.get_host_name(span),
75+
data = sd.Data(http=sd.HttpData(host=self.get_host_name(span),
7776
url=self.get_string_tag(span, ext.HTTP_URL),
7877
method=self.get_string_tag(span, ext.HTTP_METHOD),
7978
status=self.get_tag(span, ext.HTTP_STATUS_CODE)),
8079
baggage=span.context.baggage,
8180
custom=sd.CustomData(tags=span.tags,
8281
logs=self.collect_logs(span)))
8382
return sd.InstanaSpan(
83+
n=span.operation_name,
8484
t=span.context.trace_id,
8585
p=span.parent_id,
8686
s=span.context.span_id,
8787
ts=int(round(span.start_time * 1000)),
8888
d=int(round(span.duration * 1000)),
89-
n=self.get_http_type(span),
9089
f=self.sensor.agent.from_,
9190
data=data)
9291

@@ -102,13 +101,7 @@ def build_sdk_span(self, span):
102101
custom=custom_data
103102
)
104103

105-
if "span.kind" in span.tags:
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"
104+
sdk_data.Type = self.get_span_kind(span)
112105

113106
data = sd.Data(service=self.get_service_name(span),
114107
sdk=sdk_data)
@@ -137,7 +130,7 @@ def get_string_tag(self, span, tag):
137130
return ret
138131

139132
def get_host_name(self, span):
140-
h = self.get_string_tag(span, ext.PEER_HOSTNAME)
133+
h = self.get_string_tag(span, "http.host")
141134
if len(h) > 0:
142135
return h
143136

@@ -158,12 +151,16 @@ def get_service_name(self, span):
158151

159152
return self.sensor.service_name
160153

161-
def get_http_type(self, span):
162-
k = self.get_string_tag(span, ext.SPAN_KIND)
163-
if k == ext.SPAN_KIND_RPC_CLIENT:
164-
return http.HTTP_CLIENT
165-
166-
return http.HTTP_SERVER
154+
def get_span_kind(self, span):
155+
kind = ""
156+
if "span.kind" in span.tags:
157+
if span.tags["span.kind"] in self.entry_kind:
158+
kind = "entry"
159+
elif span.tags["span.kind"] in self.exit_kind:
160+
kind = "exit"
161+
else:
162+
kind = "local"
163+
return kind
167164

168165
def collect_logs(self, span):
169166
logs = {}

0 commit comments

Comments
 (0)