Skip to content

Add a basic http OpAMP client#3635

Merged
xrmx merged 52 commits intoopen-telemetry:mainfrom
xrmx:basic-http-opamp-client
Mar 5, 2026
Merged

Add a basic http OpAMP client#3635
xrmx merged 52 commits intoopen-telemetry:mainfrom
xrmx:basic-http-opamp-client

Conversation

@xrmx
Copy link
Copy Markdown
Contributor

@xrmx xrmx commented Jul 11, 2025

Description

This introduces a basic OpAMP http client for handling remote configuration. The client implements a bunch of capabilities (ReportsStatus, ReportsHeartbeat, AcceptsRemoteConfig, ReportsRemoteConfig) that are enough to get a remote config from an opamp server, parse it, apply it and ack it. Since OTel / OpAMP do not standardize APIs, config options or environment variables the distros are required to provide code doing so.
OTel Python distros would need to provide their own message handler callback that implements the actual change of whatever configuration their backends sends.

In practice distro would need to do something like the following:

from opentelemetry._opamp import messages
from opentelemetry._opamp.agent import OpAMPAgent
from opentelemetry._opamp.client import OpAMPClient
from opentelemetry._opamp.proto import opamp_pb2 as opamp_pb2


def opamp_handler(agent: OpAMPAgent, client: OpAMPClient, message: opamp_pb2.ServerToAgent):
    for config_filename, config in messages._decode_remote_config(message.remote_config):
        print("do something")


class MyOpenTelemetryConfigurator(_OTelSDKConfigurator):
    def _configure(self, **kwargs):
        super()._configure(**kwargs)

        enable_opamp = False
        endpoint = os.environ.get(OTEL_OPAMP_ENDPOINT)
        if endpoint:
            # this is not great but we don't have the calculated resource attributes around
            # see https://github.com/open-telemetry/opentelemetry-python/pull/4646 for creating
            # an entry point distros can implement
            resource = OTELResourceDetector().detect()
            agent_identifying_attributes = {
                "service.name": resource.attributes.get("service.name"),
            }
            opamp_client = OpAMPClient(
                endpoint=endpoint,
                agent_identifying_attributes=agent_identifying_attributes,
            )
            opamp_agent = OpAMPAgent(
                interval=30,
                message_handler=opamp_handler,
                client=opamp_client,
            )
            opamp_agent.start()

The module is called _opamp because it's a bit early to standardize on an api. The code is divided roughly in:

  • agent: handles threads and queues for sending messages to the server, supports sending heartbeat messages at a fixed interval
  • client: expose the api to build and send the OpAMP messages
  • messages: wrappers to simplify protobuf serialization
  • transports: http backends, currently there is only one using requests (to match the exporters)

OpAMP reference: https://opentelemetry.io/docs/specs/opamp/.

This is tested against https://github.com/elastic/opentelemetry-collector-components/ that is using the opamp-go implementation.

TODO:

  • write some docs with usage examples

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • tox

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@xrmx xrmx requested a review from a team as a code owner July 11, 2025 15:06
@danielgblanco
Copy link
Copy Markdown

@open-telemetry/opamp-spec-approvers could you help review this? thanks!

@xrmx xrmx force-pushed the basic-http-opamp-client branch from 3e67115 to e5fced7 Compare July 30, 2025 16:59
@xrmx xrmx force-pushed the basic-http-opamp-client branch from 1d2061f to 04d8923 Compare August 1, 2025 15:11
@xrmx xrmx force-pushed the basic-http-opamp-client branch from 4cfbf33 to a746292 Compare September 11, 2025 09:28
@xrmx xrmx force-pushed the basic-http-opamp-client branch from 1d85953 to cf479f2 Compare September 12, 2025 09:51
@Kludex
Copy link
Copy Markdown
Member

Kludex commented Sep 12, 2025

I can't unresolve threads, but I've replied above.

@tigrannajaryan
Copy link
Copy Markdown
Member

Thank you for working on this.

This is tested against https://github.com/elastic/opentelemetry-collector-components/ that is using the opamp-go implementation.

One thing that would be great to add is interoperability tests between Go and Python implementations. Ideally we would have both pairs (Client in Python, Server in Go and the vice versa) connecting and performing OpAMP exchanges to make sure the pair works correctly together.

OpAMP Go implementation presumably is the most complete implementation at the moment, so all other languages (including Python) could use it as a reference implementation to test against. I think we can spend a bit time adding any necessary tooling to opamp-go that makes this possible (mock servers, clients that probe capabilities, etc). Unfortunately I don't have time myself but if anyone wants to work on the design and implementation I can dedicate some time to review the design.

@xrmx
Copy link
Copy Markdown
Contributor Author

xrmx commented Sep 15, 2025

Thank you for working on this.

This is tested against https://github.com/elastic/opentelemetry-collector-components/ that is using the opamp-go implementation.

One thing that would be great to add is interoperability tests between Go and Python implementations. Ideally we would have both pairs (Client in Python, Server in Go and the vice versa) connecting and performing OpAMP exchanges to make sure the pair works correctly together.

This PR has some recorded e2e tests doing this, we don't test many scenarios but at least we test against a real response.

OpAMP Go implementation presumably is the most complete implementation at the moment, so all other languages (including Python) could use it as a reference implementation to test against. I think we can spend a bit time adding any necessary tooling to opamp-go that makes this possible (mock servers, clients that probe capabilities, etc). Unfortunately I don't have time myself but if anyone wants to work on the design and implementation I can dedicate some time to review the design.

That would be helpful indeed

@xrmx xrmx force-pushed the basic-http-opamp-client branch from b48e242 to 3eb1769 Compare September 30, 2025 08:36
Copy link
Copy Markdown
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving this an approving "python review" but I don't know much about OpAmp. Looks good enough to merge though as an initial prototype with proper disclaimers.

🚢

@xrmx xrmx force-pushed the basic-http-opamp-client branch 3 times, most recently from a483c24 to 6185955 Compare November 7, 2025 16:57
@kelseyma
Copy link
Copy Markdown
Contributor

kelseyma commented Feb 24, 2026

Hi @xrmx, thanks so much for creating this! I’ve been using the client for a PoC and had a few questions as I was going through the changes.

  • I noticed that opamp-go and the Java opamp-client define some additional callbacks. I was wondering if there are any plans to add similar callbacks to the Python client, particularly around error response handling?
  • Are there plans to support additional content types for configs, or potentially generalize the config methods to work for any content type?
  • Are there any plans to add more message options, or possibly introduce a helper to construct messages automatically based on updated fields (similar to opamp-go’s NextMessage)?

Totally understand if these are out of scope for this PR, wanted to ask in case there's been any discussion around them. I’m also happy to move this discussion to a new issue and take on the implementation work if that would be helpful. Thanks again!

@xrmx
Copy link
Copy Markdown
Contributor Author

xrmx commented Mar 5, 2026

Hi @xrmx, thanks so much for creating this! I’ve been using the client for a PoC and had a few questions as I was going through the changes.

* I noticed that `opamp-go` and the Java `opamp-client` define some additional callbacks. I was wondering if there are any plans to add similar callbacks to the Python client, particularly around error response handling?

I think can change the interface to match theirs, now you have just one callback and you have to do that on your own

* Are there plans to support additional content types for configs, or potentially generalize the config methods to work for any content type?

This stuff is not specified so I've implemented only what we are using :) Of course we can generalize that. Maybe some specs will come from open-telemetry/opentelemetry-specification#4738

* Are there any plans to add more message options, or possibly introduce a helper to construct messages automatically based on updated fields (similar to opamp-go’s `NextMessage`)?

Wasn't aware of that, I'll need to check that

Totally understand if these are out of scope for this PR, wanted to ask in case there's been any discussion around them. I’m also happy to move this discussion to a new issue and take on the implementation work if that would be helpful. Thanks again!

May be out of scope for this PR but perfectly fine to discuss. Thanks!

In the last push I've made this package released on its own so we can iterate on this without interfering with the releases.

@xrmx xrmx requested a review from pmcollins March 5, 2026 14:25
Copy link
Copy Markdown
Member

@pmcollins pmcollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran changes locally and LGTM. Thanks for doing this.

@xrmx xrmx merged commit 88e5bfc into open-telemetry:main Mar 5, 2026
784 checks passed
sightseeker added a commit to sightseeker/opentelemetry-python-contrib that referenced this pull request Mar 11, 2026
* Add a basic http OpAMP client

* Add some docs and hook it into the system

Still not building content

* Add default value of 30 seconds to heartbeat message interval

* Fix docs build

* More docs improvements

* Fix spellcheck

* Remove local workaround

* Generate workflows and add to release script

* Fix typos in opamp lint commands

* Fix requirements for pylint

* Update opamp/opentelemetry-opamp-client/pyproject.toml

* Recreate requirements

* Add missing opentelemetry-api dependency

* Fix tox test commands

Drop opentelemetry api fixed version from requirements

* Fix tox

* Add baseline of vcrpy 7.0.0

* Ignore pb2 module in pylintrc

* Bump pylint to match the version in core

* Silence pylint warnings

* Don't trace opamp client own http requests

* Permit to pass a custom transport to client

And a custom session to RequestsTransport

* Don't bump pylint after all

* Fix pylint

* Try to typecheck opamp client

* Bump version after rebase

* Fix typecheck in client

* Please pyright in strict mode

* No need for functions and methods to be private since _opamp module is already private

* Add missing protobuf package installation for typecheck

* Fix docs generation

* Fix pyright exclusion rule for proto

Missed .pyi exclusion

* Feedback

* Don't flush the queue at exit

* Log transport send exceptions

* Update example to not assume that the config is in json format

* Fix typo in exception

* Looks like it's implementers

* Add timeout to stop to forward to threads join

* Clarify doc

* Fix typo in var name

* Add support for mTLS

* Add helpers for handling of ReportFullState ServerToAgent flag

Introducing basic handling of the ReportsEffectiveConfig capability

* Remove backup file

* Rewrite opamp_proto_codegen.sh to use uv

* Make the package releasable independently

* Send full state at connection

* Add 3.14 test run

* Add changelog entry

* Add missing ReportsEffectiveConfig capability in documentation

* Start version from 0.1b0 and re-record e2e tests

* Record tests against opentelemetry-go

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants