Skip to content

Commit 47ecf1d

Browse files
authored
Merge pull request #766 from DataDog/0.17.1-dev
v0.17.1
2 parents 6656236 + 74f5fb7 commit 47ecf1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+172
-101
lines changed

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 .settings import config
66

7-
__version__ = '0.17.0'
7+
__version__ = '0.17.1'
88

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

ddtrace/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
'compatibility_mode': False,
1919
'fallback': 'v0.3'},
2020
'v0.3': {'traces': '/v0.3/traces',
21-
'services': '/v0.3/services',
21+
'services': '/v0.3/services',
2222
'compatibility_mode': False,
2323
'fallback': 'v0.2'},
2424
'v0.2': {'traces': '/v0.2/traces',
25-
'services': '/v0.2/services',
25+
'services': '/v0.2/services',
2626
'compatibility_mode': True,
2727
'fallback': None}}
2828

29+
2930
def _parse_response_json(response):
3031
"""
3132
Parse the content of a response object, and return the right type,
@@ -48,6 +49,7 @@ def _parse_response_json(response):
4849
except (ValueError, TypeError) as err:
4950
log.debug("unable to load JSON '%s': %s" % (body, err))
5051

52+
5153
class API(object):
5254
"""
5355
Send data to the trace agent using the HTTP protocol and JSON format

ddtrace/commands/ddtrace_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
DATADOG_PRIORITY_SAMPLING=true|false : (default: false): enables Priority Sampling.
3434
""" # noqa
3535

36+
3637
def _ddtrace_root():
3738
from ddtrace import __file__
3839
return os.path.dirname(__file__)
@@ -46,8 +47,7 @@ def _add_bootstrap_to_pythonpath(bootstrap_dir):
4647
python_path = os.environ.get('PYTHONPATH', '')
4748

4849
if python_path:
49-
new_path = "%s%s%s" % (bootstrap_dir, os.path.pathsep,
50-
os.environ['PYTHONPATH'])
50+
new_path = "%s%s%s" % (bootstrap_dir, os.path.pathsep, os.environ['PYTHONPATH'])
5151
os.environ['PYTHONPATH'] = new_path
5252
else:
5353
os.environ['PYTHONPATH'] = bootstrap_dir

ddtrace/contrib/bottle/patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import os
32

43
from .trace import TracePlugin
@@ -7,6 +6,7 @@
76

87
import wrapt
98

9+
1010
def patch():
1111
"""Patch the bottle.Bottle class
1212
"""
@@ -16,6 +16,7 @@ def patch():
1616
setattr(bottle, '_datadog_patch', True)
1717
wrapt.wrap_function_wrapper('bottle', 'Bottle.__init__', traced_init)
1818

19+
1920
def traced_init(wrapped, instance, args, kwargs):
2021
wrapped(*args, **kwargs)
2122

ddtrace/contrib/bottle/trace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
SPAN_TYPE = 'web'
1212

13+
1314
class TracePlugin(object):
1415
name = 'trace'
1516
api = 2

ddtrace/contrib/cassandra/session.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@
2525
# Original connect connect function
2626
_connect = cassandra.cluster.Cluster.connect
2727

28+
2829
def patch():
2930
""" patch will add tracing to the cassandra library. """
3031
setattr(cassandra.cluster.Cluster, 'connect',
3132
wrapt.FunctionWrapper(_connect, traced_connect))
3233
Pin(service=SERVICE, app=SERVICE, app_type="db").onto(cassandra.cluster.Cluster)
3334

35+
3436
def unpatch():
3537
cassandra.cluster.Cluster.connect = _connect
3638

39+
3740
def traced_connect(func, instance, args, kwargs):
3841
session = func(*args, **kwargs)
3942
if not isinstance(session.execute, wrapt.FunctionWrapper):
4043
# FIXME[matt] this should probably be private.
4144
setattr(session, 'execute_async', wrapt.FunctionWrapper(session.execute_async, traced_execute_async))
4245
return session
4346

47+
4448
def _close_span_on_success(result, future):
4549
span = getattr(future, CURRENT_SPAN, None)
4650
if not span:
@@ -54,11 +58,13 @@ def _close_span_on_success(result, future):
5458
span.finish()
5559
delattr(future, CURRENT_SPAN)
5660

61+
5762
def traced_set_final_result(func, instance, args, kwargs):
5863
result = args[0]
5964
_close_span_on_success(result, instance)
6065
return func(*args, **kwargs)
6166

67+
6268
def _close_span_on_error(exc, future):
6369
span = getattr(future, CURRENT_SPAN, None)
6470
if not span:
@@ -76,11 +82,13 @@ def _close_span_on_error(exc, future):
7682
span.finish()
7783
delattr(future, CURRENT_SPAN)
7884

85+
7986
def traced_set_final_exception(func, instance, args, kwargs):
8087
exc = args[0]
8188
_close_span_on_error(exc, instance)
8289
return func(*args, **kwargs)
8390

91+
8492
def traced_start_fetching_next_page(func, instance, args, kwargs):
8593
has_more_pages = getattr(instance, 'has_more_pages', True)
8694
if not has_more_pages:
@@ -106,11 +114,12 @@ def traced_start_fetching_next_page(func, instance, args, kwargs):
106114
setattr(instance, CURRENT_SPAN, span)
107115
try:
108116
return func(*args, **kwargs)
109-
except:
117+
except Exception:
110118
with span:
111119
span.set_exc_info(*sys.exc_info())
112120
raise
113121

122+
114123
def traced_execute_async(func, instance, args, kwargs):
115124
cluster = getattr(instance, 'cluster', None)
116125
pin = Pin.get_from(cluster)
@@ -161,11 +170,12 @@ def traced_execute_async(func, instance, args, kwargs):
161170
)
162171
result.clear_callbacks()
163172
return result
164-
except:
173+
except Exception:
165174
with span:
166175
span.set_exc_info(*sys.exc_info())
167176
raise
168177

178+
169179
def _start_span_and_set_tags(pin, query, session, cluster):
170180
service = pin.service
171181
tracer = pin.tracer
@@ -175,6 +185,7 @@ def _start_span_and_set_tags(pin, query, session, cluster):
175185
span.set_tags(_extract_cluster_metas(cluster))
176186
return span
177187

188+
178189
def _extract_session_metas(session):
179190
metas = {}
180191

@@ -185,6 +196,7 @@ def _extract_session_metas(session):
185196

186197
return metas
187198

199+
188200
def _extract_cluster_metas(cluster):
189201
metas = {}
190202
if deep_getattr(cluster, "metadata.cluster_name"):
@@ -194,6 +206,7 @@ def _extract_cluster_metas(cluster):
194206

195207
return metas
196208

209+
197210
def _extract_result_metas(result):
198211
metas = {}
199212
if result is None:
@@ -230,6 +243,7 @@ def _extract_result_metas(result):
230243

231244
return metas
232245

246+
233247
def _sanitize_query(span, query):
234248
# TODO (aaditya): fix this hacky type check. we need it to avoid circular imports
235249
t = type(query).__name__
@@ -250,7 +264,7 @@ def _sanitize_query(span, query):
250264
elif t == 'str':
251265
resource = query
252266
else:
253-
resource = 'unknown-query-type' # FIXME[matt] what else do to here?
267+
resource = 'unknown-query-type' # FIXME[matt] what else do to here?
254268

255269
span.resource = stringify(resource)[:RESOURCE_MAX_LENGTH]
256270

ddtrace/contrib/celery/signals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
retrieve_span,
1414
)
1515

16-
1716
log = logging.getLogger(__name__)
1817
SPAN_TYPE = 'worker'
1918

19+
2020
def trace_prerun(*args, **kwargs):
2121
# safe-guard to avoid crashes in case the signals API
2222
# changes in Celery

ddtrace/contrib/celery/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def patch_task(task, pin=None):
1818
patch_app(task.app)
1919
return task
2020

21+
2122
def unpatch_task(task):
2223
"""Deprecated API. The new API uses signals that can be deactivated
2324
via unpatch() API. This API is now a no-op implementation so it doesn't

ddtrace/contrib/dbapi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def rollback(self, *args, **kwargs):
153153
span_name = '{}.{}'.format(self._self_datadog_name, 'rollback')
154154
return self._trace_method(self.__wrapped__.rollback, span_name, {}, *args, **kwargs)
155155

156+
156157
def _get_vendor(conn):
157158
""" Return the vendor (e.g postgres, mysql) of the given
158159
database.

ddtrace/contrib/django/cache.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def _trace_operation(fn, method_name):
5454
def wrapped(self, *args, **kwargs):
5555
# get the original function method
5656
method = getattr(self, DATADOG_NAMESPACE.format(method=method_name))
57-
with tracer.trace('django.cache',
58-
span_type=TYPE, service=cache_service_name) as span:
57+
with tracer.trace('django.cache', span_type=TYPE, service=cache_service_name) as span:
5958
# update the resource name and tag the cache backend
6059
span.resource = _resource_from_cache_prefix(method_name, self)
6160
cache_backend = '{}.{}'.format(self.__module__, self.__class__.__name__)
@@ -93,6 +92,7 @@ def _wrap_method(cls, method_name):
9392
for method in TRACED_METHODS:
9493
_wrap_method(cache, method)
9594

95+
9696
def unpatch_method(cls, method_name):
9797
method = getattr(cls, DATADOG_NAMESPACE.format(method=method_name), None)
9898
if method is None:
@@ -101,6 +101,7 @@ def unpatch_method(cls, method_name):
101101
setattr(cls, method_name, method)
102102
delattr(cls, DATADOG_NAMESPACE.format(method=method_name))
103103

104+
104105
def unpatch_cache():
105106
cache_backends = set([cache['BACKEND'] for cache in django_settings.CACHES.values()])
106107
for cache_module in cache_backends:

0 commit comments

Comments
 (0)