File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
src/opentelemetry/context Expand file tree Collapse file tree 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]:
5151 )
5252 ).load ()()
5353 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 ()()
5667
5768
5869_RUNTIME_CONTEXT = _load_runtime_context ()
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515import unittest
16- from os import environ
16+ from unittest . mock import patch
1717
1818from opentelemetry import context
1919from opentelemetry .context .context import Context
@@ -80,11 +80,11 @@ def test_set_current(self):
8080
8181
8282class 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 ):
8584 ctx = context ._load_runtime_context () # pylint: disable=W0212
8685 self .assertIsInstance (ctx , ContextVarsRuntimeContext )
8786
88- environ .pop (OTEL_PYTHON_CONTEXT )
87+ @patch .dict ("os.environ" , {OTEL_PYTHON_CONTEXT : "contextvars_context" })
88+ def test_load_runtime_context (self ):
8989 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