Skip to content

Commit

Permalink
chore(django): disable middleware,db,cache,and template spans by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Feb 4, 2025
1 parent 1245846 commit d0f9af2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ddtrace/contrib/_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,31 @@
Can also be enabled with the ``DD_DJANGO_INSTRUMENT_MIDDLEWARE`` environment variable.
Default: ``True``
Default: ``False``
.. py:data:: ddtrace.config.django['instrument_templates']
Whether or not to instrument template rendering.
Can also be enabled with the ``DD_DJANGO_INSTRUMENT_TEMPLATES`` environment variable.
Default: ``True``
Default: ``False``
.. py:data:: ddtrace.config.django['instrument_databases']
Whether or not to instrument databases.
Can also be enabled with the ``DD_DJANGO_INSTRUMENT_DATABASES`` environment variable.
Default: ``True``
Default: ``False``
.. py:data:: ddtrace.config.django['instrument_caches']
Whether or not to instrument caches.
Can also be enabled with the ``DD_DJANGO_INSTRUMENT_CACHES`` environment variable.
Default: ``True``
Default: ``False``
.. py:data:: ddtrace.config.django.http['trace_query_string']
Expand Down
8 changes: 4 additions & 4 deletions ddtrace/contrib/internal/django/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
database_service_name=os.getenv("DD_DJANGO_DATABASE_SERVICE_NAME", default=""),
trace_fetch_methods=asbool(os.getenv("DD_DJANGO_TRACE_FETCH_METHODS", default=False)),
distributed_tracing_enabled=True,
instrument_middleware=asbool(os.getenv("DD_DJANGO_INSTRUMENT_MIDDLEWARE", default=True)),
instrument_templates=asbool(os.getenv("DD_DJANGO_INSTRUMENT_TEMPLATES", default=True)),
instrument_databases=asbool(os.getenv("DD_DJANGO_INSTRUMENT_DATABASES", default=True)),
instrument_caches=asbool(os.getenv("DD_DJANGO_INSTRUMENT_CACHES", default=True)),
instrument_middleware=asbool(os.getenv("DD_DJANGO_INSTRUMENT_MIDDLEWARE", default=False)),
instrument_templates=asbool(os.getenv("DD_DJANGO_INSTRUMENT_TEMPLATES", default=False)),
instrument_databases=asbool(os.getenv("DD_DJANGO_INSTRUMENT_DATABASES", default=False)),
instrument_caches=asbool(os.getenv("DD_DJANGO_INSTRUMENT_CACHES", default=False)),
analytics_enabled=None, # None allows the value to be overridden by the global config
analytics_sample_rate=None,
trace_query_string=None, # Default to global config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
upgrade:
- |
django: The following configurations are now disabled by default. To enable django middleware,
templates, databases, and/or caches spans, set the following environment variables to `true`:
- DD_DJANGO_INSTRUMENT_MIDDLEWARE
- DD_DJANGO_INSTRUMENT_TEMPLATES
- DD_DJANGO_INSTRUMENT_DATABASES
- DD_DJANGO_INSTRUMENT_CACHES
36 changes: 36 additions & 0 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
env={
"DD_CIVISIBILITY_ITR_ENABLED": "0",
"DD_IAST_REQUEST_SAMPLING": "100", # Override default 30% to analyze all IAST requests
# With ddtrace>=3.0 django middleware, db, cache, and template instrumentation are opt-in
# Setting these environment variables to true in riot will allow us to roll out this change
# without updating very single test.
"DD_DJANGO_INSTRUMENT_MIDDLEWARE": "true",
"DD_DJANGO_INSTRUMENT_TEMPLATES": "true",
"DD_DJANGO_INSTRUMENT_DATABASES": "true",
"DD_DJANGO_INSTRUMENT_CACHES": "true",
},
venvs=[
Venv(
Expand Down Expand Up @@ -773,6 +780,17 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"pytest-randomly": latest,
"setuptools": latest,
},
env={
"DD_CIVISIBILITY_ITR_ENABLED": "0",
"DD_IAST_REQUEST_SAMPLING": "100", # Override default 30% to analyze all IAST requests
# With ddtrace>=3.0 django middleware, db, cache, and template instrumentation are opt-in
# Setting these environment variables to true in riot will allow us to roll out this change
# without updating very single test.
"DD_DJANGO_INSTRUMENT_MIDDLEWARE": "true",
"DD_DJANGO_INSTRUMENT_TEMPLATES": "true",
"DD_DJANGO_INSTRUMENT_DATABASES": "true",
"DD_DJANGO_INSTRUMENT_CACHES": "true",
},
venvs=[
Venv(
pys=select_pys(min_version="3.8"),
Expand All @@ -797,6 +815,15 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"pytest-django[testing]": "==3.10.0",
"pytest-randomly": latest,
},
# With ddtrace>=3.0 django middleware, db, cache, and template instrumentation are opt-in
# Setting these environment variables to true in riot will allow us to roll out this change
# without updating very single test.
env={
"DD_DJANGO_INSTRUMENT_MIDDLEWARE": "true",
"DD_DJANGO_INSTRUMENT_TEMPLATES": "true",
"DD_DJANGO_INSTRUMENT_DATABASES": "true",
"DD_DJANGO_INSTRUMENT_CACHES": "true",
}
venvs=[
Venv(
# djangorestframework dropped support for Django 2.x in 3.14
Expand Down Expand Up @@ -836,6 +863,15 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"typing-extensions": latest,
"pytest-randomly": latest,
},
# With ddtrace>=3.0 django middleware, db, cache, and template instrumentation are opt-in
# Setting these environment variables to true in riot will allow us to roll out this change
# without updating very single test.
env={
"DD_DJANGO_INSTRUMENT_MIDDLEWARE": "true",
"DD_DJANGO_INSTRUMENT_TEMPLATES": "true",
"DD_DJANGO_INSTRUMENT_DATABASES": "true",
"DD_DJANGO_INSTRUMENT_CACHES": "true",
}
venvs=[
Venv(
pys=select_pys(min_version="3.8", max_version="3.11"),
Expand Down

0 comments on commit d0f9af2

Please sign in to comment.