Skip to content

Commit

Permalink
Handle TypeError from opentelemetry.context.contextvars_context in de…
Browse files Browse the repository at this point in the history
…tach
  • Loading branch information
hyoinandout committed Aug 29, 2024
1 parent 889f7df commit 1dadd33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def detach(token: object) -> None:
"""
try:
_RUNTIME_CONTEXT.detach(token)
except TypeError:
logger.exception("Expected an instance of Token, got None")
except Exception: # pylint: disable=broad-exception-caught
logger.exception("Failed to detach context")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def detach(self, token: object) -> None:
Args:
token: A reference to a previous Context.
"""
self._current_context.reset(token) # type: ignore
try:
self._current_context.reset(token)
except TypeError:
raise TypeError


__all__ = ["ContextVarsRuntimeContext"]

0 comments on commit 1dadd33

Please sign in to comment.