Skip to content

Commit d173e34

Browse files
mitchh456claude
andauthored
Add Redis Cluster instrumentation support (#844)
* Use Job.id property instead of removed get_id() method rq v2.7 refactored Job.id from `id = property(get_id, set_id)` to a `@property` decorator, removing get_id() as a callable method. Job.id has been available since rq v0.5.0 so this is backwards compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Support FastMCP 3.x while maintaining 2.x backwards compatibility FastMCP 3.0 replaced private _call_tool_mcp()/_list_tools_mcp() with public call_tool()/list_tools() methods, and changed get_tool() to return None instead of raising when a tool is not found. - Update instrumentation to handle get_tool() returning None - Update tests with compat helpers that use the correct API based on the installed fastmcp version - Remove the fastmcp<3 version pin from tox.ini (no longer needed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add Redis Cluster instrumentation support Extend Redis instrumentation to cover RedisCluster.execute_command() when available, providing visibility into cluster operations including the new async Cluster PubSub feature in redis-py. Closes #840 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eb7c0e5 commit d173e34

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/scout_apm/instruments/redis.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@
1818
from redis import StrictRedis as Redis
1919
from redis.client import BasePipeline as Pipeline
2020

21+
try:
22+
from redis.cluster import RedisCluster
23+
except ImportError:
24+
RedisCluster = None
25+
2126
logger = logging.getLogger(__name__)
2227

2328

2429
have_patched_redis_execute_command = False
2530
have_patched_pipeline_execute = False
31+
have_patched_redis_cluster_execute_command = False
2632

2733

2834
def ensure_installed():
2935
global have_patched_redis_execute_command, have_patched_pipeline_execute
36+
global have_patched_redis_cluster_execute_command
3037

3138
logger.debug("Instrumenting redis.")
3239

@@ -55,6 +62,20 @@ def ensure_installed():
5562
else:
5663
have_patched_pipeline_execute = True
5764

65+
if RedisCluster is not None and not have_patched_redis_cluster_execute_command:
66+
try:
67+
RedisCluster.execute_command = wrapped_execute_command(
68+
RedisCluster.execute_command
69+
)
70+
except Exception as exc:
71+
logger.warning(
72+
"Failed to instrument redis.RedisCluster.execute_command: %r",
73+
exc,
74+
exc_info=exc,
75+
)
76+
else:
77+
have_patched_redis_cluster_execute_command = True
78+
5879
return True
5980

6081

0 commit comments

Comments
 (0)