Modify sdkstats manager#47363
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the statsbeat system in azure-monitor-opentelemetry-exporter to allow SDKs/distros to register additional metric callbacks and have their observations included alongside the built-in statsbeat network metrics.
Changes:
- Add a callback registry and an
_iter_extra_observationshelper to safely aggregate extra observations from registered callbacks. - Add
StatsbeatManager.add_metric_callbackfor registering per-metric callbacks (idempotent per callback instance). - Update statsbeat network metric callbacks to append contributed observations, and add unit tests + changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_utils.py | Adds callback registry + iterator helper for contributed observations. |
| sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_manager.py | Adds StatsbeatManager.add_metric_callback API for registering callbacks. |
| sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_statsbeat_metrics.py | Appends extra observations to built-in network metrics callbacks. |
| sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_metrics.py | Adds tests validating callback registration and observation aggregation behavior. |
| sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md | Documents the new callback capability under Features Added. |
d128d6f to
15b56f1
Compare
973cc6a to
79de717
Compare
07aa1a0 to
2bd92fa
Compare
| @@ -0,0 +1,189 @@ | |||
| ```py | |||
There was a problem hiding this comment.
I am getting some api inconsistency error in the CI/CD pipeline, trying to fix that. EDIT: So, I investigated the cause of this issue and looks like this PR - #47203 adds this new API consistency check which requires us to add the api.md and the metadata file. I believe this should be a one-time occurrence, unless the API is updated and we will have to push that change then.
| :rtype: bool | ||
| """ | ||
| with _ADDITIONAL_CALLBACKS_LOCK: | ||
| callbacks = _ADDITIONAL_CALLBACKS.setdefault(metric_name, []) |
There was a problem hiding this comment.
Let's add additional callbacks globals to state and have gettors / settors pattern just like the other global variables.
There was a problem hiding this comment.
We can then also make the additional callbacks as fields on the manager instead of accessing it directly from globals.
…r own metric observations to built-in statsbeat metrics
a6024d9 to
719e178
Compare
The corresponding PR in
microsoft-opentelemetry- microsoft/opentelemetry-distro-python#191, currently the tests fail because they reference theadditional_callbacksfield which has been introduced in this PR.Once the exporter is released and the latest version is pinned in the microsoft opentelemetry distro, we would be able to merge the PR.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines