Skip to content

Commit f5239dd

Browse files
kaveEmanuele Palazzetti
authored andcommitted
[tornado] add settings object to set filters configurations (#498)
* [tornado] tracer needs the settings object to grab filter configurations * [tornado] namespace extra settings under `settings` for consistency with Tracer.configure()
1 parent f5a672d commit f5239dd

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

ddtrace/contrib/tornado/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def notify(self):
5555
'default_service': 'my-tornado-app',
5656
'tags': {'env': 'production'},
5757
'distributed_tracing': True,
58+
'settings': {
59+
'FILTERS': [
60+
FilterRequestsOnUrl(r'http://test\.example\.com'),
61+
],
62+
},
5863
},
5964
}
6065
@@ -74,6 +79,7 @@ def notify(self):
7479
We suggest to enable it only for internal services where headers are under your control.
7580
* ``agent_hostname`` (default: `localhost`): define the hostname of the APM agent.
7681
* ``agent_port`` (default: `8126`): define the port of the APM agent.
82+
* ``settings`` (default: ``{}``): Tracer extra settings used to change, for instance, the filtering behavior.
7783
"""
7884
from ...utils.importlib import require_modules
7985

ddtrace/contrib/tornado/application.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def tracer_config(__init__, app, args, kwargs):
3232
tracer = settings['tracer']
3333
service = settings['default_service']
3434

35+
# extract extra settings
36+
extra_settings = settings.get('settings', {})
37+
3538
# the tracer must use the right Context propagation and wrap executor;
3639
# this action is done twice because the patch() method uses the
3740
# global tracer while here we can have a different instance (even if
@@ -42,6 +45,7 @@ def tracer_config(__init__, app, args, kwargs):
4245
enabled=settings.get('enabled', None),
4346
hostname=settings.get('agent_hostname', None),
4447
port=settings.get('agent_port', None),
48+
settings=extra_settings,
4549
)
4650

4751
# set global tags if any

tests/contrib/tornado/test_config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from nose.tools import eq_
1+
from nose.tools import eq_, ok_
2+
3+
from ddtrace.filters import FilterRequestsOnUrl
24

35
from .utils import TornadoTestCase
46

@@ -17,6 +19,11 @@ def get_settings(self):
1719
'enabled': False,
1820
'agent_hostname': 'dd-agent.service.consul',
1921
'agent_port': 8126,
22+
'settings': {
23+
'FILTERS': [
24+
FilterRequestsOnUrl(r'http://test\.example\.com'),
25+
],
26+
},
2027
},
2128
}
2229

@@ -27,3 +34,7 @@ def test_tracer_is_properly_configured(self):
2734
eq_(self.tracer.enabled, False)
2835
eq_(self.tracer.writer.api.hostname, 'dd-agent.service.consul')
2936
eq_(self.tracer.writer.api.port, 8126)
37+
# settings are properly passed
38+
ok_(self.tracer.writer._filters is not None)
39+
eq_(len(self.tracer.writer._filters), 1)
40+
ok_(isinstance(self.tracer.writer._filters[0], FilterRequestsOnUrl))

0 commit comments

Comments
 (0)