Added OTel instrumentation and metrics export for sync client#3954
Added OTel instrumentation and metrics export for sync client#3954vladvildanov merged 39 commits intomasterfrom
Conversation
* Added intrastructure and integration point with OTel * Added check for enabled metric groups * Applied comments
* Added stadalone client metrics export * Added support for cluster client * Removed unused dispatchers and test
* Added stadalone client metrics export * Added support for cluster client * Added error metric export on fail commands for standalone client * Removed unused dispatchers and test * Added on error metrics export for cluster * Added export of maint notification count metric * Apply comments * Remove redundant Union
* Added export of connection basic metrics * Added new error category attribute * Update tests/test_observability/test_recorder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/test_observability/test_recorder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply comments * Applied comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Added export of connection basic metrics * Added new error category attribute * Added pub/sub and stream lag metrics export * Added metric export form XREAD * Update redis/client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/event.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Applied comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Added export of connection basic metrics * Added new error category attribute * Added pub/sub and stream lag metrics export * Added metric export form XREAD * Added benchmark tests * Added error output * Added env variable for otel host * Fixed endpoint * Added iterations and results averaging * Use unsecured gRPC * Added --with-command-metrics argument * Removed incorrect identation * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Added export of connection advanced metrics * Update tests/test_connection_pool.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/observability/metrics.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactored kwargs instead of args --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Added export of connection advanced metrics * Added CSC metrics export * Revert changes * Added observable gauge registry and refactored observables metric export * Fixed case with trackin non-cachable cache tracking
* Added full benchmark tests + fixes * Added Memory and CPU usage calculation
…3934) * Removed events dispatching overhead, refactored metrics attributes * Fixed incorrect retry attempts, changed indexes to named parameters * Fixed issue with connection attribute and metric recording
* Added async recorders and registry * Removed async registry * Added more coverage
* Added async recorders and registry * Added bucket override configuration * Removed async registry * Added more coverage * Fixed version constraints, removed ubused imports * Moved module desription on top of file
elena-kolevska
left a comment
There was a problem hiding this comment.
We need to use standard UCUM units, as defined in the SemConv
Signed-off-by: Elena Kolevska <elena@kolevska.com>
f433178 to
453101d
Compare
Signed-off-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>
|
augment review |
|
This pull request is too large for Augment to review. The PR exceeds the maximum size limit of 100000 tokens (approximately 400000 characters) for automated code review. Please consider breaking this PR into smaller, more focused changes. |
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive OpenTelemetry (OTel) instrumentation to redis-py, enabling automatic metrics collection for Redis operations. The implementation follows a singleton pattern where observability is initialized once globally, and all Redis clients automatically collect metrics.
Changes:
- Adds new
redis/observabilitymodule with configuration, metrics collection, and provider management - Integrates metrics recording into command execution, connection management, PubSub, streaming, and caching
- Adds error type categorization to exceptions for better error metrics
- Updates retry mechanism to support failure count tracking
- Fixes test assertions to use
e.valueinstead ofstr(e) - Adds comprehensive unit and integration tests for metrics recording
Reviewed changes
Copilot reviewed 39 out of 41 changed files in this pull request and generated 37 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_ssl.py | Fixed pytest assertions to use e.value instead of str(e) |
| tests/test_search.py | Fixed pytest assertions to use e.value instead of str(e) |
| tests/test_pubsub.py | Fixed assertions + added metrics recording tests for PubSub |
| tests/test_pipeline.py | Added comprehensive metrics recording tests for Pipeline |
| tests/test_maint_notifications.py | Updated tests for new notification signature + metrics tests |
| tests/test_credentials.py | Added connection attributes (host, port, db) to mock connections |
| tests/test_connection_pool.py | Added tests for connection count observability |
| tests/test_connection.py | Added tests for connection pool methods and CSC metrics |
| tests/test_cluster_transaction.py | Added metrics recording tests for cluster transactions |
| tests/test_cluster.py | Added comprehensive cluster and pipeline metrics tests |
| tests/test_client.py | New file with Redis client metrics recording tests |
| tests/test_cache.py | Added CacheProxy tests for CSC eviction metrics |
| tests/test_observability/*.py | New unit tests for observability modules |
| redis/observability/*.py | New observability module with config, metrics, providers, attributes, registry |
| redis/client.py | Integrated metrics recording into command execution and PubSub |
| redis/connection.py | Added connection metrics and CSC metrics recording |
| redis/cache.py | Added CacheProxy for eviction metrics |
| redis/cluster.py | Integrated metrics for cluster operations |
| redis/event.py | Added connection count observability initialization |
| redis/exceptions.py | Added error type categorization |
| redis/retry.py | Added failure count support |
| redis/maint_notifications.py | Added maintenance notification metrics |
| redis/commands/core.py | Added PubSub and streaming metrics |
| pyproject.toml | Added otel optional dependencies |
| docs/opentelemetry.rst | Added comprehensive documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Description of change
This PR adds optional OpenTelemetry (OTel) instrumentation to redis-py, enabling automatic metrics collection and export for Redis operations. The implementation follows a singleton pattern where observability is initialised once globally, and all Redis clients automatically collect metrics without additional configuration.
It provides:
How to Enable
Install OTel dependencies:
Set up your OTel exporter and initialize redis-py observability:
Configure your OTel exporter
Initialize redis-py observability (once at app startup)
All Redis clients now automatically collect metrics
Optional: Customise metric groups:
Pull Request check-list
Please make sure to review and check all of these items: