Skip to content

Commit

Permalink
chore(tracing): deprecates FilterRequestsOnUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Jan 15, 2025
1 parent 21d50d4 commit d6f0509
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 53 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"]
18 changes: 9 additions & 9 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,23 +333,23 @@ all traces of incoming requests to a specific url::

from ddtrace import tracer

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
35 changes: 0 additions & 35 deletions tests/tracer/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
from unittest import TestCase

import pytest

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


class FilterRequestOnUrlTests(TestCase):
def test_is_match(self):
span = Span(name="Name")
span.set_tag(URL, r"http://example.com")
filtr = FilterRequestsOnUrl("http://examp.*.com")
trace = filtr.process_trace([span])
self.assertIsNone(trace)

def test_is_not_match(self):
span = Span(name="Name")
span.set_tag(URL, r"http://anotherexample.com")
filtr = FilterRequestsOnUrl("http://examp.*.com")
trace = filtr.process_trace([span])
self.assertIsNotNone(trace)

def test_list_match(self):
span = Span(name="Name")
span.set_tag(URL, r"http://anotherdomain.example.com")
filtr = FilterRequestsOnUrl([r"http://domain\.example\.com", r"http://anotherdomain\.example\.com"])
trace = filtr.process_trace([span])
self.assertIsNone(trace)

def test_list_no_match(self):
span = Span(name="Name")
span.set_tag(URL, r"http://cooldomain.example.com")
filtr = FilterRequestsOnUrl([r"http://domain\.example\.com", r"http://anotherdomain\.example\.com"])
trace = filtr.process_trace([span])
self.assertIsNotNone(trace)


def test_not_implemented_trace_filter():
class Filter(TraceFilter):
pass
Expand Down

0 comments on commit d6f0509

Please sign in to comment.