@@ -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 ("TestSpxn " ) 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 ("TestSpzn " ) 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 ("TestSpTn " )
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 ("TestSpcn " )
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,9 +134,7 @@ def test_explicit_start_time(self):
134
134
"""Test `start_time` argument."""
135
135
136
136
now = time .time ()
137
- from ipdb import set_trace
138
- set_trace ()
139
- with self .shim .start_active_span ("TestSp5n" , start_time = now ) as scope :
137
+ with self .shim .start_active_span ("TestSpan4" , start_time = now ) as scope :
140
138
result = util .time_seconds_from_ns (scope .span .unwrap ().start_time )
141
139
# Tolerate inaccuracies of less than a microsecond. See Note:
142
140
# https://open-telemetry.github.io/opentelemetry-python/opentelemetry.ext.opentracing_shim.html
@@ -147,7 +145,7 @@ def test_explicit_start_time(self):
147
145
def test_explicit_end_time (self ):
148
146
"""Test `end_time` argument of `finish()` method."""
149
147
150
- span = self .shim .start_span ("TestSpmn " )
148
+ span = self .shim .start_span ("TestSpan5 " )
151
149
now = time .time ()
152
150
span .finish (now )
153
151
@@ -161,7 +159,7 @@ def test_explicit_end_time(self):
161
159
def test_explicit_span_activation (self ):
162
160
"""Test manual activation and deactivation of a span."""
163
161
164
- span = self .shim .start_span ("TestSp99n " )
162
+ span = self .shim .start_span ("TestSpan6 " )
165
163
166
164
# Verify no span is currently active.
167
165
self .assertIsNone (self .shim .active_span )
@@ -182,7 +180,7 @@ def test_start_active_span_finish_on_close(self):
182
180
"""Test `finish_on_close` argument of `start_active_span()`."""
183
181
184
182
with self .shim .start_active_span (
185
- "TestSp88n " , finish_on_close = True
183
+ "TestSpan7 " , finish_on_close = True
186
184
) as scope :
187
185
# Verify span hasn't ended.
188
186
self .assertIsNone (scope .span .unwrap ().end_time )
@@ -191,7 +189,7 @@ def test_start_active_span_finish_on_close(self):
191
189
self .assertIsNotNone (scope .span .unwrap ().end_time )
192
190
193
191
with self .shim .start_active_span (
194
- "TestSp23n " , finish_on_close = False
192
+ "TestSpan8 " , finish_on_close = False
195
193
) as scope :
196
194
# Verify span hasn't ended.
197
195
self .assertIsNone (scope .span .unwrap ().end_time )
@@ -204,7 +202,7 @@ def test_start_active_span_finish_on_close(self):
204
202
def test_activate_finish_on_close (self ):
205
203
"""Test `finish_on_close` argument of `activate()`."""
206
204
207
- span = self .shim .start_span ("TestSp533n " )
205
+ span = self .shim .start_span ("TestSpan9 " )
208
206
209
207
with self .shim .scope_manager .activate (
210
208
span , finish_on_close = True
@@ -218,7 +216,7 @@ def test_activate_finish_on_close(self):
218
216
# Verify span has ended.
219
217
self .assertIsNotNone (span .unwrap ().end_time )
220
218
221
- span = self .shim .start_span ("TestSp009n " )
219
+ span = self .shim .start_span ("TestSpan10 " )
222
220
223
221
with self .shim .scope_manager .activate (
224
222
span , finish_on_close = False
@@ -404,13 +402,13 @@ def test_tags(self):
404
402
def test_span_tracer (self ):
405
403
"""Test the `tracer` property on `Span` objects."""
406
404
407
- with self .shim .start_active_span ("TestSp423n " ) as scope :
405
+ with self .shim .start_active_span ("TestSpan11 " ) as scope :
408
406
self .assertEqual (scope .span .tracer , self .shim )
409
407
410
408
def test_log_kv (self ):
411
409
"""Test the `log_kv()` method on `Span` objects."""
412
410
413
- with self .shim .start_span ("TestSp44444n " ) as span :
411
+ with self .shim .start_span ("TestSpan12 " ) as span :
414
412
span .log_kv ({"foo" : "bar" })
415
413
self .assertEqual (span .unwrap ().events [0 ].attributes ["foo" ], "bar" )
416
414
# Verify timestamp was generated automatically.
@@ -432,7 +430,7 @@ def test_log_kv(self):
432
430
def test_log (self ):
433
431
"""Test the deprecated `log` method on `Span` objects."""
434
432
435
- with self .shim .start_span ("TestSp3232n " ) as span :
433
+ with self .shim .start_span ("TestSpan13 " ) as span :
436
434
with self .assertWarns (DeprecationWarning ):
437
435
span .log (event = "foo" , payload = "bar" )
438
436
@@ -443,7 +441,7 @@ def test_log(self):
443
441
def test_log_event (self ):
444
442
"""Test the deprecated `log_event` method on `Span` objects."""
445
443
446
- with self .shim .start_span ("TestSpun " ) as span :
444
+ with self .shim .start_span ("TestSpan14 " ) as span :
447
445
with self .assertWarns (DeprecationWarning ):
448
446
span .log_event ("foo" , "bar" )
449
447
@@ -534,8 +532,6 @@ def test_extract_empty_context_returns_invalid_context(self):
534
532
try :
535
533
carrier = {}
536
534
537
- from ipdb import set_trace
538
- set_trace ()
539
535
ctx = self .shim .extract (opentracing .Format .HTTP_HEADERS , carrier )
540
536
self .assertEqual (ctx .unwrap (), trace .INVALID_SPAN_CONTEXT )
541
537
finally :
@@ -561,6 +557,7 @@ def test_extract_binary(self):
561
557
self .shim .extract (opentracing .Format .BINARY , bytearray ())
562
558
563
559
def test_baggage (self ):
560
+ """Test SpanShim baggage being set and being immutable"""
564
561
565
562
span_context_shim = SpanContextShim (
566
563
trace .SpanContext (1234 , 5678 , is_remote = False )
@@ -576,3 +573,22 @@ def test_baggage(self):
576
573
span_shim .set_baggage_item (1 , 2 )
577
574
578
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