@@ -112,25 +112,27 @@ def __call__(self, environ, start_response):
112
112
)
113
113
span .start ()
114
114
try :
115
- self ._add_request_attributes (span , environ )
116
- start_response = self ._create_start_response (span , start_response )
117
-
118
- iterable = self .wsgi (environ , start_response )
119
-
120
- # Put this in a subfunction to not delay the call to the wrapped
121
- # WSGI application (instrumentation should change the application
122
- # behavior as little as possible).
123
- def iter_result (iterable , span ):
124
- try :
125
- for yielded in iterable :
126
- yield yielded
127
- finally :
128
- close = getattr (iterable , "close" , None )
129
- if close :
130
- close ()
131
- span .end ()
132
-
133
- return iter_result (iterable , span )
115
+ with tracer .use_span (span ):
116
+ self ._add_request_attributes (span , environ )
117
+ start_response = self ._create_start_response (span , start_response )
118
+
119
+ iterable = self .wsgi (environ , start_response )
120
+
121
+ # Put this in a subfunction to not delay the call to the wrapped
122
+ # WSGI application (instrumentation should change the application
123
+ # behavior as little as possible).
124
+ def iter_result (iterable , span ):
125
+ try :
126
+ with tracer .use_span (span ):
127
+ for yielded in iterable :
128
+ yield yielded
129
+ finally :
130
+ close = getattr (iterable , "close" , None )
131
+ if close :
132
+ close ()
133
+ span .end ()
134
+
135
+ return iter_result (iterable , span )
134
136
except : # noqa
135
137
span .end ()
136
138
raise
0 commit comments