@@ -63,7 +63,7 @@ def test_shim_type(self):
63
63
def test_start_active_span (self ):
64
64
"""Test span creation and activation using `start_active_span()`."""
65
65
66
- with self .shim .start_active_span ("TestSpan " ) as scope :
66
+ with self .shim .start_active_span ("TestSpan0 " ) as scope :
67
67
# Verify correct type of Scope and Span objects.
68
68
self .assertIsInstance (scope , opentracing .Scope )
69
69
self .assertIsInstance (scope .span , opentracing .Span )
@@ -91,7 +91,7 @@ def test_start_active_span(self):
91
91
def test_start_span (self ):
92
92
"""Test span creation using `start_span()`."""
93
93
94
- with self .shim .start_span ("TestSpan " ) as span :
94
+ with self .shim .start_span ("TestSpan1 " ) as span :
95
95
# Verify correct type of Span object.
96
96
self .assertIsInstance (span , opentracing .Span )
97
97
@@ -107,7 +107,7 @@ def test_start_span(self):
107
107
def test_start_span_no_contextmanager (self ):
108
108
"""Test `start_span()` without a `with` statement."""
109
109
110
- span = self .shim .start_span ("TestSpan " )
110
+ span = self .shim .start_span ("TestSpan2 " )
111
111
112
112
# Verify span is started.
113
113
self .assertIsNotNone (span .unwrap ().start_time )
@@ -120,7 +120,7 @@ def test_start_span_no_contextmanager(self):
120
120
def test_explicit_span_finish (self ):
121
121
"""Test `finish()` method on `Span` objects."""
122
122
123
- span = self .shim .start_span ("TestSpan " )
123
+ span = self .shim .start_span ("TestSpan3 " )
124
124
125
125
# Verify span hasn't ended.
126
126
self .assertIsNone (span .unwrap ().end_time )
@@ -134,7 +134,7 @@ def test_explicit_start_time(self):
134
134
"""Test `start_time` argument."""
135
135
136
136
now = time .time ()
137
- with self .shim .start_active_span ("TestSpan " , start_time = now ) as scope :
137
+ with self .shim .start_active_span ("TestSpan4 " , start_time = now ) as scope :
138
138
result = util .time_seconds_from_ns (scope .span .unwrap ().start_time )
139
139
# Tolerate inaccuracies of less than a microsecond. See Note:
140
140
# https://open-telemetry.github.io/opentelemetry-python/opentelemetry.instrumentation.opentracing_shim.html
@@ -145,7 +145,7 @@ def test_explicit_start_time(self):
145
145
def test_explicit_end_time (self ):
146
146
"""Test `end_time` argument of `finish()` method."""
147
147
148
- span = self .shim .start_span ("TestSpan " )
148
+ span = self .shim .start_span ("TestSpan5 " )
149
149
now = time .time ()
150
150
span .finish (now )
151
151
@@ -159,7 +159,7 @@ def test_explicit_end_time(self):
159
159
def test_explicit_span_activation (self ):
160
160
"""Test manual activation and deactivation of a span."""
161
161
162
- span = self .shim .start_span ("TestSpan " )
162
+ span = self .shim .start_span ("TestSpan6 " )
163
163
164
164
# Verify no span is currently active.
165
165
self .assertIsNone (self .shim .active_span )
@@ -180,7 +180,7 @@ def test_start_active_span_finish_on_close(self):
180
180
"""Test `finish_on_close` argument of `start_active_span()`."""
181
181
182
182
with self .shim .start_active_span (
183
- "TestSpan " , finish_on_close = True
183
+ "TestSpan7 " , finish_on_close = True
184
184
) as scope :
185
185
# Verify span hasn't ended.
186
186
self .assertIsNone (scope .span .unwrap ().end_time )
@@ -189,7 +189,7 @@ def test_start_active_span_finish_on_close(self):
189
189
self .assertIsNotNone (scope .span .unwrap ().end_time )
190
190
191
191
with self .shim .start_active_span (
192
- "TestSpan " , finish_on_close = False
192
+ "TestSpan8 " , finish_on_close = False
193
193
) as scope :
194
194
# Verify span hasn't ended.
195
195
self .assertIsNone (scope .span .unwrap ().end_time )
@@ -202,7 +202,7 @@ def test_start_active_span_finish_on_close(self):
202
202
def test_activate_finish_on_close (self ):
203
203
"""Test `finish_on_close` argument of `activate()`."""
204
204
205
- span = self .shim .start_span ("TestSpan " )
205
+ span = self .shim .start_span ("TestSpan9 " )
206
206
207
207
with self .shim .scope_manager .activate (
208
208
span , finish_on_close = True
@@ -216,7 +216,7 @@ def test_activate_finish_on_close(self):
216
216
# Verify span has ended.
217
217
self .assertIsNotNone (span .unwrap ().end_time )
218
218
219
- span = self .shim .start_span ("TestSpan " )
219
+ span = self .shim .start_span ("TestSpan10 " )
220
220
221
221
with self .shim .scope_manager .activate (
222
222
span , finish_on_close = False
@@ -402,13 +402,13 @@ def test_tags(self):
402
402
def test_span_tracer (self ):
403
403
"""Test the `tracer` property on `Span` objects."""
404
404
405
- with self .shim .start_active_span ("TestSpan " ) as scope :
405
+ with self .shim .start_active_span ("TestSpan11 " ) as scope :
406
406
self .assertEqual (scope .span .tracer , self .shim )
407
407
408
408
def test_log_kv (self ):
409
409
"""Test the `log_kv()` method on `Span` objects."""
410
410
411
- with self .shim .start_span ("TestSpan " ) as span :
411
+ with self .shim .start_span ("TestSpan12 " ) as span :
412
412
span .log_kv ({"foo" : "bar" })
413
413
self .assertEqual (span .unwrap ().events [0 ].attributes ["foo" ], "bar" )
414
414
# Verify timestamp was generated automatically.
@@ -430,7 +430,7 @@ def test_log_kv(self):
430
430
def test_log (self ):
431
431
"""Test the deprecated `log` method on `Span` objects."""
432
432
433
- with self .shim .start_span ("TestSpan " ) as span :
433
+ with self .shim .start_span ("TestSpan13 " ) as span :
434
434
with self .assertWarns (DeprecationWarning ):
435
435
span .log (event = "foo" , payload = "bar" )
436
436
@@ -441,7 +441,7 @@ def test_log(self):
441
441
def test_log_event (self ):
442
442
"""Test the deprecated `log_event` method on `Span` objects."""
443
443
444
- with self .shim .start_span ("TestSpan " ) as span :
444
+ with self .shim .start_span ("TestSpan14 " ) as span :
445
445
with self .assertWarns (DeprecationWarning ):
446
446
span .log_event ("foo" , "bar" )
447
447
@@ -557,6 +557,7 @@ def test_extract_binary(self):
557
557
self .shim .extract (opentracing .Format .BINARY , bytearray ())
558
558
559
559
def test_baggage (self ):
560
+ """Test SpanShim baggage being set and being immutable"""
560
561
561
562
span_context_shim = SpanContextShim (
562
563
trace .SpanContext (1234 , 5678 , is_remote = False )
@@ -572,3 +573,22 @@ def test_baggage(self):
572
573
span_shim .set_baggage_item (1 , 2 )
573
574
574
575
self .assertTrue (span_shim .get_baggage_item (1 ), 2 )
576
+
577
+ def test_active (self ):
578
+ """Test that the active property and start_active_span return the same
579
+ object"""
580
+
581
+ # Verify no span is currently active.
582
+ self .assertIsNone (self .shim .active_span )
583
+
584
+ with self .shim .start_active_span ("TestSpan15" ) as scope :
585
+ # Verify span is active.
586
+ self .assertEqual (
587
+ self .shim .active_span .context .unwrap (),
588
+ scope .span .context .unwrap (),
589
+ )
590
+
591
+ self .assertIs (self .shim .scope_manager .active , scope )
592
+
593
+ # Verify no span is active.
594
+ self .assertIsNone (self .shim .active_span )
0 commit comments