Skip to content

Commit

Permalink
Optimize iter_result.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberon00 committed Sep 19, 2019
1 parent a708407 commit 4846503
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import functools
import wsgiref.util as wsgiref_util
from urllib.parse import urlparse

from opentelemetry import trace
from opentelemetry.ext.wsgi.version import __version__ # noqa
Expand Down Expand Up @@ -120,16 +119,17 @@ def __call__(self, environ, start_response):
# Put this in a subfunction to not delay the call to the wrapped
# WSGI application (instrumentation should change the application
# behavior as little as possible).
def iter_result():
def iter_result(iterable, span):
try:
for yielded in iterable:
yield yielded
finally:
if hasattr(iterable, "close"):
iterable.close()
close = getattr(iterable, "close", None)
if close:
close()
span.end()

return iter_result()
return iter_result(iterable, span)
except: # noqa
span.end()
raise

0 comments on commit 4846503

Please sign in to comment.