55from nose .tools import assert_equals
66
77import instana .http_propagator as ihp
8+ import instana .text_propagator as itp
89from instana import options , util
910from instana .tracer import InstanaTracer
1011
1112
12- def test_basics ():
13+ def test_http_basics ():
1314 inspect .isclass (ihp .HTTPPropagator )
1415
1516 inject_func = getattr (ihp .HTTPPropagator , "inject" , None )
@@ -21,7 +22,7 @@ def test_basics():
2122 assert callable (extract_func )
2223
2324
24- def test_inject_with_dict ():
25+ def test_http_inject_with_dict ():
2526 opts = options .Options ()
2627 ot .tracer = InstanaTracer (opts )
2728
@@ -37,7 +38,7 @@ def test_inject_with_dict():
3738 assert_equals (carrier ['X-Instana-L' ], "1" )
3839
3940
40- def test_inject_with_list ():
41+ def test_http_inject_with_list ():
4142 opts = options .Options ()
4243 ot .tracer = InstanaTracer (opts )
4344
@@ -50,7 +51,7 @@ def test_inject_with_list():
5051 assert ('X-Instana-L' , "1" ) in carrier
5152
5253
53- def test_basic_extract ():
54+ def test_http_basic_extract ():
5455 opts = options .Options ()
5556 ot .tracer = InstanaTracer (opts )
5657
@@ -62,7 +63,7 @@ def test_basic_extract():
6263 assert_equals ('0000000000000001' , ctx .span_id )
6364
6465
65- def test_mixed_case_extract ():
66+ def test_http_mixed_case_extract ():
6667 opts = options .Options ()
6768 ot .tracer = InstanaTracer (opts )
6869
@@ -74,7 +75,7 @@ def test_mixed_case_extract():
7475 assert_equals ('0000000000000001' , ctx .span_id )
7576
7677
77- def test_no_context_extract ():
78+ def test_http_no_context_extract ():
7879 opts = options .Options ()
7980 ot .tracer = InstanaTracer (opts )
8081
@@ -84,7 +85,7 @@ def test_no_context_extract():
8485 assert ctx is None
8586
8687
87- def test_128bit_headers ():
88+ def test_http_128bit_headers ():
8889 opts = options .Options ()
8990 ot .tracer = InstanaTracer (opts )
9091
@@ -96,3 +97,88 @@ def test_128bit_headers():
9697 assert_equals ('b0789916ff8f319f' , ctx .trace_id )
9798 assert_equals ('b0789916ff8f319f' , ctx .span_id )
9899
100+
101+ def test_text_basics ():
102+ inspect .isclass (itp .TextPropagator )
103+
104+ inject_func = getattr (itp .TextPropagator , "inject" , None )
105+ assert inject_func
106+ assert callable (inject_func )
107+
108+ extract_func = getattr (itp .TextPropagator , "extract" , None )
109+ assert extract_func
110+ assert callable (extract_func )
111+
112+
113+ def test_text_inject_with_dict ():
114+ opts = options .Options ()
115+ ot .tracer = InstanaTracer (opts )
116+
117+ carrier = {}
118+ span = ot .tracer .start_span ("nosetests" )
119+ ot .tracer .inject (span .context , ot .Format .TEXT_MAP , carrier )
120+
121+ assert 'X-INSTANA-T' in carrier
122+ assert_equals (carrier ['X-INSTANA-T' ], span .context .trace_id )
123+ assert 'X-INSTANA-S' in carrier
124+ assert_equals (carrier ['X-INSTANA-S' ], span .context .span_id )
125+ assert 'X-INSTANA-L' in carrier
126+ assert_equals (carrier ['X-INSTANA-L' ], "1" )
127+
128+
129+ def test_text_inject_with_list ():
130+ opts = options .Options ()
131+ ot .tracer = InstanaTracer (opts )
132+
133+ carrier = []
134+ span = ot .tracer .start_span ("nosetests" )
135+ ot .tracer .inject (span .context , ot .Format .TEXT_MAP , carrier )
136+
137+ assert ('X-INSTANA-T' , span .context .trace_id ) in carrier
138+ assert ('X-INSTANA-S' , span .context .span_id ) in carrier
139+ assert ('X-INSTANA-L' , "1" ) in carrier
140+
141+
142+ def test_text_basic_extract ():
143+ opts = options .Options ()
144+ ot .tracer = InstanaTracer (opts )
145+
146+ carrier = {'X-INSTANA-T' : '1' , 'X-INSTANA-S' : '1' , 'X-INSTANA-L' : '1' }
147+ ctx = ot .tracer .extract (ot .Format .TEXT_MAP , carrier )
148+
149+ assert type (ctx ) is basictracer .context .SpanContext
150+ assert_equals ('0000000000000001' , ctx .trace_id )
151+ assert_equals ('0000000000000001' , ctx .span_id )
152+
153+
154+ def test_text_mixed_case_extract ():
155+ opts = options .Options ()
156+ ot .tracer = InstanaTracer (opts )
157+
158+ carrier = {'x-insTana-T' : '1' , 'X-inSTANa-S' : '1' , 'X-INstana-l' : '1' }
159+ ctx = ot .tracer .extract (ot .Format .TEXT_MAP , carrier )
160+
161+ assert (ctx is None )
162+
163+
164+ def test_text_no_context_extract ():
165+ opts = options .Options ()
166+ ot .tracer = InstanaTracer (opts )
167+
168+ carrier = {}
169+ ctx = ot .tracer .extract (ot .Format .TEXT_MAP , carrier )
170+
171+ assert ctx is None
172+
173+
174+ def test_text_128bit_headers ():
175+ opts = options .Options ()
176+ ot .tracer = InstanaTracer (opts )
177+
178+ carrier = {'X-INSTANA-T' : '0000000000000000b0789916ff8f319f' ,
179+ 'X-INSTANA-S' : ' 0000000000000000b0789916ff8f319f' , 'X-INSTANA-L' : '1' }
180+ ctx = ot .tracer .extract (ot .Format .TEXT_MAP , carrier )
181+
182+ assert type (ctx ) is basictracer .context .SpanContext
183+ assert_equals ('b0789916ff8f319f' , ctx .trace_id )
184+ assert_equals ('b0789916ff8f319f' , ctx .span_id )
0 commit comments