Skip to content

Commit cbbf626

Browse files
committed
Optimize iter_result.
1 parent 1cbd877 commit cbbf626

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
@@ -21,7 +21,6 @@
2121
import functools
2222
import typing
2323
import wsgiref.util as wsgiref_util
24-
from urllib.parse import urlparse
2524

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

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

0 commit comments

Comments
 (0)