Skip to content

Commit a74d746

Browse files
committed
opentelemetry-sdk: sketch of an OpAMP integration
1 parent 7b38450 commit a74d746

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • opentelemetry-sdk/src/opentelemetry/sdk/_configuration

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

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

493493

494+
def _import_opamp() -> callable[[...], None]:
495+
# this in development, at the moment we are looking for a callable that takes
496+
# the resource and instantiate an OpAMP agent.
497+
# 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()
515+
_, opamp_init_func = _import_config_components(
516+
["_init_func"], "_opentelemetry_opamp"
517+
)[0]
518+
519+
return opamp_init_func
520+
521+
494522
def _initialize_components(
495523
auto_instrumentation_version: str | None = None,
496524
trace_exporter_names: list[str] | None = None,
@@ -543,6 +571,18 @@ def _initialize_components(
543571
# from the env variable else defaults to "unknown_service"
544572
resource = Resource.create(resource_attributes)
545573

574+
# OpAMP is a system created to configure OpenTelemetry SDKs with a remote config.
575+
# This is different than other init helpers because setting up OpAMP requires distro
576+
# provided code as it's not strictly specified. We call OpAMP init before other code
577+
# 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.
583+
_init_opamp = _import_opamp()
584+
_init_opamp(resource=resource)
585+
546586
_init_tracing(
547587
exporters=span_exporters,
548588
id_generator=id_generator,

0 commit comments

Comments
 (0)