Skip to content

Commit

Permalink
chore(tracing): deprecates FilterRequestsOnUrl [3.0] (#11962)
Browse files Browse the repository at this point in the history
In recent ddtrace versions spans can be sampled by tags and resource
names via the `DD_TRACE_SAMPLING_RULES` configuration. Setting this
configuration allows ddtrace to compute accurate trace metrics and
prevents the generation of partial traces.

To encourage the use of `DD_TRACE_SAMPLING_RULES`, `FilterRequestsOnUrl`
will be deprecated.


## Checklist
- [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))

## Reviewer Checklist
- [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)
  • Loading branch information
mabdinur authored Jan 16, 2025
1 parent b028cc6 commit 0275a5e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
5 changes: 0 additions & 5 deletions ddtrace/contrib/tornado/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ def log_exception(self, typ, value, tb):
'default_service': 'my-tornado-app',
'tags': {'env': 'production'},
'distributed_tracing': False,
'settings': {
'FILTERS': [
FilterRequestsOnUrl(r'http://test\\.example\\.com'),
],
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


deprecate(
"The ddtrace.filters module is deprecated and will be removed.",
message="Import ``TraceFilter`` and/or ``FilterRequestsOnUrl`` from the ddtrace.trace package.",
"The ddtrace.filters module and the ``FilterRequestsOnUrl`` class is deprecated and will be removed.",
message="Import ``TraceFilter`` from the ddtrace.trace package.",
category=DDTraceDeprecationWarning,
)
3 changes: 1 addition & 2 deletions ddtrace/trace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from ddtrace._trace.context import Context
from ddtrace._trace.filters import FilterRequestsOnUrl
from ddtrace._trace.filters import TraceFilter
from ddtrace._trace.pin import Pin


# TODO: Move `ddtrace.Tracer`, `ddtrace.Span`, and `ddtrace.tracer` to this module
__all__ = ["Context", "Pin", "TraceFilter", "FilterRequestsOnUrl"]
__all__ = ["Context", "Pin", "TraceFilter"]
19 changes: 10 additions & 9 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,25 @@ configuring the tracer with a filters list. For instance, to filter out
all traces of incoming requests to a specific url::

from ddtrace import tracer
from ddtrace.trace import TraceFilter

class FilterbyName(TraceFilter):
def process_trace(self, trace):
for span in trace:
if span.name == "some_name"
# drop the full trace chunk
return None
return trace

tracer.configure(settings={
'FILTERS': [
FilterRequestsOnUrl(r'http://test\.example\.com'),
FilterbyName(),
],
})

The filters in the filters list will be applied sequentially to each trace
and the resulting trace will either be sent to the Agent or discarded.

**Built-in filters**

The library comes with a ``FilterRequestsOnUrl`` filter that can be used to
filter out incoming requests to specific urls:

.. autoclass:: ddtrace.trace.FilterRequestsOnUrl
:members:

**Writing a custom filter**

Create a filter by implementing a class with a ``process_trace`` method and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
deprecations:
- |
tracing: Deprecates ``ddtrace.filters.FilterRequestsOnUrl``. Spans should be filtered/sampled using DD_TRACE_SAMPLING_RULES configuration.
2 changes: 1 addition & 1 deletion tests/tracer/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pytest

from ddtrace._trace.filters import FilterRequestsOnUrl
from ddtrace._trace.span import Span
from ddtrace.ext.http import URL
from ddtrace.trace import FilterRequestsOnUrl
from ddtrace.trace import TraceFilter


Expand Down

0 comments on commit 0275a5e

Please sign in to comment.