Skip to content

Commit

Permalink
FIX: add __exit__ method to ScopeShim to report exceptions in opentel…
Browse files Browse the repository at this point in the history
…emetry spec format
  • Loading branch information
robertsben committed May 21, 2021
1 parent 7e1f247 commit da0709a
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,14 @@ def close(self):

detach(self._token)

def __exit__(self, exc_type, exc_val, exc_tb):
"""
Override the __exit__ method of `opentracing.scope.Scope` so we can report
exceptions correctly in opentelemetry specification format. """
self.close()

if self._span_cm is not None:
# We don't have error information to pass to `__exit__()` so we
# pass `None` in all arguments. If the OpenTelemetry tracer
# implementation requires this information, the `__exit__()` method
# on `opentracing.Scope` should be overridden and modified to pass
# the relevant values to this `close()` method.
self._span_cm.__exit__(None, None, None)
self._span_cm.__exit__(exc_type, exc_val, exc_tb)
else:
self._span.unwrap().end()

Expand Down

0 comments on commit da0709a

Please sign in to comment.