Skip to content

Commit

Permalink
Fix active span in WSGI instrumentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberon00 committed Sep 19, 2019
1 parent dd098ed commit 0f37eec
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,27 @@ def __call__(self, environ, start_response):
)
span.start()
try:
self._add_request_attributes(span, environ)
start_response = self._create_start_response(span, start_response)

iterable = self.wsgi(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(iterable, span):
try:
for yielded in iterable:
yield yielded
finally:
close = getattr(iterable, "close", None)
if close:
close()
span.end()

return iter_result(iterable, span)
with tracer.use_span(span):
self._add_request_attributes(span, environ)
start_response = self._create_start_response(span, start_response)

iterable = self.wsgi(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(iterable, span):
try:
with tracer.use_span(span):
for yielded in iterable:
yield yielded
finally:
close = getattr(iterable, "close", None)
if close:
close()
span.end()

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

0 comments on commit 0f37eec

Please sign in to comment.