Skip to content

Commit 37ccc12

Browse files
committed
need to end the scope and span properly on both exit and close
1 parent da0709a commit 37ccc12

File tree

1 file changed

+12
-6
lines changed
  • shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim

1 file changed

+12
-6
lines changed

shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/__init__.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
# pylint:disable=no-member
8787

8888
import logging
89-
from typing import Optional, TypeVar, Union
89+
from types import TracebackType
90+
from typing import Optional, TypeVar, Union, Type
9091

9192
from deprecated import deprecated
9293
from opentracing import (
@@ -98,7 +99,6 @@
9899
Tracer,
99100
UnsupportedFormatException,
100101
)
101-
102102
from opentelemetry.baggage import get_baggage, set_baggage
103103
from opentelemetry.context import Context, attach, detach, get_value, set_value
104104
from opentelemetry.propagate import get_global_textmap
@@ -401,15 +401,21 @@ def close(self):
401401
ends the associated span**, regardless of the value passed in
402402
*finish_on_close* when activating the span.
403403
"""
404-
405-
detach(self._token)
404+
self._end_span_scope(None, None, None)
406405

407406
def __exit__(self, exc_type, exc_val, exc_tb):
408407
"""
409408
Override the __exit__ method of `opentracing.scope.Scope` so we can report
410409
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)
413419
if self._span_cm is not None:
414420
self._span_cm.__exit__(exc_type, exc_val, exc_tb)
415421
else:

0 commit comments

Comments
 (0)