29
29
util ,
30
30
)
31
31
from opentelemetry .sdk .trace import TracerProvider
32
- from opentelemetry .test .mock_httptextformat import (
33
- MockHTTPTextFormat ,
34
- NOOPHTTPTextFormat ,
32
+ from opentelemetry .test .mock_textmap import (
33
+ MockTextMapPropagator ,
34
+ NOOPTextMapPropagator ,
35
35
)
36
36
37
37
@@ -46,15 +46,15 @@ def setUp(self):
46
46
@classmethod
47
47
def setUpClass (cls ):
48
48
# Save current propagator to be restored on teardown.
49
- cls ._previous_propagator = propagators .get_global_httptextformat ()
49
+ cls ._previous_propagator = propagators .get_global_textmap ()
50
50
51
51
# Set mock propagator for testing.
52
- propagators .set_global_httptextformat ( MockHTTPTextFormat ())
52
+ propagators .set_global_textmap ( MockTextMapPropagator ())
53
53
54
54
@classmethod
55
55
def tearDownClass (cls ):
56
56
# Restore previous propagator.
57
- propagators .set_global_httptextformat (cls ._previous_propagator )
57
+ propagators .set_global_textmap (cls ._previous_propagator )
58
58
59
59
def test_shim_type (self ):
60
60
# Verify shim is an OpenTracing tracer.
@@ -482,8 +482,10 @@ def test_inject_http_headers(self):
482
482
483
483
headers = {}
484
484
self .shim .inject (context , opentracing .Format .HTTP_HEADERS , headers )
485
- self .assertEqual (headers [MockHTTPTextFormat .TRACE_ID_KEY ], str (1220 ))
486
- self .assertEqual (headers [MockHTTPTextFormat .SPAN_ID_KEY ], str (7478 ))
485
+ self .assertEqual (
486
+ headers [MockTextMapPropagator .TRACE_ID_KEY ], str (1220 )
487
+ )
488
+ self .assertEqual (headers [MockTextMapPropagator .SPAN_ID_KEY ], str (7478 ))
487
489
488
490
def test_inject_text_map (self ):
489
491
"""Test `inject()` method for Format.TEXT_MAP."""
@@ -496,8 +498,12 @@ def test_inject_text_map(self):
496
498
# Verify Format.TEXT_MAP
497
499
text_map = {}
498
500
self .shim .inject (context , opentracing .Format .TEXT_MAP , text_map )
499
- self .assertEqual (text_map [MockHTTPTextFormat .TRACE_ID_KEY ], str (1220 ))
500
- self .assertEqual (text_map [MockHTTPTextFormat .SPAN_ID_KEY ], str (7478 ))
501
+ self .assertEqual (
502
+ text_map [MockTextMapPropagator .TRACE_ID_KEY ], str (1220 )
503
+ )
504
+ self .assertEqual (
505
+ text_map [MockTextMapPropagator .SPAN_ID_KEY ], str (7478 )
506
+ )
501
507
502
508
def test_inject_binary (self ):
503
509
"""Test `inject()` method for Format.BINARY."""
@@ -515,8 +521,8 @@ def test_extract_http_headers(self):
515
521
"""Test `extract()` method for Format.HTTP_HEADERS."""
516
522
517
523
carrier = {
518
- MockHTTPTextFormat .TRACE_ID_KEY : 1220 ,
519
- MockHTTPTextFormat .SPAN_ID_KEY : 7478 ,
524
+ MockTextMapPropagator .TRACE_ID_KEY : 1220 ,
525
+ MockTextMapPropagator .SPAN_ID_KEY : 7478 ,
520
526
}
521
527
522
528
ctx = self .shim .extract (opentracing .Format .HTTP_HEADERS , carrier )
@@ -527,22 +533,22 @@ def test_extract_empty_context_returns_invalid_context(self):
527
533
"""In the case where the propagator cannot extract a
528
534
SpanContext, extract should return and invalid span context.
529
535
"""
530
- _old_propagator = propagators .get_global_httptextformat ()
531
- propagators .set_global_httptextformat ( NOOPHTTPTextFormat ())
536
+ _old_propagator = propagators .get_global_textmap ()
537
+ propagators .set_global_textmap ( NOOPTextMapPropagator ())
532
538
try :
533
539
carrier = {}
534
540
535
541
ctx = self .shim .extract (opentracing .Format .HTTP_HEADERS , carrier )
536
542
self .assertEqual (ctx .unwrap (), trace .INVALID_SPAN_CONTEXT )
537
543
finally :
538
- propagators .set_global_httptextformat (_old_propagator )
544
+ propagators .set_global_textmap (_old_propagator )
539
545
540
546
def test_extract_text_map (self ):
541
547
"""Test `extract()` method for Format.TEXT_MAP."""
542
548
543
549
carrier = {
544
- MockHTTPTextFormat .TRACE_ID_KEY : 1220 ,
545
- MockHTTPTextFormat .SPAN_ID_KEY : 7478 ,
550
+ MockTextMapPropagator .TRACE_ID_KEY : 1220 ,
551
+ MockTextMapPropagator .SPAN_ID_KEY : 7478 ,
546
552
}
547
553
548
554
ctx = self .shim .extract (opentracing .Format .TEXT_MAP , carrier )
0 commit comments