Skip to content

Commit a83ab37

Browse files
committed
opentelemetry-sdk: sketch of an OpAMP integration
1 parent 59baf31 commit a83ab37

File tree

1 file changed

+40
-0
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_configuration

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,34 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator:
382382
raise RuntimeError(f"{id_generator_name} is not an IdGenerator")
383383

384384

385+
def _import_opamp() -> callable[[...], None]:
386+
# this in development, at the moment we are looking for a callable that takes
387+
# the resource and instantiate an OpAMP agent.
388+
# Since configuration is not specified every implementors may have its own.
389+
# OpAMPAgent and OpAMPClient will be contributed once I finish writing tests :)
390+
# def opamp_init(resource: Resource):
391+
# endpoint = os.environ.get("OTEL_PYTHON_OPAMP_ENDPOINT")
392+
# if endpoint:
393+
# opamp_client = OpAMPClient(
394+
# endpoint=endpoint,
395+
# agent_identifying_attributes={
396+
# "service.name": resource.get("service.name"),
397+
# "deployment.environment.name": resource.get("deployment.environment.name"),
398+
# },
399+
# )
400+
# opamp_agent = OpAMPAgent(
401+
# interval=30,
402+
# handler=opamp_handler, # this is an handler that gets called to process each OpAMP message
403+
# client=opamp_client,
404+
# )
405+
# opamp_agent.start()
406+
_, opamp_init_func = _import_config_components(
407+
["_init_func"], "_opentelemetry_opamp"
408+
)[0]
409+
410+
return opamp_init_func
411+
412+
385413
def _initialize_components(
386414
auto_instrumentation_version: str | None = None,
387415
trace_exporter_names: list[str] | None = None,
@@ -420,6 +448,18 @@ def _initialize_components(
420448
# from the env variable else defaults to "unknown_service"
421449
resource = Resource.create(resource_attributes)
422450

451+
# OpAMP is a system created to configure OpenTelemetry SDKs with a remote config.
452+
# This is different than other init helpers because setting up OpAMP requires distro
453+
# provided code as it's not strictly specified. We call OpAMP init before other code
454+
# because people may want to have it blocking to get an updated config before setting
455+
# up the rest. Content of OpAMP config depends on the implementor and vendors will
456+
# have their own. OpAMP to be fully integrated will need to introduce the concept of a
457+
# config so we can track the difference between current config and a newly provided remote
458+
# config. The goal is to have configuration updated dynamically while our SDK config is
459+
# currently static.
460+
_init_opamp = _import_opamp()
461+
_init_opamp(resource=resource)
462+
423463
_init_tracing(
424464
exporters=span_exporters,
425465
id_generator=id_generator,

0 commit comments

Comments
 (0)