@@ -129,17 +129,35 @@ def test_nested_span_suppression_with_multiple_outer_spans(self, tracing_helper)
129129 spans_names_list = [span .name for span in tracing_helper .exporter .get_finished_spans ()]
130130 assert spans_names_list == ["outer-span-1" , "outer-span-2" , "Root" ]
131131
132+ def test_suppress_http_under_change_context (self , tracing_helper ):
133+ from opentelemetry .context import get_value , _SUPPRESS_HTTP_INSTRUMENTATION_KEY
134+
135+ span1 = OpenTelemetrySpan (name = "span1" , kind = SpanKind .INTERNAL )
136+
137+ with OpenTelemetrySpan .change_context (span1 .span_instance ):
138+ # this won't suppress HTTP since it's an arbitrary span
139+ assert get_value (_SUPPRESS_HTTP_INSTRUMENTATION_KEY ) is None
140+
141+ with OpenTelemetrySpan .change_context (span1 ):
142+ # this works - we can guarantee suppression under our spans
143+ assert get_value (_SUPPRESS_HTTP_INSTRUMENTATION_KEY )
144+
132145 def test_suppress_http_auto_instrumentation_policy (self , tracing_helper ):
133146 from azure .core .rest import HttpRequest
134147 from azure .core .pipeline .transport import RequestsTransport
135- from azure .core .pipeline .policies import DistributedTracingPolicy
148+ from azure .core .pipeline .policies import DistributedTracingPolicy , SansIOHTTPPolicy
136149 from azure .core .settings import settings
150+ from opentelemetry .context import get_value , _SUPPRESS_HTTP_INSTRUMENTATION_KEY
137151
138152 settings .tracing_implementation = "opentelemetry"
139153
154+ class ContextValidator (SansIOHTTPPolicy ):
155+ def on_request (self , request ):
156+ assert get_value (_SUPPRESS_HTTP_INSTRUMENTATION_KEY )
157+
140158 class FooClient :
141159 def __init__ (self , endpoint : str ):
142- policies = [DistributedTracingPolicy ()]
160+ policies = [DistributedTracingPolicy (), ContextValidator () ]
143161 self ._client = PipelineClient (endpoint , policies = policies , transport = RequestsTransport ())
144162
145163 @distributed_trace
0 commit comments