3
3
4
4
import os
5
5
6
- # First patch httplib
6
+ # First patch urllib
7
7
tracer = None
8
8
try :
9
9
from ddtrace import config , patch , tracer
18
18
)
19
19
tracer .configure (writer )
20
20
21
- config .httplib ["distributed_tracing" ] = True
22
- patch (httplib = True )
21
+ patch (urllib3 = True )
23
22
24
23
from pytest import hookimpl
25
24
@@ -80,6 +79,28 @@ def escape_reserved_keyword(word):
80
79
return word
81
80
82
81
82
+ def pytest_bdd_before_scenario (request , feature , scenario ):
83
+ if tracer is None :
84
+ return
85
+
86
+ span = tracer .start_span (
87
+ scenario .name ,
88
+ span_type = "scenario" ,
89
+ child_of = tracer .current_trace_context (),
90
+ activate = True ,
91
+ )
92
+ setattr (scenario , "__dd_span__" , span )
93
+
94
+
95
+ def pytest_bdd_after_scenario (request , feature , scenario ):
96
+ ctx = request .getfixturevalue ("context" )
97
+ for undo in reversed (ctx ["undo_operations" ]):
98
+ undo ()
99
+ span = getattr (scenario , "__dd_span__" , None )
100
+ if span is not None :
101
+ span .finish ()
102
+
103
+
83
104
def pytest_bdd_before_step (request , feature , scenario , step , step_func ):
84
105
if tracer is None :
85
106
return
@@ -88,7 +109,8 @@ def pytest_bdd_before_step(request, feature, scenario, step, step_func):
88
109
step .type ,
89
110
resource = step .name ,
90
111
span_type = step .type ,
91
- child_of = tracer .current_trace_context (),
112
+ child_of = getattr (scenario , "__dd_span__" ),
113
+ activate = True ,
92
114
)
93
115
setattr (step_func , "__dd_span__" , span )
94
116
@@ -230,9 +252,6 @@ def context(vcr, unique, unique_lower, freezer):
230
252
231
253
yield ctx
232
254
233
- for undo in reversed (ctx ["undo_operations" ]):
234
- undo ()
235
-
236
255
237
256
@pytest .fixture (scope = "session" )
238
257
def record_mode (request ):
0 commit comments