11import logging
22import threading
33
4- from .constants import SAMPLING_PRIORITY_KEY
4+ from .constants import SAMPLING_PRIORITY_KEY , ORIGIN_KEY
55from .utils .formats import asbool , get_env
66
77log = logging .getLogger (__name__ )
@@ -25,7 +25,7 @@ class Context(object):
2525 _partial_flush_enabled = asbool (get_env ('tracer' , 'partial_flush_enabled' , 'false' ))
2626 _partial_flush_min_spans = int (get_env ('tracer' , 'partial_flush_min_spans' , 500 ))
2727
28- def __init__ (self , trace_id = None , span_id = None , sampled = True , sampling_priority = None ):
28+ def __init__ (self , trace_id = None , span_id = None , sampled = True , sampling_priority = None , _dd_origin = None ):
2929 """
3030 Initialize a new thread-safe ``Context``.
3131
@@ -41,6 +41,7 @@ def __init__(self, trace_id=None, span_id=None, sampled=True, sampling_priority=
4141 self ._parent_span_id = span_id
4242 self ._sampled = sampled
4343 self ._sampling_priority = sampling_priority
44+ self ._dd_origin = _dd_origin
4445
4546 @property
4647 def trace_id (self ):
@@ -184,6 +185,10 @@ def get(self):
184185 # attach the sampling priority to the context root span
185186 if sampled and sampling_priority is not None and trace :
186187 trace [0 ].set_metric (SAMPLING_PRIORITY_KEY , sampling_priority )
188+ origin = self ._dd_origin
189+ # attach the origin to the root span tag
190+ if sampled and origin is not None and trace :
191+ trace [0 ].set_tag (ORIGIN_KEY , origin )
187192
188193 # clean the current state
189194 self ._trace = []
@@ -202,6 +207,10 @@ def get(self):
202207 # attach the sampling priority to the context root span
203208 if sampled and sampling_priority is not None and trace :
204209 trace [0 ].set_metric (SAMPLING_PRIORITY_KEY , sampling_priority )
210+ origin = self ._dd_origin
211+ # attach the origin to the root span tag
212+ if sampled and origin is not None and trace :
213+ trace [0 ].set_tag (ORIGIN_KEY , origin )
205214
206215 # Any open spans will remain as `self._trace`
207216 # Any finished spans will get returned to be flushed
0 commit comments