Skip to content

Commit 4846503

Browse files
committed
Optimize iter_result.
1 parent a708407 commit 4846503

File tree

1 file changed

+5
-5
lines changed
  • ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi

1 file changed

+5
-5
lines changed

ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import functools
2222
import wsgiref.util as wsgiref_util
23-
from urllib.parse import urlparse
2423

2524
from opentelemetry import trace
2625
from opentelemetry.ext.wsgi.version import __version__ # noqa
@@ -120,16 +119,17 @@ def __call__(self, environ, start_response):
120119
# Put this in a subfunction to not delay the call to the wrapped
121120
# WSGI application (instrumentation should change the application
122121
# behavior as little as possible).
123-
def iter_result():
122+
def iter_result(iterable, span):
124123
try:
125124
for yielded in iterable:
126125
yield yielded
127126
finally:
128-
if hasattr(iterable, "close"):
129-
iterable.close()
127+
close = getattr(iterable, "close", None)
128+
if close:
129+
close()
130130
span.end()
131131

132-
return iter_result()
132+
return iter_result(iterable, span)
133133
except: # noqa
134134
span.end()
135135
raise

0 commit comments

Comments
 (0)