File tree 2 files changed +9
-8
lines changed
src/opentelemetry/context
2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
import logging
16
- import threading
17
16
import typing
18
- from functools import wraps
19
17
from os import environ
20
18
from uuid import uuid4
21
19
26
24
27
25
logger = logging .getLogger (__name__ )
28
26
27
+
29
28
def _load_runtime_context () -> typing .Optional [_RuntimeContext ]:
30
29
"""Initialize the RuntimeContext
31
30
@@ -51,8 +50,10 @@ def _load_runtime_context() -> typing.Optional[_RuntimeContext]:
51
50
)
52
51
).load ()()
53
52
53
+
54
54
_RUNTIME_CONTEXT = _load_runtime_context ()
55
55
56
+
56
57
def create_key (keyname : str ) -> str :
57
58
"""To allow cross-cutting concern to control access to their local state,
58
59
the RuntimeContext API provides a function which takes a keyname as input,
Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
import unittest
16
+ from os import environ
16
17
17
18
from opentelemetry import context
18
19
from opentelemetry .context .context import Context
20
+ from opentelemetry .context .contextvars_context import ContextVarsRuntimeContext
21
+ from opentelemetry .environment_variables import OTEL_PYTHON_CONTEXT
19
22
20
23
21
24
def _do_work () -> str :
@@ -75,16 +78,13 @@ def test_set_current(self):
75
78
context .detach (token )
76
79
self .assertEqual ("yyy" , context .get_value ("a" ))
77
80
81
+
78
82
class TestInitContext (unittest .TestCase ):
79
83
def test_load_runtime_context (self ):
80
- from os import environ
81
- from opentelemetry .environment_variables import OTEL_PYTHON_CONTEXT
82
- from opentelemetry .context .contextvars_context import ContextVarsRuntimeContext
83
-
84
84
environ [OTEL_PYTHON_CONTEXT ] = "contextvars_context"
85
- ctx = context ._load_runtime_context ()
85
+ ctx = context ._load_runtime_context () # pylint: disable=W0212
86
86
self .assertIsInstance (ctx , ContextVarsRuntimeContext )
87
87
88
88
environ .pop (OTEL_PYTHON_CONTEXT )
89
- ctx = context ._load_runtime_context ()
89
+ ctx = context ._load_runtime_context () # pylint: disable=W0212
90
90
self .assertIsInstance (ctx , ContextVarsRuntimeContext )
You can’t perform that action at this time.
0 commit comments