|
86 | 86 | # pylint:disable=no-member
|
87 | 87 |
|
88 | 88 | import logging
|
89 |
| -from typing import Optional, TypeVar, Union |
| 89 | +from types import TracebackType |
| 90 | +from typing import Optional, TypeVar, Union, Type |
90 | 91 |
|
91 | 92 | from deprecated import deprecated
|
92 | 93 | from opentracing import (
|
|
98 | 99 | Tracer,
|
99 | 100 | UnsupportedFormatException,
|
100 | 101 | )
|
101 |
| - |
102 | 102 | from opentelemetry.baggage import get_baggage, set_baggage
|
103 | 103 | from opentelemetry.context import Context, attach, detach, get_value, set_value
|
104 | 104 | from opentelemetry.propagate import get_global_textmap
|
@@ -401,15 +401,21 @@ def close(self):
|
401 | 401 | ends the associated span**, regardless of the value passed in
|
402 | 402 | *finish_on_close* when activating the span.
|
403 | 403 | """
|
404 |
| - |
405 |
| - detach(self._token) |
| 404 | + self._end_span_scope(None, None, None) |
406 | 405 |
|
407 | 406 | def __exit__(self, exc_type, exc_val, exc_tb):
|
408 | 407 | """
|
409 | 408 | Override the __exit__ method of `opentracing.scope.Scope` so we can report
|
410 | 409 | exceptions correctly in opentelemetry specification format. """
|
411 |
| - self.close() |
412 |
| - |
| 410 | + self._end_span_scope(exc_type, exc_val, exc_tb) |
| 411 | + |
| 412 | + def _end_span_scope( |
| 413 | + self, |
| 414 | + exc_type: Optional[Type[BaseException]], |
| 415 | + exc_val: Optional[BaseException], |
| 416 | + exc_tb: Optional[TracebackType], |
| 417 | + ) -> None: |
| 418 | + detach(self._token) |
413 | 419 | if self._span_cm is not None:
|
414 | 420 | self._span_cm.__exit__(exc_type, exc_val, exc_tb)
|
415 | 421 | else:
|
|
0 commit comments