diff --git a/opentelemetry_distro_solarwinds/propagator.py b/opentelemetry_distro_solarwinds/propagator.py index b11d50ee5..46b578dd1 100644 --- a/opentelemetry_distro_solarwinds/propagator.py +++ b/opentelemetry_distro_solarwinds/propagator.py @@ -74,14 +74,16 @@ def inject( context: typing.Optional[Context] = None, setter: textmap.Setter = textmap.default_setter, ) -> None: - """Injects sw tracestate and trace options from SpanContext into carrier for HTTP request""" + """Injects sw tracestate from carrier into carrier for HTTP request, to get + tracestate injected by previous propagators""" span = trace.get_current_span(context) span_context = span.get_span_context() - trace_state = span_context.trace_state sw_value = W3CTransformer.sw_from_context(span_context) + trace_state_header = carrier.get(self._TRACESTATE_HEADER_NAME, None) - # Prepare carrier with context's or new tracestate - if trace_state: + # Prepare carrier with carrier's or new tracestate + if trace_state_header: + trace_state = TraceState.from_header([trace_state_header]) # Check if trace_state already contains sw KV if SW_TRACESTATE_KEY in trace_state.keys(): # If so, modify current span_id and trace_flags, and move to beginning of list diff --git a/opentelemetry_distro_solarwinds/sampler.py b/opentelemetry_distro_solarwinds/sampler.py index a4610d28e..378e2ab49 100644 --- a/opentelemetry_distro_solarwinds/sampler.py +++ b/opentelemetry_distro_solarwinds/sampler.py @@ -348,9 +348,9 @@ def calculate_attributes( trace_state_no_response = self.remove_response_from_sw(trace_state) else: # Must retain all potential tracestate pairs for attributes - attr_trace_state = TraceState.from_header( + attr_trace_state = TraceState.from_header([ tracestate_capture - ) + ]) new_attr_trace_state = attr_trace_state.update( SW_TRACESTATE_KEY, W3CTransformer.sw_from_span_and_decision(