1111HTTP_HEADER_TRACE_ID = "x-datadog-trace-id"
1212HTTP_HEADER_PARENT_ID = "x-datadog-parent-id"
1313HTTP_HEADER_SAMPLING_PRIORITY = "x-datadog-sampling-priority"
14+ HTTP_HEADER_ORIGIN = "x-datadog-origin"
1415
1516
1617# Note that due to WSGI spec we have to also check for uppercased and prefixed
2425POSSIBLE_HTTP_HEADER_SAMPLING_PRIORITIES = frozenset (
2526 [HTTP_HEADER_SAMPLING_PRIORITY , get_wsgi_header (HTTP_HEADER_SAMPLING_PRIORITY )]
2627)
28+ POSSIBLE_HTTP_HEADER_ORIGIN = frozenset (
29+ [HTTP_HEADER_ORIGIN , get_wsgi_header (HTTP_HEADER_ORIGIN )]
30+ )
2731
2832
2933class HTTPPropagator (object ):
@@ -54,6 +58,9 @@ def parent_call():
5458 # Propagate priority only if defined
5559 if sampling_priority is not None :
5660 headers [HTTP_HEADER_SAMPLING_PRIORITY ] = str (span_context .sampling_priority )
61+ # Propagate origin only if defined
62+ if span_context ._dd_origin is not None :
63+ headers [HTTP_HEADER_ORIGIN ] = str (span_context ._dd_origin )
5764
5865 @staticmethod
5966 def extract_header_value (possible_header_names , headers , default = None ):
@@ -86,6 +93,12 @@ def extract_sampling_priority(headers):
8693 POSSIBLE_HTTP_HEADER_SAMPLING_PRIORITIES , headers ,
8794 )
8895
96+ @staticmethod
97+ def extract_origin (headers ):
98+ return HTTPPropagator .extract_header_value (
99+ POSSIBLE_HTTP_HEADER_ORIGIN , headers ,
100+ )
101+
89102 def extract (self , headers ):
90103 """Extract a Context from HTTP headers into a new Context.
91104
@@ -111,6 +124,7 @@ def my_controller(url, headers):
111124 trace_id = HTTPPropagator .extract_trace_id (headers )
112125 parent_span_id = HTTPPropagator .extract_parent_span_id (headers )
113126 sampling_priority = HTTPPropagator .extract_sampling_priority (headers )
127+ origin = HTTPPropagator .extract_origin (headers )
114128
115129 if sampling_priority is not None :
116130 sampling_priority = int (sampling_priority )
@@ -119,15 +133,17 @@ def my_controller(url, headers):
119133 trace_id = trace_id ,
120134 span_id = parent_span_id ,
121135 sampling_priority = sampling_priority ,
136+ _dd_origin = origin ,
122137 )
123138 # If headers are invalid and cannot be parsed, return a new context and log the issue.
124139 except Exception as error :
125140 try :
126141 log .debug (
127- "invalid x-datadog-* headers, trace-id: %s, parent-id: %s, priority: %s, error: %s" ,
142+ "invalid x-datadog-* headers, trace-id: %s, parent-id: %s, priority: %s, origin: %s, error: %s" ,
128143 headers .get (HTTP_HEADER_TRACE_ID , 0 ),
129144 headers .get (HTTP_HEADER_PARENT_ID , 0 ),
130145 headers .get (HTTP_HEADER_SAMPLING_PRIORITY ),
146+ headers .get (HTTP_HEADER_ORIGIN , '' ),
131147 error ,
132148 )
133149 # We might fail on string formatting errors ; in that case only format the first error
0 commit comments