feat: add OpenTelemetry metrics support#553
feat: add OpenTelemetry metrics support#553ajbozarth merged 11 commits intogenerative-computing:mainfrom
Conversation
Refactored telemetry module structure to follow Python best practices: - Moved tracing implementation from __init__.py to new tracing.py module - Updated __init__.py to only contain imports and exports - Updated backend_instrumentation.py to import from tracing module This improves code organization and maintainability by separating implementation from the package interface. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Implemented comprehensive metrics support using OpenTelemetry Metrics API: - Created mellea/telemetry/metrics.py with: - Lazy MeterProvider initialization (similar to tracing pattern) - Environment-based configuration (MELLEA_METRICS_ENABLED, MELLEA_METRICS_CONSOLE) - Zero overhead when disabled (no-op instrument classes) - Named meter: mellea.metrics - Instrument creation helpers: - create_counter() - for monotonically increasing values - create_histogram() - for value distributions - create_up_down_counter() - for values that can increase/decrease - Updated mellea/telemetry/__init__.py to export metrics functions Environment Variables: - MELLEA_METRICS_ENABLED (default: false) - Enable metrics collection - MELLEA_METRICS_CONSOLE (default: false) - Print metrics to console Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Fixes test failures after f449d9a moved tracing code to submodule. Test fixtures now reload mellea.telemetry.tracing to pick up env var changes. Also moved test file to test/telemetry/test_tracing.py to mirror source structure. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Comprehensive test coverage for metrics configuration, lazy initialization, instrument creation, no-op behavior, and functional operations. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
After moving tracing code from __init__.py to tracing.py, the test fixture needs to import from mellea.telemetry.tracing instead of mellea.telemetry. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
|
Opening this with what I have at EOD for peer review, I want to spend more time re-reviewing this myself before final merge as it was primarily ai generated and I've only done one manual review pass so far |
…validation Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Replace hardcoded version strings with importlib.metadata.version() Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
|
I've pushed a couple commits handling review feedback from a couple more ai assistants. This is now ready for review, approval, and merge. |
planetf1
left a comment
There was a problem hiding this comment.
Just one comment on verification of metrics. Otherwise LGTM
|
I have a follow up PR for #462 almost ready once this is merged (I just need to finish updating the docs before opening it) |
|
I tagged a few people directly to try and get this reviewed and merged to unblock the followup PR before its ready tomorrow morning |
psschwei
left a comment
There was a problem hiding this comment.
One possible issue (flagged by one AI but not others), but otherwise LGTM
Switched from lazy to eager initialization to match tracing module pattern and prevent potential threading issues. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
78c5aab
Misc PR
Type of PR
Description
Implemented OpenTelemetry metrics support for Mellea:
Changes:
__init__.pyto dedicatedtracing.pymodule for better organizationmellea/telemetry/metrics.pywith full OpenTelemetry metrics support including:Testing:
test/telemetry/test_metrics.pywith extensive coverage of metric creation, recording, and exportThe implementation follows OpenTelemetry standards and integrates seamlessly with Mellea's existing tracing infrastructure.
Testing