Skip to content

Commit 6de31a4

Browse files
fix(redis): remove circular import from redis integrations (#7794)
This change fixes #7783 by removing the imports of `contrib.redis` code from `contrib.yaaredis` and `contrib.aredis`. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. --------- Co-authored-by: William Conti <[email protected]>
1 parent c89c376 commit 6de31a4

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

ddtrace/contrib/aioredis/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from ...internal.utils.formats import asbool
2525
from ...internal.utils.formats import stringify_cache_args
2626
from .. import trace_utils
27-
from ..redis.asyncio_patch import _run_redis_command_async
2827
from ..trace_utils_redis import ROW_RETURNING_COMMANDS
28+
from ..trace_utils_redis import _run_redis_command_async
2929
from ..trace_utils_redis import _trace_redis_cmd
3030
from ..trace_utils_redis import _trace_redis_execute_pipeline
3131
from ..trace_utils_redis import determine_row_count

ddtrace/contrib/aredis/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ...internal.utils.formats import stringify_cache_args
1212
from ...internal.utils.wrappers import unwrap
1313
from ...pin import Pin
14-
from ..redis.asyncio_patch import _run_redis_command_async
14+
from ..trace_utils_redis import _run_redis_command_async
1515
from ..trace_utils_redis import _trace_redis_cmd
1616
from ..trace_utils_redis import _trace_redis_execute_pipeline
1717

ddtrace/contrib/redis/asyncio_patch.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from ddtrace import config
22

3-
from ...ext import db
43
from ...internal.utils.formats import stringify_cache_args
54
from ...pin import Pin
6-
from ..trace_utils_redis import ROW_RETURNING_COMMANDS
5+
from ..trace_utils_redis import _run_redis_command_async
76
from ..trace_utils_redis import _trace_redis_cmd
87
from ..trace_utils_redis import _trace_redis_execute_async_cluster_pipeline
98
from ..trace_utils_redis import _trace_redis_execute_pipeline
10-
from ..trace_utils_redis import determine_row_count
119

1210

1311
#
@@ -32,20 +30,6 @@ async def traced_async_execute_pipeline(func, instance, args, kwargs):
3230
return await func(*args, **kwargs)
3331

3432

35-
async def _run_redis_command_async(span, func, args, kwargs):
36-
parsed_command = stringify_cache_args(args)
37-
redis_command = parsed_command.split(" ")[0]
38-
try:
39-
result = await func(*args, **kwargs)
40-
if redis_command in ROW_RETURNING_COMMANDS:
41-
determine_row_count(redis_command=redis_command, span=span, result=result)
42-
return result
43-
except Exception:
44-
if redis_command in ROW_RETURNING_COMMANDS:
45-
span.set_metric(db.ROWCOUNT, 0)
46-
raise
47-
48-
4933
async def traced_async_execute_cluster_pipeline(func, instance, args, kwargs):
5034
pin = Pin.get_from(instance)
5135
if not pin or not pin.enabled():

ddtrace/contrib/trace_utils_redis.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,17 @@ def _trace_redis_execute_async_cluster_pipeline(pin, config_integration, cmds, i
168168
span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config_integration.get_analytics_sample_rate())
169169
# yield the span in case the caller wants to build on span
170170
yield span
171+
172+
173+
async def _run_redis_command_async(span, func, args, kwargs):
174+
parsed_command = stringify_cache_args(args)
175+
redis_command = parsed_command.split(" ")[0]
176+
try:
177+
result = await func(*args, **kwargs)
178+
if redis_command in ROW_RETURNING_COMMANDS:
179+
determine_row_count(redis_command=redis_command, span=span, result=result)
180+
return result
181+
except Exception:
182+
if redis_command in ROW_RETURNING_COMMANDS:
183+
span.set_metric(db.ROWCOUNT, 0)
184+
raise

ddtrace/contrib/yaaredis/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ...internal.utils.formats import stringify_cache_args
1212
from ...internal.utils.wrappers import unwrap
1313
from ...pin import Pin
14-
from ..redis.asyncio_patch import _run_redis_command_async
14+
from ..trace_utils_redis import _run_redis_command_async
1515
from ..trace_utils_redis import _trace_redis_cmd
1616
from ..trace_utils_redis import _trace_redis_execute_pipeline
1717

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
redis: This fix resolves an issue where the yaaredis and aredis integrations imported
5+
code from the redis integration, causing a circular import error.

0 commit comments

Comments
 (0)