Skip to content

Commit 579da8c

Browse files
committed
Reword and add tests
1 parent 3c1eb2e commit 579da8c

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -495,25 +495,9 @@ def _import_opamp() -> callable[[...], None]:
495495
# this in development, at the moment we are looking for a callable that takes
496496
# the resource and instantiate an OpAMP agent.
497497
# Since configuration is not specified every implementors may have its own.
498-
# OpAMPAgent and OpAMPClient will be contributed once I finish writing tests :)
499-
# def opamp_init(resource: Resource):
500-
# endpoint = os.environ.get("OTEL_PYTHON_OPAMP_ENDPOINT")
501-
# if endpoint:
502-
# opamp_client = OpAMPClient(
503-
# endpoint=endpoint,
504-
# agent_identifying_attributes={
505-
# "service.name": resource.get("service.name"),
506-
# "deployment.environment.name": resource.get("deployment.environment.name"),
507-
# },
508-
# )
509-
# opamp_agent = OpAMPAgent(
510-
# interval=30,
511-
# handler=opamp_handler, # this is an handler that gets called to process each OpAMP message
512-
# client=opamp_client,
513-
# )
514-
# opamp_agent.start()
498+
# Refer to opentelemetry-opamp-client package on how to setup the OpAMP agent.
515499
_, opamp_init_func = _import_config_components(
516-
["_init_func"], "_opentelemetry_opamp"
500+
["init_function"], "_opentelemetry_opamp"
517501
)[0]
518502

519503
return opamp_init_func
@@ -575,11 +559,7 @@ def _initialize_components(
575559
# This is different than other init helpers because setting up OpAMP requires distro
576560
# provided code as it's not strictly specified. We call OpAMP init before other code
577561
# because people may want to have it blocking to get an updated config before setting
578-
# up the rest. Content of OpAMP config depends on the implementor and vendors will
579-
# have their own. OpAMP to be fully integrated will need to introduce the concept of a
580-
# config so we can track the difference between current config and a newly provided remote
581-
# config. The goal is to have configuration updated dynamically while our SDK config is
582-
# currently static.
562+
# up the rest.
583563
try:
584564
_init_opamp = _import_opamp()
585565
_init_opamp(resource=resource)

opentelemetry-sdk/tests/test_configurator.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,3 +1438,33 @@ def f(x):
14381438
self.assertEqual(logging.config.dictConfig.__name__, "dictConfig")
14391439
self.assertEqual(logging.basicConfig.__name__, "basicConfig")
14401440
self.assertEqual(logging.config.fileConfig.__name__, "fileConfig")
1441+
1442+
1443+
class TestOpAMPInit(TestCase):
1444+
@patch("opentelemetry.sdk._configuration.entry_points")
1445+
@patch("opentelemetry.sdk._configuration.Resource")
1446+
def test_init_function_found(self, mock_resource, mock_entry_points):
1447+
init_function = mock.Mock()
1448+
mock_entry_points.configure_mock(
1449+
return_value=[IterEntryPoint("init_function", init_function)]
1450+
)
1451+
1452+
_initialize_components(id_generator=1)
1453+
1454+
mock_entry_points.assert_has_calls(
1455+
[mock.call(group="_opentelemetry_opamp", name="init_function")]
1456+
)
1457+
init_function.assert_called_once_with(
1458+
resource=mock_resource.create.return_value
1459+
)
1460+
1461+
@patch("opentelemetry.sdk._configuration.entry_points")
1462+
def test_init_function_not_found(self, mock_entry_points):
1463+
mock_entry_points.configure_mock(return_value=[])
1464+
1465+
with self.assertLogs(level="DEBUG") as cm:
1466+
_initialize_components(id_generator=1)
1467+
self.assertIn(
1468+
"DEBUG:opentelemetry.sdk._configuration:No OpAMP init function found",
1469+
cm.output,
1470+
)

0 commit comments

Comments
 (0)