Skip to content

Commit 8995916

Browse files
committed
initial find and replace along with integration docs mods
rn chore(iast): taint parameter name in post requests in fastapi (#12038) Continuation of #12009 - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - 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) still expose patch_all since it's just deprecated change imports for _patch_all clean up where it's called in strings fix up more tests
1 parent e294f47 commit 8995916

File tree

20 files changed

+55
-71
lines changed

20 files changed

+55
-71
lines changed

Diff for: benchmarks/ddtrace_run/scenario.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def run(self):
2222

2323
# initialize subprocess args
2424
subp_cmd = []
25-
code = "import ddtrace; ddtrace.patch_all()\n"
25+
code = "import ddtrace; ddtrace._monkey._patch_all()\n"
2626
if self.ddtrace_run:
2727
subp_cmd = ["ddtrace-run"]
2828
code = ""

Diff for: ddtrace/bootstrap/preload.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _(_):
8787
LLMObs.enable()
8888

8989
if asbool(os.getenv("DD_TRACE_ENABLED", default=True)):
90-
from ddtrace import patch_all
90+
from ddtrace._monkey import _patch_all
9191

9292
@register_post_preload
9393
def _():
@@ -97,7 +97,7 @@ def _():
9797
modules_to_patch = os.getenv("DD_PATCH_MODULES")
9898
modules_to_str = parse_tags_str(modules_to_patch)
9999
modules_to_bool = {k: asbool(v) for k, v in modules_to_str.items()}
100-
patch_all(**modules_to_bool)
100+
_patch_all(**modules_to_bool)
101101

102102
if config._trace_methods:
103103
_install_trace_methods(config._trace_methods)

Diff for: ddtrace/contrib/_aws_lambda.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
~~~~~~~~~~~~~~~~~~~~
1515
1616
This integration is configured automatically. The `datadog_lambda` package
17-
calls ``patch_all`` when ``DD_TRACE_ENABLED`` is set to ``true``.
17+
calls ``_patch_all`` when ``DD_TRACE_ENABLED`` is set to ``true``.
1818
It's not recommended to call ``patch`` for it manually. Since it would not do
1919
anything for other environments that do not meet the criteria above.
2020

Diff for: ddtrace/contrib/_httplib.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88
99
The httplib integration is disabled by default. It can be enabled when using
1010
:ref:`ddtrace-run<ddtracerun>` or :ref:`import ddtrace.auto<ddtraceauto>`
11-
using the ``DD_TRACE_HTTPLIB_ENABLED`` environment variable::
11+
using the `DD_PATCH_MODULES` environment variable::
1212
13-
DD_TRACE_HTTPLIB_ENABLED=true ddtrace-run ....
14-
15-
The integration can also be enabled manually in code with
16-
:func:`patch_all()<ddtrace.patch_all>`::
17-
18-
from ddtrace import patch_all
19-
patch_all(httplib=True)
13+
DD_PATCH_MODULES=httplib:true ddtrace-run ....
2014
2115
2216
Global Configuration

Diff for: ddtrace/contrib/_kombu.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Instrument kombu to report AMQP messaging.
22
3-
``patch_all`` will not automatically patch your Kombu client to make it work, as this would conflict with the
3+
ref:`import ddtrace.auto<ddtraceauto>` and `ddtrace-run` will not automatically patch your Kombu client to
4+
make it work, as this would conflict with the
45
Celery integration. You must specifically request kombu be patched, as in the example below.
56
67
Note: To permit distributed tracing for the kombu integration you must enable the tracer with priority
@@ -9,10 +10,9 @@
910
1011
Without enabling distributed tracing, spans within a trace generated by the kombu integration might be dropped
1112
without the whole trace being dropped.
12-
::
13-
14-
from ddtrace import patch
15-
from ddtrace.trace import Pin
13+
Run with `DD_PATCH_MODULES=kombu:true`::
14+
import ddtrace.auto
15+
from ddtrace import Pin
1616
import kombu
1717
1818
# If not patched yet, you can patch kombu specifically

Diff for: ddtrace/contrib/_sanic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
99
Sanic tracing can also be enabled explicitly::
1010
11-
from ddtrace import patch_all
12-
patch_all(sanic=True)
11+
import ddtrace.auto
1312
1413
from sanic import Sanic
1514
from sanic.response import text

Diff for: ddtrace/contrib/_snowflake.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@
99
The integration is not enabled automatically when using
1010
:ref:`ddtrace-run<ddtracerun>` or :ref:`import ddtrace.auto<ddtraceauto>`.
1111
12-
Use ``DD_TRACE_SNOWFLAKE_ENABLED=true`` to enable it with ``ddtrace-run``
13-
14-
or :func:`patch()<ddtrace.patch>` to manually enable the integration::
15-
16-
from ddtrace import patch
17-
patch(snowflake=True)
18-
19-
or use :func:`patch_all()<ddtrace.patch_all>` to manually enable the integration::
20-
21-
from ddtrace import patch_all
22-
patch_all(snowflake=True)
23-
24-
12+
Use environment variable `DD_PATCH_MODULES:snowflake:true` to manually enable the integration::
2513
2614
2715
Global Configuration

Diff for: ddtrace/contrib/_urllib3.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
Enabling
77
~~~~~~~~
88
9-
The ``urllib3`` integration is not enabled by default. Use ``patch_all()``
10-
with the environment variable ``DD_TRACE_URLLIB3_ENABLED`` set, or call
11-
:func:`patch()<ddtrace.patch>` with the ``urllib3`` argument set to ``True`` to manually
12-
enable the integration, before importing and using ``urllib3``::
13-
14-
from ddtrace import patch
15-
patch(urllib3=True)
9+
The ``urllib3`` integration is not enabled by default. Use either ``ddtrace-run``
10+
or ``import ddtrace.auto`` with ``DD_PATCH_MODULES`` to enable it.
11+
``DD_PATCH_MODULES=urllib3 ddtrace-run python app.py`` or
12+
``DD_PATCH_MODULES=urllib3:true python app.py``::
1613
14+
import ddtrace.auto
1715
# use urllib3 like usual
1816
1917

Diff for: ddtrace/contrib/internal/pytest/plugin.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
DDTRACE_HELP_MSG = "Enable tracing of pytest functions."
3838
NO_DDTRACE_HELP_MSG = "Disable tracing of pytest functions."
3939
DDTRACE_INCLUDE_CLASS_HELP_MSG = "Prepend 'ClassName.' to names of class-based tests."
40-
PATCH_ALL_HELP_MSG = "Call ddtrace.patch_all before running tests."
40+
PATCH_ALL_HELP_MSG = "Call ddtrace._patch_all before running tests."
4141

4242

4343
def is_enabled(config):
@@ -172,7 +172,7 @@ def patch_all(request):
172172
"""Patch all available modules for Datadog tracing when ddtrace-patch-all
173173
is specified in command or .ini.
174174
"""
175-
import ddtrace
176-
177175
if request.config.getoption("ddtrace-patch-all") or request.config.getini("ddtrace-patch-all"):
178-
ddtrace.patch_all()
176+
from ddtrace._monkey import _patch_all
177+
178+
_patch_all()

Diff for: docs/api.rst

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Tracing
99
1010
.. automodule:: ddtrace.auto
1111

12-
.. autofunction:: ddtrace.patch_all
13-
1412
.. autofunction:: ddtrace.patch
1513

1614
.. autoclass:: ddtrace.trace.Tracer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
deprecations:
3+
- |
4+
tracer: ``patch_all`` is deprecated and will be removed in 3.0. As an alternative to ``patch_all``, you can use ``import ddtrace.auto`` along with ``DD_PATCH_MODULES`` if specific module patching is necessary.

Diff for: tests/appsec/iast/fixtures/entrypoint/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def add_test():
2222

2323

2424
def create_app_patch_all():
25-
from ddtrace import patch_all
25+
from ddtrace._monkey import _patch_all
2626

27-
patch_all()
27+
_patch_all()
2828
app = Flask(__name__)
2929
return app
3030

Diff for: tests/commands/test_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_dogstatsd_client_env_url_path(self):
144144

145145
def test_patch_modules_from_env(self):
146146
"""
147-
DD_PATCH_MODULES overrides the defaults for patch_all()
147+
DD_PATCH_MODULES overrides the defaults for _patch_all()
148148
"""
149149
with self.override_env(
150150
env=dict(

Diff for: tests/contrib/algoliasearch/test.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ddtrace import config
2-
from ddtrace import patch_all
2+
from ddtrace._monkey import _patch_all
33
from ddtrace.contrib.internal.algoliasearch.patch import algoliasearch_version
44
from ddtrace.contrib.internal.algoliasearch.patch import patch
55
from ddtrace.contrib.internal.algoliasearch.patch import unpatch
@@ -156,7 +156,7 @@ def test_patch_unpatch(self):
156156
assert len(spans) == 1
157157

158158
def test_patch_all_auto_enable(self):
159-
patch_all()
159+
_patch_all()
160160
Pin.override(self.index, tracer=self.tracer)
161161
self.perform_search("test search")
162162

@@ -178,7 +178,7 @@ def test_user_specified_service_default(self):
178178
When a service name is specified by the user
179179
The algoliasearch integration shouldn't use it as the service name
180180
"""
181-
patch_all()
181+
_patch_all()
182182
Pin.override(self.index, tracer=self.tracer)
183183
self.perform_search("test search")
184184
spans = self.get_spans()
@@ -194,7 +194,7 @@ def test_user_specified_service_v0(self):
194194
When a service name is specified by the user
195195
The algoliasearch integration shouldn't use it as the service name
196196
"""
197-
patch_all()
197+
_patch_all()
198198
Pin.override(self.index, tracer=self.tracer)
199199
self.perform_search("test search")
200200
spans = self.get_spans()
@@ -210,7 +210,7 @@ def test_user_specified_service_v1(self):
210210
In the v1 service name schema, services default to $DD_SERVICE,
211211
so make sure that is used and not the v0 schema 'algoliasearch'
212212
"""
213-
patch_all()
213+
_patch_all()
214214
Pin.override(self.index, tracer=self.tracer)
215215
self.perform_search("test search")
216216
spans = self.get_spans()
@@ -222,7 +222,7 @@ def test_user_specified_service_v1(self):
222222

223223
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_TRACE_SPAN_ATTRIBUTE_SCHEMA="v0"))
224224
def test_span_name_v0_schema(self):
225-
patch_all()
225+
_patch_all()
226226
Pin.override(self.index, tracer=self.tracer)
227227
self.perform_search("test search")
228228
spans = self.get_spans()
@@ -234,7 +234,7 @@ def test_span_name_v0_schema(self):
234234

235235
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_TRACE_SPAN_ATTRIBUTE_SCHEMA="v1"))
236236
def test_span_name_v1_schema(self):
237-
patch_all()
237+
_patch_all()
238238
Pin.override(self.index, tracer=self.tracer)
239239
self.perform_search("test search")
240240
spans = self.get_spans()

Diff for: tests/contrib/django/test_django.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,8 @@ def test_django_use_handler_resource_format_env(client, test_spans):
20182018
"python",
20192019
"-c",
20202020
(
2021-
"from ddtrace import config, patch_all; patch_all(); "
2021+
"from ddtrace import config "
2022+
"from ddtrace._monkey import _patch_all; _patch_all(); "
20222023
"import django; "
20232024
"assert config.django.use_handler_resource_format; print('Test success')"
20242025
),
@@ -2037,7 +2038,8 @@ def test_django_use_handler_with_url_name_resource_format_env(client, test_spans
20372038
"python",
20382039
"-c",
20392040
(
2040-
"from ddtrace import config, patch_all; patch_all(); "
2041+
"from ddtrace import config "
2042+
"from ddtrace._monkey import _patch_all; _patch_all(); "
20412043
"import django; "
20422044
"assert config.django.use_handler_with_url_name_resource_format; print('Test success')"
20432045
),
@@ -2117,7 +2119,8 @@ def test_django_use_legacy_resource_format_env(client, test_spans):
21172119
"python",
21182120
"-c",
21192121
(
2120-
"from ddtrace import config, patch_all; patch_all(); "
2122+
"from ddtrace import config "
2123+
"from ddtrace._monkey import _patch_all; _patch_all(); "
21212124
"import django; "
21222125
"assert config.django.use_legacy_resource_format; print('Test success')"
21232126
),

Diff for: tests/contrib/psycopg/test_psycopg_snapshot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_connect_traced_via_env(run_python_code_in_subprocess):
7272
import ddtrace
7373
from tests.contrib.config import POSTGRES_CONFIG
7474
75-
ddtrace.patch_all()
75+
ddtrace._monkey._patch_all()
7676
7777
conn = psycopg.connect(**POSTGRES_CONFIG)
7878
assert conn

Diff for: tests/contrib/psycopg2/test_psycopg.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ def test_manual_wrap_extension_adapt(self):
247247

248248
@skipIf(PSYCOPG2_VERSION < (2, 7), "quote_ident not available in psycopg2<2.7")
249249
def test_manual_wrap_extension_quote_ident(self):
250-
from ddtrace import patch_all
250+
from ddtrace._monkey import _patch_all
251251

252-
patch_all()
252+
_patch_all()
253253
from psycopg2.extensions import quote_ident
254254

255255
# NOTE: this will crash if it doesn't work.
@@ -497,9 +497,9 @@ def test_postgres_dbm_propagation_comment(self):
497497

498498
@skipIf(PSYCOPG2_VERSION < (2, 7), "quote_ident not available in psycopg2<2.7")
499499
def test_manual_wrap_extension_quote_ident_standalone():
500-
from ddtrace import patch_all
500+
from ddtrace._monkey import _patch_all
501501

502-
patch_all()
502+
_patch_all()
503503
from psycopg2.extensions import quote_ident
504504

505505
# NOTE: this will crash if it doesn't work.

Diff for: tests/contrib/psycopg2/test_psycopg_snapshot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_connect_traced_via_env(run_python_code_in_subprocess):
5454
import ddtrace
5555
from tests.contrib.config import POSTGRES_CONFIG
5656
57-
ddtrace.patch_all()
57+
ddtrace._monkey._patch_all()
5858
5959
conn = psycopg2.connect(**POSTGRES_CONFIG)
6060
assert conn

Diff for: tests/contrib/starlette/test_starlette.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,17 @@ def test_incorrect_patching(run_python_code_in_subprocess):
497497
from starlette.testclient import TestClient
498498
import sqlalchemy
499499
500-
from ddtrace import patch_all
500+
from ddtrace._monkey import _patch_all
501501
502502
503503
from tests.contrib.starlette.app import get_app
504504
505505
engine = sqlalchemy.create_engine("sqlite:///test.db")
506506
app = get_app(engine)
507507
508-
# Calling patch_all late
508+
# Calling _patch_all late
509509
# DEV: The test client uses `requests` so we want to ignore them for this scenario
510-
patch_all(requests=False, http=False)
510+
_patch_all(requests=False, http=False)
511511
with TestClient(app) as test_client:
512512
r = test_client.get("/200")
513513

Diff for: tests/tracer/test_monkey.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class TestPatching(SubprocessTestCase):
1717
@run_in_subprocess(env_overrides=dict())
1818
def test_patch_all_env_override_sqlite_none(self):
1919
# Make sure sqlite is enabled by default.
20-
_monkey.patch_all()
20+
_monkey._patch_all()
2121
assert "sqlite3" in _monkey._PATCHED_MODULES
2222

2323
@run_in_subprocess(env_overrides=dict(DD_TRACE_SQLITE3_ENABLED="false"))
2424
def test_patch_all_env_override_sqlite_disabled(self):
25-
_monkey.patch_all()
25+
_monkey._patch_all()
2626
assert "sqlite3" not in _monkey._PATCHED_MODULES
2727

2828
@run_in_subprocess(env_overrides=dict(DD_TRACE_SQLITE3_ENABLED="false"))
@@ -46,12 +46,12 @@ def test_patch_raise_exception_manual_patch(self):
4646
@run_in_subprocess(env_overrides=dict())
4747
def test_patch_all_env_override_httplib_none(self):
4848
# Make sure httplib is disabled by default.
49-
_monkey.patch_all()
49+
_monkey._patch_all()
5050
assert "httplib" not in _monkey._PATCHED_MODULES
5151

5252
@run_in_subprocess(env_overrides=dict(DD_TRACE_HTTPLIB_ENABLED="true"))
5353
def test_patch_all_env_override_httplib_enabled(self):
54-
_monkey.patch_all()
54+
_monkey._patch_all()
5555
assert "httplib" in _monkey._PATCHED_MODULES
5656

5757
@run_in_subprocess()

0 commit comments

Comments
 (0)