Skip to content

Commit

Permalink
Resolve conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
WqyJh committed Apr 22, 2024
1 parent be6ddce commit 447ebeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,19 @@ def _load_runtime_context() -> typing.Optional[_RuntimeContext]:
)
).load()()
except Exception: # pylint: disable=broad-except
logger.exception("Failed to load context: %s", configured_context)
return None
logger.exception(
"Failed to load context: %s, fallback to %s",
configured_context,
OTEL_PYTHON_CONTEXT,
)
return next( # type: ignore
iter( # type: ignore
entry_points( # type: ignore
group="opentelemetry_context",
name=OTEL_PYTHON_CONTEXT,
)
)
).load()()


_RUNTIME_CONTEXT = _load_runtime_context()
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/tests/context/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import unittest
from os import environ
from unittest.mock import patch

from opentelemetry import context
from opentelemetry.context.context import Context
Expand Down Expand Up @@ -80,11 +80,11 @@ def test_set_current(self):


class TestInitContext(unittest.TestCase):
def test_load_runtime_context(self):
environ[OTEL_PYTHON_CONTEXT] = "contextvars_context"
def test_load_runtime_context_default(self):
ctx = context._load_runtime_context() # pylint: disable=W0212
self.assertIsInstance(ctx, ContextVarsRuntimeContext)

environ.pop(OTEL_PYTHON_CONTEXT)
@patch.dict("os.environ", {OTEL_PYTHON_CONTEXT: "contextvars_context"})
def test_load_runtime_context(self):
ctx = context._load_runtime_context() # pylint: disable=W0212
self.assertIsInstance(ctx, ContextVarsRuntimeContext)

0 comments on commit 447ebeb

Please sign in to comment.