Skip to content

Commit f5e1d07

Browse files
committed
Resolve conversation
1 parent 458b483 commit f5e1d07

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

+13-2
Original file line numberDiff line numberDiff 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()

opentelemetry-api/tests/context/test_context.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import unittest
16-
from os import environ
16+
from unittest.mock import patch
1717

1818
from opentelemetry import context
1919
from opentelemetry.context.context import Context
@@ -80,11 +80,11 @@ def test_set_current(self):
8080

8181

8282
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):
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)

0 commit comments

Comments
 (0)