Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6988ff

Browse files
author
Alex Boten
committed
update set_current/reset to attach/detach in RuntimeContext
Signed-off-by: Alex Boten <[email protected]>
1 parent c0ede6c commit e6988ff

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

opentelemetry-api/src/opentelemetry/context/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def attach(context: Context) -> object:
9595
"""
9696
get_current()
9797

98-
return _RUNTIME_CONTEXT.set_current(context) # type:ignore
98+
return _RUNTIME_CONTEXT.attach(context) # type:ignore
9999

100100

101101
def detach(token: object) -> None:
@@ -106,7 +106,7 @@ def detach(token: object) -> None:
106106
token: The Token that was returned by a previous call to attach a Context.
107107
"""
108108
try:
109-
_RUNTIME_CONTEXT.reset(token) # type: ignore
109+
_RUNTIME_CONTEXT.detach(token) # type: ignore
110110
except (AttributeError, TypeError, ValueError):
111111
logger.error("Failed to detach context")
112112

opentelemetry-api/src/opentelemetry/context/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RuntimeContext(ABC):
2929
"""
3030

3131
@abstractmethod
32-
def set_current(self, context: Context) -> object:
32+
def attach(self, context: Context) -> object:
3333
""" Sets the current `Context` object. Returns a
3434
token that can be used to reset to the previous `Context`.
3535
@@ -42,7 +42,7 @@ def get_current(self) -> Context:
4242
""" Returns the current `Context` object. """
4343

4444
@abstractmethod
45-
def reset(self, token: object) -> None:
45+
def detach(self, token: object) -> None:
4646
""" Resets Context to a previous value
4747
4848
Args:

opentelemetry-api/src/opentelemetry/context/contextvars_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ def __init__(self) -> None:
3535
self._CONTEXT_KEY, default=Context()
3636
)
3737

38-
def set_current(self, context: Context) -> object:
39-
"""See `opentelemetry.context.RuntimeContext.set_current`."""
38+
def attach(self, context: Context) -> object:
39+
"""See `opentelemetry.context.RuntimeContext.attach`."""
4040
return self._current_context.set(context)
4141

4242
def get_current(self) -> Context:
4343
"""See `opentelemetry.context.RuntimeContext.get_current`."""
4444
return self._current_context.get()
4545

46-
def reset(self, token: object) -> None:
47-
"""See `opentelemetry.context.RuntimeContext.reset`."""
46+
def detach(self, token: object) -> None:
47+
"""See `opentelemetry.context.RuntimeContext.detach`."""
4848
self._current_context.reset(token) # type: ignore
4949

5050

opentelemetry-api/src/opentelemetry/context/threadlocal_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def __init__(self, context: Context) -> None:
3232
def __init__(self) -> None:
3333
self._current_context = threading.local()
3434

35-
def set_current(self, context: Context) -> object:
36-
"""See `opentelemetry.context.RuntimeContext.set_current`."""
35+
def attach(self, context: Context) -> object:
36+
"""See `opentelemetry.context.RuntimeContext.attach`."""
3737
current = self.get_current()
3838
setattr(self._current_context, self._CONTEXT_KEY, context)
3939
return self._Token(current)
@@ -49,8 +49,8 @@ def get_current(self) -> Context:
4949
) # type: Context
5050
return context
5151

52-
def reset(self, token: object) -> None:
53-
"""See `opentelemetry.context.RuntimeContext.reset`."""
52+
def detach(self, token: object) -> None:
53+
"""See `opentelemetry.context.RuntimeContext.detach`."""
5454
if not isinstance(token, self._Token):
5555
raise ValueError("invalid token")
5656
setattr(self._current_context, self._CONTEXT_KEY, token.context)

0 commit comments

Comments
 (0)