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
4 changes: 2 additions & 2 deletions instana/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def start(self, e):

def to_json(self, o):
def extractor(o):
return {k: v for k, v in o.__dict__.items() if v is not None}
return {k.lower(): v for k, v in o.__dict__.items() if v is not None}

try:
return json.dumps(o, default=extractor, sort_keys=False, separators=(',', ':')).encode()
except Exception as e:
except:
logger.debug("to_json", exc_info=True)

def is_timed_out(self):
Expand Down
6 changes: 5 additions & 1 deletion instana/json_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ def __init__(self, **kwds):

class SDKData(object):
name = None

# Since 'type' and 'return' are a Python builtin and a reserved keyword respectively, these keys (all keys) are
# lower-case'd in json encoding. See Agent.to_json
Type = None
arguments = None
Return = None

arguments = None
custom = None

def __init__(self, **kwds):
Expand Down
43 changes: 37 additions & 6 deletions instana/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class InstanaRecorder(SpanRecorder):

entry_kind = ["entry", "server", "consumer"]
exit_kind = ["exit", "client", "producer"]

queue = queue.Queue()

def __init__(self):
Expand Down Expand Up @@ -208,11 +209,16 @@ def build_sdk_span(self, span):
logs=self.collect_logs(span))

sdk_data = SDKData(name=span.operation_name,
custom=custom_data)
custom=custom_data,
Type=self.get_span_kind_as_string(span))

if "arguments" in span.tags:
sdk_data.arguments = span.tags["arguments"]

sdk_data.Type = self.get_span_kind(span)
data = Data(service=instana.singletons.agent.sensor.options.service_name,
sdk=sdk_data)
if "return" in span.tags:
sdk_data.Return = span.tags["return"]

data = Data(service=instana.singletons.agent.sensor.options.service_name, sdk=sdk_data)
entity_from = {'e': instana.singletons.agent.from_.pid,
'h': instana.singletons.agent.from_.agentUuid}

Expand All @@ -222,6 +228,7 @@ def build_sdk_span(self, span):
s=span.context.span_id,
ts=int(round(span.start_time * 1000)),
d=int(round(span.duration * 1000)),
k=self.get_span_kind_as_int(span),
n="sdk",
f=entity_from,
data=data)
Expand All @@ -246,16 +253,40 @@ def get_http_host_name(self, span):

return "localhost"

def get_span_kind(self, span):
kind = ""
def get_span_kind_as_string(self, span):
"""
Will retrieve the `span.kind` tag and return the appropriate string value for the Instana backend or
None if the tag is set to something we don't recognize.

:param span: The span to search for the `span.kind` tag
:return: String
"""
kind = None
if "span.kind" in span.tags:
if span.tags["span.kind"] in self.entry_kind:
kind = "entry"
elif span.tags["span.kind"] in self.exit_kind:
kind = "exit"
else:
kind = "intermediate"
return kind

def get_span_kind_as_int(self, span):
"""
Will retrieve the `span.kind` tag and return the appropriate integer value for the Instana backend or
None if the tag is set to something we don't recognize.

:param span: The span to search for the `span.kind` tag
:return: Integer
"""
kind = None
if "span.kind" in span.tags:
if span.tags["span.kind"] in self.entry_kind:
kind = 1
elif span.tags["span.kind"] in self.exit_kind:
kind = 2
else:
kind = 3
return kind

def collect_logs(self, span):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_ot_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ def test_span_kind(self):

span = spans[4]
assert_equals('intermediate', span.data.sdk.Type)

span = spans[0]
assert_equals(1, span.k)

span = spans[1]
assert_equals(1, span.k)

span = spans[2]
assert_equals(2, span.k)

span = spans[3]
assert_equals(2, span.k)

span = spans[4]
assert_equals(3, span.k)
3 changes: 0 additions & 3 deletions tests/test_ot_tracer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import opentracing
from nose.tools import assert_equals

from instana.singletons import tracer


def test_tracer_basics():
Expand Down