Skip to content

Update OpAMP client to have additional callback methods#4322

Merged
xrmx merged 7 commits intoopen-telemetry:mainfrom
kelseyma:update_callbacks
Mar 20, 2026
Merged

Update OpAMP client to have additional callback methods#4322
xrmx merged 7 commits intoopen-telemetry:mainfrom
kelseyma:update_callbacks

Conversation

@kelseyma
Copy link
Copy Markdown
Contributor

@kelseyma kelseyma commented Mar 10, 2026

Description

Update the OpAMP client to use a Callbacks class, bringing Python closer to the existing opamp-go and Java opamp-client implementations. Adding a minimal set of callbacks at the moment (on_connect, on_connect_failed, on_error, on_message) with no-op default methods so new callbacks can be added in the future without breaking existing subclasses.
Hoping to work on client-side sending of messages after state changes next, which might add some additional callbacks and also allow us to not have to pass OpAMPAgent into the callbacks.

Also, removed some logging as I found it to be a little verbose while testing (e.g. 100 line traceback logged when can't connect to server) and exception was logged in multiple places. Happy to add back if preferred to keep.

Note: this is a breaking change to the OpAMPAgent constructor (message_handler is replaced by Callbacks), but the package hasn't been released yet. Some prior discussion on this: #3635 (comment)

Type of change

  • 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?

Tested with a local sample app (implemented callbacks subclass) and test server

// on_connect and on_message
2026-03-12 16:07:54,627 - client - INFO - Connected to OpAMP server
2026-03-12 16:07:54,627 - opentelemetry._opamp.agent - DEBUG - Job succeeded: b'\n\x10\x01\x9c\xe4M\x1b\xbf{\xb1\x85Zb{\x13}\x023\x10\x03 \x87`'
2026-03-12 16:07:54,627 - client - DEBUG - Received OpAMP message: MessageData(remote_config=None)
2026-03-12 16:08:24,609 - opentelemetry._opamp.agent - DEBUG - Periodic job enqueued
2026-03-12 16:08:24,630 - urllib3.connectionpool - DEBUG - http://localhost:8080 "POST /v1/opamp HTTP/1.1" 200 274
2026-03-12 16:08:24,630 - client - INFO - Connected to OpAMP server
2026-03-12 16:08:24,630 - opentelemetry._opamp.agent - DEBUG - Job succeeded: b'\n\x10\x01\x9c\xe4M\x1b\xbf{\xb1\x85Zb{\x13}\x023\x10\x04 \x87`'
2026-03-12 16:08:24,630 - client - DEBUG - Received OpAMP message: MessageData(remote_config=config {
  config_map {
    key: "test-python-file"
    value {
      body: "..."
      content_type: "application/json"
    }
  }
}
config_hash: "\373\001B\261H\373\364\241J\207u<\2676\033\221;\313\307#\272\017\224\226\000\306db\000e\2507"
)
2026-03-12 16:08:24,630 - client - INFO - Received remote config (hash: fb0142b148fbf4a1)
2026-03-12 16:08:24,631 - config - INFO - Log level changed from debug to INFO
2026-03-12 16:08:24,631 - client - INFO - Sent config APPLIED status with effective config
2026-03-12 16:08:24,639 - client - INFO - Connected to OpAMP server
2026-03-12 16:08:54,641 - client - INFO - Connected to OpAMP server

// full state requested
2026-03-12 15:10:36,961 - opentelemetry._opamp.agent - DEBUG - Server requested full state report
2026-03-12 15:10:36,961 - opentelemetry._opamp.agent - DEBUG - On-demand job enqueued: b'xyz'

// on_connect (throwing an exception) and on_connect_failed 
2026-03-09 14:27:10,099 - urllib3.connectionpool - DEBUG - http://localhost:8080 "POST /v1/opamp HTTP/1.1" 200 18
2026-03-09 14:27:10,100 - opentelemetry._opamp.agent - ERROR - Error when invoking function 'on_connect'
Traceback (most recent call last):
  File "/.../opentelemetry-python-contrib/opamp/opentelemetry-opamp-client/src/opentelemetry/_opamp/agent.py", line 34, in _safe_invoke
    function(*args)
    ~~~~~~~~^^^^^^^
  File "/.../sample-apps/docker/python-app/client.py", line 69, in on_connect
    raise ValueError("Testing _safe_invoke error handling")
ValueError: Testing _safe_invoke error handling
2026-03-09 14:27:10,101 - opentelemetry._opamp.agent - DEBUG - Job succeeded: b'\n\x10\x01\x9c\xd4~\xb6\xd4r\x81\x8a\x98\x12u \xe05\x17\x10\x01 \x87`'
2026-03-09 14:27:10,101 - client - DEBUG - Received OpAMP message (flags=0)
2026-03-09 14:27:40,092 - opentelemetry._opamp.agent - DEBUG - Periodic job enqueued
2026-03-09 14:27:40,094 - urllib3.connectionpool - DEBUG - Resetting dropped connection: localhost
2026-03-09 14:27:40,096 - client - WARNING - Failed to connect to OpAMP server: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1/opamp (Caused by NewConnectionError("HTTPConnection(host='localhost', port=8080): Failed to establish a new connection: [Errno 61] Connection refused"))
2026-03-09 14:27:40,096 - opentelemetry._opamp.agent - WARNING - Job b'\n\x10\x01\x9c\xd4~\xb6\xd4r\x81\x8a\x98\x12u \xe05\x17\x10\x02 \x87`' failed attempt 1/2: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1/opamp (Caused by NewConnectionError("HTTPConnection(host='localhost', port=8080): Failed to establish a new connection: [Errno 61] Connection refused"))
2026-03-09 14:27:40,096 - opentelemetry._opamp.agent - DEBUG - Retrying in 0.9s
2026-03-09 14:27:40,991 - urllib3.connectionpool - DEBUG - Starting new HTTP connection (2): localhost:8080
2026-03-09 14:27:40,995 - client - WARNING - Failed to connect to OpAMP server: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1/opamp (Caused by NewConnectionError("HTTPConnection(host='localhost', port=8080): Failed to establish a new connection: [Errno 61] Connection refused"))
2026-03-09 14:27:40,996 - opentelemetry._opamp.agent - WARNING - Job b'\n\x10\x01\x9c\xd4~\xb6\xd4r\x81\x8a\x98\x12u \xe05\x17\x10\x02 \x87`' failed attempt 2/2: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1/opamp (Caused by NewConnectionError("HTTPConnection(host='localhost', port=8080): Failed to establish a new connection: [Errno 61] Connection refused"))
2026-03-09 14:27:40,996 - opentelemetry._opamp.agent - ERROR - Job b'\n\x10\x01\x9c\xd4~\xb6\xd4r\x81\x8a\x98\x12u \xe05\x17\x10\x02 \x87`' dropped after max retries
  • 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

@kelseyma kelseyma marked this pull request as ready for review March 10, 2026 22:41
@kelseyma kelseyma requested a review from a team as a code owner March 10, 2026 22:41
@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Mar 13, 2026
@xrmx xrmx requested review from herin049 and pmcollins March 18, 2026 09:40
@xrmx xrmx moved this from Reviewed PRs that need fixes to Ready for review in Python PR digest Mar 18, 2026
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.

LGTM, thanks @kelseyma!

@xrmx xrmx enabled auto-merge (squash) March 20, 2026 08:32
@xrmx xrmx merged commit 6fb4918 into open-telemetry:main Mar 20, 2026
860 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in Python PR digest Mar 20, 2026
@xrmx
Copy link
Copy Markdown
Contributor

xrmx commented Mar 20, 2026

For integrations in the distro, could you please also take a look at open-telemetry/opentelemetry-python#4646 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants