Skip to content

Commit be743b9

Browse files
authored
Enable distributed tracing by default (#818)
* [flask] enable distributed tracing by default * [aiohttp] Enable distributed tracing by default * [bottle] Enable distributed tracing by default * [falcon] Enable distributed tracing by default * [molten] Ennable distributed tracing by default * [pylons] Enable distributed tracing by default * [pyramid] enable distributed tracing by default * [requests] Enable distributed tracing by default * [tornado] Enable distributed tracing by default * Update distributed tracing documentation * update docs
1 parent d2f5644 commit be743b9

32 files changed

+202
-105
lines changed

ddtrace/contrib/aiohttp/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
Integration settings are attached to your application under the ``datadog_trace``
2121
namespace. You can read or update them as follows::
2222
23-
# activates distributed tracing for all received requests
24-
app['datadog_trace']['distributed_tracing_enabled'] = True
23+
# disables distributed tracing for all received requests
24+
app['datadog_trace']['distributed_tracing_enabled'] = False
2525
2626
Available settings are:
2727
2828
* ``tracer`` (default: ``ddtrace.tracer``): set the default tracer instance that is used to
2929
trace `aiohttp` internals. By default the `ddtrace` tracer is used.
3030
* ``service`` (default: ``aiohttp-web``): set the service name used by the tracer. Usually
3131
this configuration must be updated with a meaningful name.
32-
* ``distributed_tracing_enabled`` (default: ``False``): enable distributed tracing during
32+
* ``distributed_tracing_enabled`` (default: ``True``): enable distributed tracing during
3333
the middleware execution, so that a new span is created with the given ``trace_id`` and
3434
``parent_id`` injected via request headers.
3535

ddtrace/contrib/aiohttp/middlewares.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def trace_app(app, tracer, service='aiohttp-web'):
117117
app[CONFIG_KEY] = {
118118
'tracer': tracer,
119119
'service': service,
120-
'distributed_tracing_enabled': False,
120+
'distributed_tracing_enabled': True,
121121
}
122122

123123
# the tracer must work with asynchronous Context propagation

ddtrace/contrib/bottle/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
app = bottle.Bottle()
1010
plugin = TracePlugin(service="my-web-app")
1111
app.install(plugin)
12-
13-
To enable distributed tracing::
14-
15-
plugin = TracePlugin(service="my-web-app", distributed_tracing=True)
1612
"""
1713

1814
from ...utils.importlib import require_modules

ddtrace/contrib/bottle/trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TracePlugin(object):
1717
name = 'trace'
1818
api = 2
1919

20-
def __init__(self, service='bottle', tracer=None, distributed_tracing=None):
20+
def __init__(self, service='bottle', tracer=None, distributed_tracing=True):
2121
self.service = service
2222
self.tracer = tracer or ddtrace.tracer
2323
self.distributed_tracing = distributed_tracing

ddtrace/contrib/falcon/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ddtrace import tracer
66
from ddtrace.contrib.falcon import TraceMiddleware
77
8-
mw = TraceMiddleware(tracer, 'my-falcon-app', distributed_tracing=True)
8+
mw = TraceMiddleware(tracer, 'my-falcon-app')
99
falcon.API(middleware=[mw])
1010
1111
You can also use the autopatching functionality::
@@ -17,8 +17,8 @@
1717
1818
app = falcon.API()
1919
20-
To enable distributed tracing when using autopatching, set the
21-
``DATADOG_FALCON_DISTRIBUTED_TRACING`` environment variable to ``True``.
20+
To disable distributed tracing when using autopatching, set the
21+
``DATADOG_FALCON_DISTRIBUTED_TRACING`` environment variable to ``False``.
2222
2323
**Supported span hooks**
2424

ddtrace/contrib/falcon/middleware.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class TraceMiddleware(object):
1313

14-
def __init__(self, tracer, service="falcon", distributed_tracing=False):
14+
def __init__(self, tracer, service="falcon", distributed_tracing=True):
1515
# store tracing references
1616
self.tracer = tracer
1717
self.service = service
@@ -23,7 +23,9 @@ def process_request(self, req, resp):
2323
headers = dict((k.lower(), v) for k, v in iteritems(req.headers))
2424
propagator = HTTPPropagator()
2525
context = propagator.extract(headers)
26-
self.tracer.context_provider.activate(context)
26+
# Only activate the new context if there was a trace id extracted
27+
if context.trace_id:
28+
self.tracer.context_provider.activate(context)
2729

2830
span = self.tracer.trace(
2931
"falcon.request",

ddtrace/contrib/falcon/patch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ddtrace import tracer
66

77
from .middleware import TraceMiddleware
8-
from ...utils.formats import asbool
8+
from ...utils.formats import asbool, get_env
99

1010

1111
def patch():
@@ -23,8 +23,7 @@ def patch():
2323
def traced_init(wrapped, instance, args, kwargs):
2424
mw = kwargs.pop('middleware', [])
2525
service = os.environ.get('DATADOG_SERVICE_NAME') or 'falcon'
26-
distributed_tracing = asbool(os.environ.get(
27-
'DATADOG_FALCON_DISTRIBUTED_TRACING')) or False
26+
distributed_tracing = asbool(get_env('falcon', 'distributed_tracing', True))
2827

2928
mw.insert(0, TraceMiddleware(tracer, service, distributed_tracing))
3029
kwargs['middleware'] = mw

ddtrace/contrib/flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def index():
3535
3636
Whether to parse distributed tracing headers from requests received by your Flask app.
3737
38-
Default: ``False``
38+
Default: ``True``
3939
4040
.. py:data:: ddtrace.config.flask['service_name']
4141

ddtrace/contrib/flask/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
app_type=AppTypes.web,
3232

3333
collect_view_args=True,
34-
distributed_tracing_enabled=False,
34+
distributed_tracing_enabled=True,
3535
template_default_name='<memory>',
3636
trace_signals=True,
3737

ddtrace/contrib/molten/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,23 @@ def hello(name: str, age: int) -> str:
1313
1414
ddtrace-run python app.py
1515
16-
To enable distributed tracing when using autopatching, set the
17-
``DD_MOLTEN_DISTRIBUTED_TRACING`` environment variable to ``True``.
16+
17+
Configuration
18+
~~~~~~~~~~~~~
19+
20+
.. py:data:: ddtrace.config.molten['distributed_tracing']
21+
22+
Whether to parse distributed tracing headers from requests received by your Molten app.
23+
24+
Default: ``True``
25+
26+
.. py:data:: ddtrace.config.molten['service_name']
27+
28+
The service name reported for your Molten app.
29+
30+
Can also be configured via the ``DD_MOLTEN_SERVICE_NAME`` environment variable.
31+
32+
Default: ``'molten'``
1833
"""
1934
from ...utils.importlib import require_modules
2035

0 commit comments

Comments
 (0)