@@ -12,7 +12,8 @@ def __init__(self,
12
12
service_name ,
13
13
recorder ,
14
14
scope_manager = None ,
15
- common_tags = None ):
15
+ common_tags = None ,
16
+ use_shared_spans = False ):
16
17
"""
17
18
Initialize a Haystack Tracer instance.
18
19
:param service_name: The service name to which all spans will belong.
@@ -22,6 +23,9 @@ def __init__(self,
22
23
ThreadLocal scope manager.
23
24
:param common_tags: An optional dictionary of tags which should be
24
25
applied to all created spans for this service
26
+ :param use_shared_spans: A boolean indicating whether or not to use
27
+ shared spans. This is when client/server spans share the same span id.
28
+ Default is to use unique span ids.
25
29
"""
26
30
27
31
scope_manager = ThreadLocalScopeManager () if scope_manager is None \
@@ -31,6 +35,7 @@ def __init__(self,
31
35
self ._common_tags = {} if common_tags is None else common_tags
32
36
self .service_name = service_name
33
37
self .recorder = recorder
38
+ self .use_shared_spans = use_shared_spans
34
39
self .register_propagator (Format .TEXT_MAP , TextPropagator ())
35
40
self .register_propagator (Format .HTTP_HEADERS , TextPropagator ())
36
41
@@ -87,10 +92,14 @@ def start_span(self,
87
92
88
93
new_ctx = SpanContext (span_id = format (uuid .uuid4 ()))
89
94
if parent_ctx is not None :
95
+ new_ctx .trace_id = parent_ctx .trace_id
90
96
if parent_ctx .baggage is not None :
91
97
new_ctx ._baggage = parent_ctx .baggage .copy ()
92
- new_ctx .trace_id = parent_ctx .trace_id
93
- new_ctx .parent_id = parent_ctx .span_id
98
+ if self .use_shared_spans :
99
+ new_ctx .span_id = parent_ctx .span_id
100
+ new_ctx .parent_id = parent_ctx .parent_id
101
+ else :
102
+ new_ctx .parent_id = parent_ctx .span_id
94
103
else :
95
104
new_ctx .trace_id = format (uuid .uuid4 ())
96
105
0 commit comments