@@ -129,17 +129,35 @@ def test_nested_span_suppression_with_multiple_outer_spans(self, tracing_helper)
129
129
spans_names_list = [span .name for span in tracing_helper .exporter .get_finished_spans ()]
130
130
assert spans_names_list == ["outer-span-1" , "outer-span-2" , "Root" ]
131
131
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
+
132
145
def test_suppress_http_auto_instrumentation_policy (self , tracing_helper ):
133
146
from azure .core .rest import HttpRequest
134
147
from azure .core .pipeline .transport import RequestsTransport
135
- from azure .core .pipeline .policies import DistributedTracingPolicy
148
+ from azure .core .pipeline .policies import DistributedTracingPolicy , SansIOHTTPPolicy
136
149
from azure .core .settings import settings
150
+ from opentelemetry .context import get_value , _SUPPRESS_HTTP_INSTRUMENTATION_KEY
137
151
138
152
settings .tracing_implementation = "opentelemetry"
139
153
154
+ class ContextValidator (SansIOHTTPPolicy ):
155
+ def on_request (self , request ):
156
+ assert get_value (_SUPPRESS_HTTP_INSTRUMENTATION_KEY )
157
+
140
158
class FooClient :
141
159
def __init__ (self , endpoint : str ):
142
- policies = [DistributedTracingPolicy ()]
160
+ policies = [DistributedTracingPolicy (), ContextValidator () ]
143
161
self ._client = PipelineClient (endpoint , policies = policies , transport = RequestsTransport ())
144
162
145
163
@distributed_trace
0 commit comments