Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Feb 1, 2023
1 parent af6d00f commit 997f7a4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
33 changes: 23 additions & 10 deletions opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,31 @@ def _import_config_components(
component_implementations = []

for selected_component in selected_components:
component_implementations.append(
(
selected_component,
next(
iter(
entry_points(
group=entry_point_name, name=selected_component
try:
component_implementations.append(
(
selected_component,
next(
iter(
entry_points(
group=entry_point_name, name=selected_component
)
)
)
).load(),
).load(),
)
)
except KeyError:

raise RuntimeError(
f"Requested entry point {entry_point_name} not found"
)

except StopIteration:

raise RuntimeError(
f"Requested component {selected_component} not found in entry "
f"points for '{entry_point_name}'"
)
)

return component_implementations

Expand Down
17 changes: 17 additions & 0 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Dict, Iterable, Optional, Sequence
from unittest import TestCase
from unittest.mock import patch
from pytest import raises

from opentelemetry import trace
from opentelemetry.context import Context
Expand All @@ -37,6 +38,7 @@
_init_metrics,
_init_tracing,
_initialize_components,
_import_config_components
)
from opentelemetry.sdk._logs import LoggingHandler
from opentelemetry.sdk._logs.export import ConsoleLogExporter
Expand Down Expand Up @@ -780,3 +782,18 @@ def test_console_exporters(self):
metric_exporterts["console"].__class__,
ConsoleMetricExporter.__class__,
)


class TestImportConfigComponents(TestCase):

@patch("opentelemetry.sdk._configuration.entry_points", **{"side_effect": KeyError})
def test__import_config_components_missing_entry_point(
self, mock_entry_points
):

with raises(RuntimeError) as error:
_import_config_components(["a", "b", "c"], "name")

from pdb import set_trace
set_trace()
self.assertEqual()

0 comments on commit 997f7a4

Please sign in to comment.