@@ -30,23 +30,44 @@ def test_from_headers_no_headers(self):
3030 def test_from_headers_keys_exist (self ):
3131 test_trace_id = '6e0c63257de34c92bf9efcd03927272e'
3232 test_span_id = '00f067aa0ba902b7'
33- test_sampled = '1'
3433
35- headers = {
36- b3_format ._TRACE_ID_KEY : test_trace_id ,
37- b3_format ._SPAN_ID_KEY : test_span_id ,
38- b3_format ._SAMPLED_KEY : test_sampled ,
39- }
34+ for test_sampled in ['1' , 'True' , 'true' , 'd' ]:
35+ headers = {
36+ b3_format ._TRACE_ID_KEY : test_trace_id ,
37+ b3_format ._SPAN_ID_KEY : test_span_id ,
38+ b3_format ._SAMPLED_KEY : test_sampled ,
39+ }
4040
41- propagator = b3_format .B3FormatPropagator ()
42- span_context = propagator .from_headers (headers )
41+ propagator = b3_format .B3FormatPropagator ()
42+ span_context = propagator .from_headers (headers )
4343
44- self .assertEqual (span_context .trace_id , test_trace_id )
45- self .assertEqual (span_context .span_id , test_span_id )
46- self .assertEqual (
47- span_context .trace_options .enabled ,
48- bool (test_sampled )
49- )
44+ self .assertEqual (span_context .trace_id , test_trace_id )
45+ self .assertEqual (span_context .span_id , test_span_id )
46+ self .assertEqual (
47+ span_context .trace_options .enabled ,
48+ True
49+ )
50+
51+ def test_from_headers_keys_exist_disabled_sampling (self ):
52+ test_trace_id = '6e0c63257de34c92bf9efcd03927272e'
53+ test_span_id = '00f067aa0ba902b7'
54+
55+ for test_sampled in ['0' , 'False' , 'false' , None ]:
56+ headers = {
57+ b3_format ._TRACE_ID_KEY : test_trace_id ,
58+ b3_format ._SPAN_ID_KEY : test_span_id ,
59+ b3_format ._SAMPLED_KEY : test_sampled ,
60+ }
61+
62+ propagator = b3_format .B3FormatPropagator ()
63+ span_context = propagator .from_headers (headers )
64+
65+ self .assertEqual (span_context .trace_id , test_trace_id )
66+ self .assertEqual (span_context .span_id , test_span_id )
67+ self .assertEqual (
68+ span_context .trace_options .enabled ,
69+ False
70+ )
5071
5172 def test_from_headers_keys_not_exist (self ):
5273 propagator = b3_format .B3FormatPropagator ()
0 commit comments