33
44from nose .tools import eq_ , assert_raises
55
6- # project
76from ddtrace import compat
87from ddtrace .contrib .pyramid .patch import insert_tween_if_needed
98
1615
1716
1817class PyramidBase (object ):
18+ """Base Pyramid test application"""
1919 instrument = False
2020
2121 def setUp (self ):
@@ -38,6 +38,9 @@ def get_settings(self):
3838 def override_settings (self , settings ):
3939 self .create_app (settings )
4040
41+ class PyramidTestCase (PyramidBase ):
42+ """Pyramid TestCase that includes tests for automatic instrumentation"""
43+
4144 def test_200 (self ):
4245 res = self .app .get ('/' , status = 200 )
4346 assert b'idx' in res .body
@@ -248,7 +251,7 @@ def includeme(config):
248251 pass
249252
250253
251- class TestPyramid (PyramidBase ):
254+ class TestPyramid (PyramidTestCase ):
252255 instrument = True
253256
254257 def get_settings (self ):
@@ -263,3 +266,30 @@ def test_tween_overridden(self):
263266 self .app .get ('/json' , status = 200 )
264267 spans = self .tracer .writer .pop ()
265268 eq_ (len (spans ), 0 )
269+
270+
271+ class TestPyramidDistributedTracing (PyramidBase ):
272+ instrument = True
273+
274+ def get_settings (self ):
275+ return {
276+ 'datadog_distributed_tracing' : True ,
277+ }
278+
279+ def test_distributed_tracing (self ):
280+ # ensure the Context is properly created
281+ # if distributed tracing is enabled
282+ headers = {
283+ 'x-datadog-trace-id' : '100' ,
284+ 'x-datadog-parent-id' : '42' ,
285+ 'x-datadog-sampling-priority' : '2' ,
286+ }
287+ res = self .app .get ('/' , headers = headers , status = 200 )
288+ writer = self .tracer .writer
289+ spans = writer .pop ()
290+ eq_ (len (spans ), 1 )
291+ # check the propagated Context
292+ span = spans [0 ]
293+ eq_ (span .trace_id , 100 )
294+ eq_ (span .parent_id , 42 )
295+ eq_ (span .get_metric ('_sampling_priority_v1' ), 2 )
0 commit comments