File tree 2 files changed +17
-6
lines changed
src/opentelemetry/context
2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -51,8 +51,19 @@ def _load_runtime_context() -> typing.Optional[_RuntimeContext]:
51
51
)
52
52
).load ()()
53
53
except Exception : # pylint: disable=broad-except
54
- logger .exception ("Failed to load context: %s" , configured_context )
55
- return None
54
+ logger .exception (
55
+ "Failed to load context: %s, fallback to %s" ,
56
+ configured_context ,
57
+ OTEL_PYTHON_CONTEXT ,
58
+ )
59
+ return next ( # type: ignore
60
+ iter ( # type: ignore
61
+ entry_points ( # type: ignore
62
+ group = "opentelemetry_context" ,
63
+ name = OTEL_PYTHON_CONTEXT ,
64
+ )
65
+ )
66
+ ).load ()()
56
67
57
68
58
69
_RUNTIME_CONTEXT = _load_runtime_context ()
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
+ from unittest . mock import patch
17
17
18
18
from opentelemetry import context
19
19
from opentelemetry .context .context import Context
@@ -80,11 +80,11 @@ def test_set_current(self):
80
80
81
81
82
82
class TestInitContext (unittest .TestCase ):
83
- def test_load_runtime_context (self ):
84
- environ [OTEL_PYTHON_CONTEXT ] = "contextvars_context"
83
+ def test_load_runtime_context_default (self ):
85
84
ctx = context ._load_runtime_context () # pylint: disable=W0212
86
85
self .assertIsInstance (ctx , ContextVarsRuntimeContext )
87
86
88
- environ .pop (OTEL_PYTHON_CONTEXT )
87
+ @patch .dict ("os.environ" , {OTEL_PYTHON_CONTEXT : "contextvars_context" })
88
+ def test_load_runtime_context (self ):
89
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