File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
src/opentelemetry/context Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515import logging
16- import threading
1716import typing
18- from functools import wraps
1917from os import environ
2018from uuid import uuid4
2119
2624
2725logger = logging .getLogger (__name__ )
2826
27+
2928def _load_runtime_context () -> typing .Optional [_RuntimeContext ]:
3029 """Initialize the RuntimeContext
3130
@@ -51,8 +50,10 @@ def _load_runtime_context() -> typing.Optional[_RuntimeContext]:
5150 )
5251 ).load ()()
5352
53+
5454_RUNTIME_CONTEXT = _load_runtime_context ()
5555
56+
5657def create_key (keyname : str ) -> str :
5758 """To allow cross-cutting concern to control access to their local state,
5859 the RuntimeContext API provides a function which takes a keyname as input,
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515import unittest
16+ from os import environ
1617
1718from opentelemetry import context
1819from opentelemetry .context .context import Context
20+ from opentelemetry .context .contextvars_context import ContextVarsRuntimeContext
21+ from opentelemetry .environment_variables import OTEL_PYTHON_CONTEXT
1922
2023
2124def _do_work () -> str :
@@ -75,16 +78,13 @@ def test_set_current(self):
7578 context .detach (token )
7679 self .assertEqual ("yyy" , context .get_value ("a" ))
7780
81+
7882class TestInitContext (unittest .TestCase ):
7983 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-
8484 environ [OTEL_PYTHON_CONTEXT ] = "contextvars_context"
85- ctx = context ._load_runtime_context ()
85+ ctx = context ._load_runtime_context () # pylint: disable=W0212
8686 self .assertIsInstance (ctx , ContextVarsRuntimeContext )
8787
8888 environ .pop (OTEL_PYTHON_CONTEXT )
89- ctx = context ._load_runtime_context ()
89+ ctx = context ._load_runtime_context () # pylint: disable=W0212
9090 self .assertIsInstance (ctx , ContextVarsRuntimeContext )
You can’t perform that action at this time.
0 commit comments