Skip to content

Commit 5434666

Browse files
authored
Revert "chore(yaaredis): remove yaaredis support" (#12480)
- [x] Reverts #12226
1 parent 0d29368 commit 5434666

File tree

39 files changed

+1598
-4
lines changed

39 files changed

+1598
-4
lines changed

.riot/requirements/1761702.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/1761702.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.4
9+
exceptiongroup==1.2.0
10+
hypothesis==6.45.0
11+
iniconfig==2.0.0
12+
mock==5.1.0
13+
opentracing==2.4.0
14+
packaging==23.2
15+
pluggy==1.3.0
16+
pytest==7.4.3
17+
pytest-asyncio==0.21.1
18+
pytest-cov==4.1.0
19+
pytest-mock==3.12.0
20+
pytest-randomly==3.15.0
21+
sortedcontainers==2.4.0
22+
tomli==2.0.1
23+
yaaredis==3.0.0

.riot/requirements/1cc7b0e.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/1cc7b0e.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.4
9+
exceptiongroup==1.2.0
10+
hypothesis==6.45.0
11+
importlib-metadata==7.0.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
opentracing==2.4.0
15+
packaging==23.2
16+
pluggy==1.3.0
17+
pytest==7.4.3
18+
pytest-asyncio==0.21.1
19+
pytest-cov==4.1.0
20+
pytest-mock==3.12.0
21+
pytest-randomly==3.15.0
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1
24+
yaaredis==2.0.4
25+
zipp==3.17.0

.riot/requirements/1f1e9b4.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/1f1e9b4.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.4
9+
exceptiongroup==1.2.0
10+
hypothesis==6.45.0
11+
importlib-metadata==7.0.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
opentracing==2.4.0
15+
packaging==23.2
16+
pluggy==1.3.0
17+
pytest==7.4.3
18+
pytest-asyncio==0.21.1
19+
pytest-cov==4.1.0
20+
pytest-mock==3.12.0
21+
pytest-randomly==3.15.0
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1
24+
yaaredis==3.0.0
25+
zipp==3.17.0

.riot/requirements/9b8251b.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/9b8251b.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.4
9+
exceptiongroup==1.2.0
10+
hypothesis==6.45.0
11+
importlib-metadata==7.0.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
opentracing==2.4.0
15+
packaging==23.2
16+
pluggy==1.3.0
17+
pytest==7.4.3
18+
pytest-asyncio==0.21.1
19+
pytest-cov==4.1.0
20+
pytest-mock==3.12.0
21+
pytest-randomly==3.15.0
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1
24+
yaaredis==3.0.0
25+
zipp==3.17.0

.riot/requirements/fda8aa6.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/fda8aa6.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.4
9+
exceptiongroup==1.2.0
10+
hypothesis==6.45.0
11+
importlib-metadata==7.0.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
opentracing==2.4.0
15+
packaging==23.2
16+
pluggy==1.3.0
17+
pytest==7.4.3
18+
pytest-asyncio==0.21.1
19+
pytest-cov==4.1.0
20+
pytest-mock==3.12.0
21+
pytest-randomly==3.15.0
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1
24+
yaaredis==2.0.4
25+
zipp==3.17.0

ddtrace/_monkey.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"pyodbc": True,
9494
"fastapi": True,
9595
"dogpile_cache": True,
96+
"yaaredis": True,
9697
"asyncpg": True,
9798
"aws_lambda": True, # patch only in AWS Lambda environments
9899
"azure_functions": True,

ddtrace/contrib/_yaaredis.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
The yaaredis integration traces yaaredis requests.
3+
4+
5+
Enabling
6+
~~~~~~~~
7+
8+
The yaaredis integration is enabled automatically when using
9+
:ref:`ddtrace-run<ddtracerun>` or :ref:`import ddtrace.auto<ddtraceauto>`.
10+
11+
Or use :func:`patch()<ddtrace.patch>` to manually enable the integration::
12+
13+
from ddtrace import patch
14+
patch(yaaredis=True)
15+
16+
17+
Global Configuration
18+
~~~~~~~~~~~~~~~~~~~~
19+
20+
.. py:data:: ddtrace.config.yaaredis["service"]
21+
22+
The service name reported by default for yaaredis traces.
23+
24+
This option can also be set with the ``DD_YAAREDIS_SERVICE`` environment
25+
variable.
26+
27+
Default: ``"redis"``
28+
29+
.. py:data:: ddtrace.config.yaaredis["cmd_max_length"]
30+
31+
Max allowable size for the yaaredis command span tag.
32+
Anything beyond the max length will be replaced with ``"..."``.
33+
34+
This option can also be set with the ``DD_YAAREDIS_CMD_MAX_LENGTH`` environment
35+
variable.
36+
37+
Default: ``1000``
38+
39+
.. py:data:: ddtrace.config.aredis["resource_only_command"]
40+
41+
The span resource will only include the command executed. To include all
42+
arguments in the span resource, set this value to ``False``.
43+
44+
This option can also be set with the ``DD_REDIS_RESOURCE_ONLY_COMMAND`` environment
45+
variable.
46+
47+
Default: ``True``
48+
49+
50+
Instance Configuration
51+
~~~~~~~~~~~~~~~~~~~~~~
52+
53+
To configure particular yaaredis instances use the :class:`Pin <ddtrace.trace.Pin>` API::
54+
55+
import yaaredis
56+
from ddtrace.trace import Pin
57+
58+
client = yaaredis.StrictRedis(host="localhost", port=6379)
59+
60+
# Override service name for this instance
61+
Pin.override(client, service="my-custom-queue")
62+
63+
# Traces reported for this client will now have "my-custom-queue"
64+
# as the service name.
65+
async def example():
66+
await client.get("my-key")
67+
"""
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import os
2+
3+
import wrapt
4+
import yaaredis
5+
6+
from ddtrace import config
7+
from ddtrace._trace.utils_redis import _instrument_redis_cmd
8+
from ddtrace._trace.utils_redis import _instrument_redis_execute_pipeline
9+
from ddtrace.contrib.internal.redis_utils import _run_redis_command_async
10+
from ddtrace.internal.schema import schematize_service_name
11+
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
12+
from ddtrace.internal.utils.formats import CMD_MAX_LEN
13+
from ddtrace.internal.utils.formats import asbool
14+
from ddtrace.internal.utils.formats import stringify_cache_args
15+
from ddtrace.internal.utils.wrappers import unwrap
16+
from ddtrace.trace import Pin
17+
from ddtrace.vendor.debtcollector import deprecate
18+
19+
20+
config._add(
21+
"yaaredis",
22+
dict(
23+
_default_service=schematize_service_name("redis"),
24+
cmd_max_length=int(os.getenv("DD_YAAREDIS_CMD_MAX_LENGTH", CMD_MAX_LEN)),
25+
resource_only_command=asbool(os.getenv("DD_REDIS_RESOURCE_ONLY_COMMAND", True)),
26+
),
27+
)
28+
29+
30+
def get_version():
31+
# type: () -> str
32+
return getattr(yaaredis, "__version__", "")
33+
34+
35+
def patch():
36+
"""Patch the instrumented methods"""
37+
deprecate(
38+
prefix="The yaaredis module is deprecated.",
39+
message="The yaaredis module is deprecated and will be deleted.",
40+
category=DDTraceDeprecationWarning,
41+
removal_version="3.0.0",
42+
)
43+
44+
if getattr(yaaredis, "_datadog_patch", False):
45+
return
46+
yaaredis._datadog_patch = True
47+
48+
_w = wrapt.wrap_function_wrapper
49+
50+
_w("yaaredis.client", "StrictRedis.execute_command", traced_execute_command)
51+
_w("yaaredis.client", "StrictRedis.pipeline", traced_pipeline)
52+
_w("yaaredis.pipeline", "StrictPipeline.execute", traced_execute_pipeline)
53+
_w("yaaredis.pipeline", "StrictPipeline.immediate_execute_command", traced_execute_command)
54+
Pin().onto(yaaredis.StrictRedis)
55+
56+
57+
def unpatch():
58+
if getattr(yaaredis, "_datadog_patch", False):
59+
yaaredis._datadog_patch = False
60+
61+
unwrap(yaaredis.client.StrictRedis, "execute_command")
62+
unwrap(yaaredis.client.StrictRedis, "pipeline")
63+
unwrap(yaaredis.pipeline.StrictPipeline, "execute")
64+
unwrap(yaaredis.pipeline.StrictPipeline, "immediate_execute_command")
65+
66+
67+
async def traced_execute_command(func, instance, args, kwargs):
68+
pin = Pin.get_from(instance)
69+
if not pin or not pin.enabled():
70+
return await func(*args, **kwargs)
71+
72+
with _instrument_redis_cmd(pin, config.yaaredis, instance, args) as ctx:
73+
return await _run_redis_command_async(ctx=ctx, func=func, args=args, kwargs=kwargs)
74+
75+
76+
async def traced_pipeline(func, instance, args, kwargs):
77+
pipeline = await func(*args, **kwargs)
78+
pin = Pin.get_from(instance)
79+
if pin:
80+
pin.onto(pipeline)
81+
return pipeline
82+
83+
84+
async def traced_execute_pipeline(func, instance, args, kwargs):
85+
pin = Pin.get_from(instance)
86+
if not pin or not pin.enabled():
87+
return await func(*args, **kwargs)
88+
89+
cmds = [stringify_cache_args(c, cmd_max_len=config.yaaredis.cmd_max_length) for c, _ in instance.command_stack]
90+
with _instrument_redis_execute_pipeline(pin, config.yaaredis, cmds, instance):
91+
return await func(*args, **kwargs)

ddtrace/settings/_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
"grpc_client",
195195
"grpc_aio_client",
196196
"grpc_aio_server",
197+
"yaaredis",
197198
}
198199
)
199200

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ contacting support.
182182
+--------------------------------------------------+---------------+----------------+
183183
| :ref:`wsgi` | \* | No |
184184
+--------------------------------------------------+---------------+----------------+
185+
| :ref:`yaaredis` | >= 2.0.0 | Yes |
186+
+--------------------------------------------------+---------------+----------------+
185187

186188

187189
.. [1] Libraries that are automatically instrumented when the

0 commit comments

Comments
 (0)