Skip to content

Commit 325fb15

Browse files
committed
Add inject/extract interfaces calling the proper propagator
1 parent 6496a09 commit 325fb15

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

instana/tracer.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import time
22
from basictracer import BasicTracer
33
import instana.recorder as r
4-
import opentracing
4+
import opentracing as ot
55
import instana.options as o
66
import instana.sensor as s
7-
import instana.log as ilog
7+
import instana.propagator as tp
88

99
from basictracer.context import SpanContext
1010
from basictracer.span import BasicSpan
@@ -29,6 +29,8 @@ def __init__(self, options=o.Options()):
2929
super(InstanaTracer, self).__init__(
3030
r.InstanaRecorder(self.sensor), r.InstanaSampler())
3131

32+
self._propagators[ot.Format.HTTP_HEADERS] = tp.HTTPPropagator()
33+
3234
def start_span(
3335
self,
3436
operation_name=None,
@@ -44,7 +46,7 @@ def start_span(
4446
parent_ctx = None
4547
if child_of is not None:
4648
parent_ctx = (
47-
child_of if isinstance(child_of, opentracing.SpanContext)
49+
child_of if isinstance(child_of, ot.SpanContext)
4850
else child_of.context)
4951
elif references is not None and len(references) > 0:
5052
# TODO only the first reference is currently used
@@ -71,6 +73,18 @@ def start_span(
7173
tags=tags,
7274
start_time=start_time)
7375

76+
def inject(self, span_context, format, carrier):
77+
if format in self._propagators:
78+
self._propagators[format].inject(span_context, carrier)
79+
else:
80+
raise ot.UnsupportedFormatException()
81+
82+
def extract(self, format, carrier):
83+
if format in self._propagators:
84+
return self._propagators[format].extract(carrier)
85+
else:
86+
raise ot.UnsupportedFormatException()
87+
7488

7589
def init(options):
76-
opentracing.tracer = InstanaTracer(options)
90+
ot.tracer = InstanaTracer(options)

0 commit comments

Comments
 (0)