Skip to content

Commit e439a52

Browse files
author
Emanuele Palazzetti
committed
Update 0.12-dev with 'v0.11.1' release
2 parents 0a3b559 + 2d8331e commit e439a52

File tree

14 files changed

+203
-138
lines changed

14 files changed

+203
-138
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ jobs:
204204
- restore_cache:
205205
keys:
206206
- tox-cache-bottle-{{ checksum "tox.ini" }}
207-
- run: tox -e '{py27,py34,py35,py36}-bottle{12}-webtest' --result-json /tmp/bottle.1.results
208-
- run: tox -e '{py27,py34,py35,py36}-bottle-autopatch{12}-webtest' --result-json /tmp/bottle.2.results
207+
- run: tox -e '{py27,py34,py35,py36}-bottle{11,12}-webtest' --result-json /tmp/bottle.1.results
208+
- run: tox -e '{py27,py34,py35,py36}-bottle-autopatch{11,12}-webtest' --result-json /tmp/bottle.2.results
209209
- persist_to_workspace:
210210
root: /tmp
211211
paths:

ddtrace/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .tracer import Tracer
55
from .configuration import Config
66

7-
__version__ = '0.11.0'
7+
__version__ = '0.11.1'
88

99
# a global tracer instance with integration settings
1010
tracer = Tracer()

ddtrace/contrib/bottle/trace.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# 3p
32
from bottle import response, request
43

@@ -10,26 +9,26 @@
109
from ...propagation.http import HTTPPropagator
1110

1211
class TracePlugin(object):
13-
1412
name = 'trace'
1513
api = 2
1614

17-
def __init__(self, service="bottle", tracer=None, distributed_tracing=None):
15+
def __init__(self, service='bottle', tracer=None, distributed_tracing=None):
1816
self.service = service
1917
self.tracer = tracer or ddtrace.tracer
18+
self.distributed_tracing = distributed_tracing
2019
self.tracer.set_service_info(
2120
service=service,
22-
app="bottle",
23-
app_type=AppTypes.web)
24-
self.distributed_tracing = distributed_tracing
21+
app='bottle',
22+
app_type=AppTypes.web,
23+
)
2524

2625
def apply(self, callback, route):
2726

2827
def wrapped(*args, **kwargs):
2928
if not self.tracer or not self.tracer.enabled:
3029
return callback(*args, **kwargs)
3130

32-
resource = "%s %s" % (request.method, request.route.rule)
31+
resource = '{} {}'.format(request.method, route.rule)
3332

3433
# Propagate headers such as x-datadog-trace-id.
3534
if self.distributed_tracing:
@@ -38,7 +37,7 @@ def wrapped(*args, **kwargs):
3837
if context.trace_id:
3938
self.tracer.context_provider.activate(context)
4039

41-
with self.tracer.trace("bottle.request", service=self.service, resource=resource) as s:
40+
with self.tracer.trace('bottle.request', service=self.service, resource=resource) as s:
4241
code = 0
4342
try:
4443
return callback(*args, **kwargs)

ddtrace/contrib/django/db.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,36 @@
1313
log = logging.getLogger(__name__)
1414

1515
CURSOR_ATTR = '_datadog_original_cursor'
16+
ALL_CONNS_ATTR = '_datadog_original_connections_all'
1617

1718

1819
def patch_db(tracer):
19-
for c in connections.all():
20-
patch_conn(tracer, c)
20+
if hasattr(connections, ALL_CONNS_ATTR):
21+
log.debug('db already patched')
22+
return
23+
setattr(connections, ALL_CONNS_ATTR, connections.all)
24+
25+
def all_connections(self):
26+
conns = getattr(self, ALL_CONNS_ATTR)()
27+
for conn in conns:
28+
patch_conn(tracer, conn)
29+
return conns
30+
31+
connections.all = all_connections.__get__(connections, type(connections))
2132

2233
def unpatch_db():
2334
for c in connections.all():
2435
unpatch_conn(c)
2536

37+
all_connections = getattr(connections, ALL_CONNS_ATTR, None)
38+
if all_connections is None:
39+
log.debug('nothing to do, the db is not patched')
40+
return
41+
connections.all = all_connections
42+
delattr(connections, ALL_CONNS_ATTR)
2643

2744
def patch_conn(tracer, conn):
2845
if hasattr(conn, CURSOR_ATTR):
29-
log.debug("already patched")
3046
return
3147

3248
setattr(conn, CURSOR_ATTR, conn.cursor)

ddtrace/contrib/django/middleware.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# 3p
1212
from django.core.exceptions import MiddlewareNotUsed
1313
from django.conf import settings as django_settings
14+
import django
1415

1516
try:
1617
from django.utils.deprecation import MiddlewareMixin
@@ -22,33 +23,37 @@
2223

2324
EXCEPTION_MIDDLEWARE = 'ddtrace.contrib.django.TraceExceptionMiddleware'
2425
TRACE_MIDDLEWARE = 'ddtrace.contrib.django.TraceMiddleware'
25-
MIDDLEWARE_ATTRIBUTES = ['MIDDLEWARE', 'MIDDLEWARE_CLASSES']
26+
MIDDLEWARE = 'MIDDLEWARE'
27+
MIDDLEWARE_CLASSES = 'MIDDLEWARE_CLASSES'
28+
29+
def get_middleware_insertion_point():
30+
"""Returns the attribute name and collection object for the Django middleware.
31+
If middleware cannot be found, returns None for the middleware collection."""
32+
middleware = getattr(django_settings, MIDDLEWARE, None)
33+
# Prioritise MIDDLEWARE over ..._CLASSES, but only in 1.10 and later.
34+
if middleware and django.VERSION >= (1, 10):
35+
return MIDDLEWARE, middleware
36+
return MIDDLEWARE_CLASSES, getattr(django_settings, MIDDLEWARE_CLASSES, None)
2637

2738
def insert_trace_middleware():
28-
for middleware_attribute in MIDDLEWARE_ATTRIBUTES:
29-
middleware = getattr(django_settings, middleware_attribute, None)
30-
if middleware is not None and TRACE_MIDDLEWARE not in set(middleware):
31-
setattr(django_settings, middleware_attribute, type(middleware)((TRACE_MIDDLEWARE,)) + middleware)
32-
break
39+
middleware_attribute, middleware = get_middleware_insertion_point()
40+
if middleware is not None and TRACE_MIDDLEWARE not in set(middleware):
41+
setattr(django_settings, middleware_attribute, type(middleware)((TRACE_MIDDLEWARE,)) + middleware)
3342

3443
def remove_trace_middleware():
35-
for middleware_attribute in MIDDLEWARE_ATTRIBUTES:
36-
middleware = getattr(django_settings, middleware_attribute, None)
37-
if middleware and TRACE_MIDDLEWARE in set(middleware):
38-
middleware.remove(TRACE_MIDDLEWARE)
44+
_, middleware = get_middleware_insertion_point()
45+
if middleware and TRACE_MIDDLEWARE in set(middleware):
46+
middleware.remove(TRACE_MIDDLEWARE)
3947

4048
def insert_exception_middleware():
41-
for middleware_attribute in MIDDLEWARE_ATTRIBUTES:
42-
middleware = getattr(django_settings, middleware_attribute, None)
43-
if middleware is not None and EXCEPTION_MIDDLEWARE not in set(middleware):
44-
setattr(django_settings, middleware_attribute, middleware + type(middleware)((EXCEPTION_MIDDLEWARE,)))
45-
break
49+
middleware_attribute, middleware = get_middleware_insertion_point()
50+
if middleware is not None and EXCEPTION_MIDDLEWARE not in set(middleware):
51+
setattr(django_settings, middleware_attribute, middleware + type(middleware)((EXCEPTION_MIDDLEWARE,)))
4652

4753
def remove_exception_middleware():
48-
for middleware_attribute in MIDDLEWARE_ATTRIBUTES:
49-
middleware = getattr(django_settings, middleware_attribute, None)
50-
if middleware and EXCEPTION_MIDDLEWARE in set(middleware):
51-
middleware.remove(EXCEPTION_MIDDLEWARE)
54+
_, middleware = get_middleware_insertion_point()
55+
if middleware and EXCEPTION_MIDDLEWARE in set(middleware):
56+
middleware.remove(EXCEPTION_MIDDLEWARE)
5257

5358
class InstrumentationMixin(MiddlewareClass):
5459
"""

ddtrace/contrib/tornado/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def notify(self):
7070
* ``enabled`` (default: `True`): define if the tracer is enabled or not. If set to `false`, the
7171
code is still instrumented but no spans are sent to the APM agent.
7272
* ``distributed_tracing`` (default: `False`): enable distributed tracing if this is called
73-
remotely from an instrumented application.
74-
We suggest to enable it only for internal services where headers are under your control.
73+
remotely from an instrumented application.
74+
We suggest to enable it only for internal services where headers are under your control.
7575
* ``agent_hostname`` (default: `localhost`): define the hostname of the APM agent.
7676
* ``agent_port`` (default: `8126`): define the port of the APM agent.
7777
"""

ddtrace/filters.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
from .ext import http
44

55
class FilterRequestsOnUrl(object):
6-
"""Filter out traces from incoming http requests based on the request's url
7-
6+
"""Filter out traces from incoming http requests based on the request's url.
87
This class takes as argument a list of regular expression patterns
98
representing the urls to be excluded from tracing. A trace will be excluded
10-
if its root span contains a http.url tag and if this tag matches any of
9+
if its root span contains a ``http.url`` tag and if this tag matches any of
1110
the provided regular expression using the standard python regexp match
1211
semantic (https://docs.python.org/2/library/re.html#re.match).
1312
14-
:param list regexps: the list of regular expressions (as strings) defining
15-
the urls that should be filtered out. (a single string is also accepted)
13+
:param list regexps: a list of regular expressions (or a single string) defining
14+
the urls that should be filtered out.
1615
1716
Examples:
1817
@@ -27,8 +26,6 @@ class FilterRequestsOnUrl(object):
2726
To filter out calls to both http://test.example.com and http://example.com/healthcheck::
2827
2928
FilterRequestOnUrl([r'http://test\.example\.com', r'http://example\.com/healthcheck'])
30-
31-
3229
"""
3330
def __init__(self, regexps):
3431
if isinstance(regexps, str):

docs/index.rst

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Instrumentation
7373
Web
7474
~~~
7575

76-
We support many `Web Frameworks`_. Install the middleware for yours.
76+
We support many :ref:`web-frameworks`. Install the middleware for yours.
7777

7878
Databases
7979
~~~~~~~~~
@@ -124,6 +124,8 @@ If the Datadog Agent is on a separate host from your application, you can modify
124124

125125
By default, these will be set to localhost and 8126 respectively.
126126

127+
.. _web-frameworks:
128+
127129
Web Frameworks
128130
--------------
129131

@@ -251,7 +253,7 @@ Redis
251253
.. automodule:: ddtrace.contrib.redis
252254

253255
Requests
254-
~~~~~
256+
~~~~~~~~
255257

256258
.. automodule:: ddtrace.contrib.requests
257259

@@ -527,61 +529,61 @@ Supported versions
527529

528530
We officially support Python 2.7, 3.4 and above.
529531

530-
+-----------------+--------------------+
531-
| Integrations | Supported versions |
532-
+=================+====================+
533-
| aiohttp | >= 1.2 |
534-
+-----------------+--------------------+
535-
| aiobotocore | >= 0.2.3 |
536-
+-----------------+--------------------+
537-
| aiopg | >= 0.12.0 |
538-
+-----------------+--------------------+
539-
| boto | >= 2.29.0 |
540-
+-----------------+--------------------+
541-
| botocore | >= 1.4.51 |
542-
+-----------------+--------------------+
543-
| bottle | >= 0.12 |
544-
+-----------------+--------------------+
545-
| celery | >= 3.1 |
546-
+-----------------+--------------------+
547-
| cassandra | >= 3.5 |
548-
+---------------------+----------------+
549-
| djangorestframework | >= 3.4 |
550-
+---------------------+----------------+
551-
| django | >= 1.8 |
552-
+-----------------+--------------------+
553-
| elasticsearch | >= 1.6 |
554-
+-----------------+--------------------+
555-
| falcon | >= 1.0 |
556-
+-----------------+--------------------+
557-
| flask | >= 0.10 |
558-
+-----------------+--------------------+
559-
| flask_cache | >= 0.12 |
560-
+-----------------+--------------------+
561-
| gevent | >= 1.0 |
562-
+-----------------+--------------------+
563-
| mongoengine | >= 0.11 |
564-
+-----------------+--------------------+
565-
| mysql-connector | >= 2.1 |
566-
+-----------------+--------------------+
567-
| MySQL-python | >= 1.2.3 |
568-
+-----------------+--------------------+
569-
| mysqlclient | >= 1.3 |
570-
+-----------------+--------------------+
571-
| psycopg2 | >= 2.4 |
572-
+-----------------+--------------------+
573-
| pylibmc | >= 1.4 |
574-
+-----------------+--------------------+
575-
| pylons | >= 0.9.6 |
576-
+-----------------+--------------------+
577-
| pymongo | >= 3.0 |
578-
+-----------------+--------------------+
579-
| pyramid | >= 1.7 |
580-
+-----------------+--------------------+
581-
| redis | >= 2.6 |
582-
+-----------------+--------------------+
583-
| sqlalchemy | >= 1.0 |
584-
+-----------------+--------------------+
532+
+---------------------+--------------------+
533+
| Integrations | Supported versions |
534+
+=====================+====================+
535+
| aiohttp | >= 1.2 |
536+
+---------------------+--------------------+
537+
| aiobotocore | >= 0.2.3 |
538+
+---------------------+--------------------+
539+
| aiopg | >= 0.12.0 |
540+
+---------------------+--------------------+
541+
| boto | >= 2.29.0 |
542+
+---------------------+--------------------+
543+
| botocore | >= 1.4.51 |
544+
+---------------------+--------------------+
545+
| bottle | >= 0.11 |
546+
+---------------------+--------------------+
547+
| celery | >= 3.1 |
548+
+---------------------+--------------------+
549+
| cassandra | >= 3.5 |
550+
+---------------------+--------------------+
551+
| djangorestframework | >= 3.4 |
552+
+---------------------+--------------------+
553+
| django | >= 1.8 |
554+
+---------------------+--------------------+
555+
| elasticsearch | >= 1.6 |
556+
+---------------------+--------------------+
557+
| falcon | >= 1.0 |
558+
+---------------------+--------------------+
559+
| flask | >= 0.10 |
560+
+---------------------+--------------------+
561+
| flask_cache | >= 0.12 |
562+
+---------------------+--------------------+
563+
| gevent | >= 1.0 |
564+
+---------------------+--------------------+
565+
| mongoengine | >= 0.11 |
566+
+---------------------+--------------------+
567+
| mysql-connector | >= 2.1 |
568+
+---------------------+--------------------+
569+
| MySQL-python | >= 1.2.3 |
570+
+---------------------+--------------------+
571+
| mysqlclient | >= 1.3 |
572+
+---------------------+--------------------+
573+
| psycopg2 | >= 2.4 |
574+
+---------------------+--------------------+
575+
| pylibmc | >= 1.4 |
576+
+---------------------+--------------------+
577+
| pylons | >= 0.9.6 |
578+
+---------------------+--------------------+
579+
| pymongo | >= 3.0 |
580+
+---------------------+--------------------+
581+
| pyramid | >= 1.7 |
582+
+---------------------+--------------------+
583+
| redis | >= 2.6 |
584+
+---------------------+--------------------+
585+
| sqlalchemy | >= 1.0 |
586+
+---------------------+--------------------+
585587

586588

587589
These are the fully tested versions but `ddtrace` can be compatible with lower versions.

tests/contrib/django/app/settings.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
]
8585

8686
# Django 2.0 has different defaults
87-
if django.VERSION >= (2, 0):
87+
elif django.VERSION >= (2, 0):
8888
MIDDLEWARE = [
8989
'django.contrib.sessions.middleware.SessionMiddleware',
9090
'django.middleware.common.CommonMiddleware',
@@ -97,20 +97,20 @@
9797
'tests.contrib.django.app.middlewares.CatchExceptionMiddleware',
9898
]
9999

100-
# Always add the legacy conf to make sure we handle it properly
101100
# Pre 1.10 style
102-
MIDDLEWARE_CLASSES = [
103-
'django.contrib.sessions.middleware.SessionMiddleware',
104-
'django.middleware.common.CommonMiddleware',
105-
'django.middleware.csrf.CsrfViewMiddleware',
106-
'django.contrib.auth.middleware.AuthenticationMiddleware',
107-
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
108-
'django.contrib.messages.middleware.MessageMiddleware',
109-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
110-
'django.middleware.security.SecurityMiddleware',
101+
else:
102+
MIDDLEWARE_CLASSES = [
103+
'django.contrib.sessions.middleware.SessionMiddleware',
104+
'django.middleware.common.CommonMiddleware',
105+
'django.middleware.csrf.CsrfViewMiddleware',
106+
'django.contrib.auth.middleware.AuthenticationMiddleware',
107+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
108+
'django.contrib.messages.middleware.MessageMiddleware',
109+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
110+
'django.middleware.security.SecurityMiddleware',
111111

112-
'tests.contrib.django.app.middlewares.CatchExceptionMiddleware',
113-
]
112+
'tests.contrib.django.app.middlewares.CatchExceptionMiddleware',
113+
]
114114

115115
INSTALLED_APPS = [
116116
'django.contrib.admin',

0 commit comments

Comments
 (0)