From 0275a5ec8c1d01b9fd343f1e6753796ce010f6dc Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Thu, 16 Jan 2025 14:36:42 -0500 Subject: [PATCH] chore(tracing): deprecates FilterRequestsOnUrl [3.0] (#11962) 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) --- ddtrace/contrib/tornado/__init__.py | 5 ----- ddtrace/filters.py | 4 ++-- ddtrace/trace/__init__.py | 3 +-- docs/advanced_usage.rst | 19 ++++++++++--------- ...rcefilter-deprecated-52b1c92d388b0518.yaml | 4 ++++ tests/tracer/test_filters.py | 2 +- 6 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 releasenotes/notes/ddtrace-resourcefilter-deprecated-52b1c92d388b0518.yaml diff --git a/ddtrace/contrib/tornado/__init__.py b/ddtrace/contrib/tornado/__init__.py index ad0adef2dd5..10390e77e6e 100644 --- a/ddtrace/contrib/tornado/__init__.py +++ b/ddtrace/contrib/tornado/__init__.py @@ -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'), - ], - }, }, } diff --git a/ddtrace/filters.py b/ddtrace/filters.py index 3c9c42892b8..bd6367d5635 100644 --- a/ddtrace/filters.py +++ b/ddtrace/filters.py @@ -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, ) diff --git a/ddtrace/trace/__init__.py b/ddtrace/trace/__init__.py index dcd3aeb928e..72653598956 100644 --- a/ddtrace/trace/__init__.py +++ b/ddtrace/trace/__init__.py @@ -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"] diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rst index 9906fddea89..c1c41df00c0 100644 --- a/docs/advanced_usage.rst +++ b/docs/advanced_usage.rst @@ -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 diff --git a/releasenotes/notes/ddtrace-resourcefilter-deprecated-52b1c92d388b0518.yaml b/releasenotes/notes/ddtrace-resourcefilter-deprecated-52b1c92d388b0518.yaml new file mode 100644 index 00000000000..183249aa688 --- /dev/null +++ b/releasenotes/notes/ddtrace-resourcefilter-deprecated-52b1c92d388b0518.yaml @@ -0,0 +1,4 @@ +--- +deprecations: + - | + tracing: Deprecates ``ddtrace.filters.FilterRequestsOnUrl``. Spans should be filtered/sampled using DD_TRACE_SAMPLING_RULES configuration. diff --git a/tests/tracer/test_filters.py b/tests/tracer/test_filters.py index 871405517b7..d632ceb4998 100644 --- a/tests/tracer/test_filters.py +++ b/tests/tracer/test_filters.py @@ -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