Skip to content

Commit e8b1070

Browse files
authored
Merge pull request #783 from DataDog/0.19-dev
0.19.0
2 parents a0bdd48 + 6b1243e commit e8b1070

Some content is hidden

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

51 files changed

+1647
-810
lines changed

.circleci/config.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ jobs:
5151
- flake8.results
5252
- *save_cache_step
5353

54+
# Test that we can build the package properly and package long description will render
55+
test_build:
56+
docker:
57+
- *test_runner
58+
resource_class: *resource_class
59+
steps:
60+
- checkout
61+
- *restore_cache_step
62+
# Install required dependencies
63+
- run: pip install twine readme_renderer[md]
64+
# Ensure we didn't cache from previous runs
65+
- run: rm -rf dist/
66+
# Ensure package will build
67+
- run: python setup.py sdist
68+
# Ensure package long description is valid and will render
69+
# https://github.com/pypa/twine/tree/6c4d5ecf2596c72b89b969ccc37b82c160645df8#twine-check
70+
- run: twine check dist/*
71+
- *save_cache_step
72+
5473
tracer:
5574
docker:
5675
- *test_runner
@@ -931,11 +950,11 @@ workflows:
931950
<<: *deploy_docs_filters
932951
requires:
933952
- approve_docs_deployment
934-
935953
test:
936954
jobs:
937955
- build_docs
938956
- flake8
957+
- test_build
939958
- aiobotocore:
940959
requires:
941960
- flake8
@@ -1076,8 +1095,12 @@ workflows:
10761095
- flake8
10771096
- wait_all_tests:
10781097
requires:
1098+
# Initial jobs
10791099
- build_docs
10801100
- flake8
1101+
- test_build
1102+
1103+
# flake8 dependent jobs
10811104
- aiobotocore
10821105
- aiohttp
10831106
- aiopg

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.18.0'
7+
__version__ = '0.19.0'
88

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

ddtrace/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
FILTERS_KEY = 'FILTERS'
2-
SAMPLE_RATE_METRIC_KEY = "_sample_rate"
2+
SAMPLE_RATE_METRIC_KEY = '_sample_rate'
33
SAMPLING_PRIORITY_KEY = '_sampling_priority_v1'
4+
EVENT_SAMPLE_RATE_KEY = '_dd1.sr.eausr'
5+
6+
NUMERIC_TAGS = (EVENT_SAMPLE_RATE_KEY, )

ddtrace/contrib/aiohttp/middlewares.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22

33
from ..asyncio import context_provider
4-
from ...ext import AppTypes, http
54
from ...compat import stringify
6-
from ...context import Context
5+
from ...constants import EVENT_SAMPLE_RATE_KEY
6+
from ...ext import AppTypes, http
77
from ...propagation.http import HTTPPropagator
8+
from ...settings import config
89

910

1011
CONFIG_KEY = 'datadog_trace'
@@ -45,6 +46,10 @@ def attach_context(request):
4546
span_type=http.TYPE,
4647
)
4748

49+
# Configure trace search sample rate
50+
if config.aiohttp.event_sample_rate is not None:
51+
request_span.set_tag(EVENT_SAMPLE_RATE_KEY, config.aiohttp.event_sample_rate)
52+
4853
# attach the context and the root span to the request; the Context
4954
# may be freely used by the application code
5055
request[REQUEST_CONTEXT_KEY] = request_span.context

ddtrace/contrib/bottle/trace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from ddtrace.ext import http, AppTypes
77

88
# project
9+
from ...constants import EVENT_SAMPLE_RATE_KEY
910
from ...propagation.http import HTTPPropagator
11+
from ...settings import config
1012

1113
SPAN_TYPE = 'web'
1214

@@ -41,6 +43,10 @@ def wrapped(*args, **kwargs):
4143
self.tracer.context_provider.activate(context)
4244

4345
with self.tracer.trace('bottle.request', service=self.service, resource=resource, span_type=SPAN_TYPE) as s:
46+
# Configure trace search sample rate
47+
if config.bottle.event_sample_rate is not None:
48+
s.set_tag(EVENT_SAMPLE_RATE_KEY, config.bottle.event_sample_rate)
49+
4450
code = 0
4551
try:
4652
return callback(*args, **kwargs)

ddtrace/contrib/dbapi/__init__.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
from ddtrace import Pin
1010
from ddtrace.ext import AppTypes, sql
11+
from ddtrace.settings import config
12+
from ddtrace.utils.formats import asbool, get_env
1113

1214
log = logging.getLogger(__name__)
1315

16+
config._add('dbapi2', dict(
17+
trace_fetch_methods=asbool(get_env('dbapi2', 'trace_fetch_methods', 'false')),
18+
))
19+
1420

1521
class TracedCursor(wrapt.ObjectProxy):
1622
""" TracedCursor wraps a psql cursor and traces it's queries. """
@@ -72,6 +78,27 @@ def execute(self, query, *args, **kwargs):
7278
self._trace_method(self.__wrapped__.execute, self._self_datadog_name, query, {}, query, *args, **kwargs)
7379
return self
7480

81+
def callproc(self, proc, args):
82+
""" Wraps the cursor.callproc method"""
83+
self._self_last_execute_operation = proc
84+
return self._trace_method(self.__wrapped__.callproc, self._self_datadog_name, proc, {}, proc, args)
85+
86+
def __enter__(self):
87+
# previous versions of the dbapi didn't support context managers. let's
88+
# reference the func that would be called to ensure that errors
89+
# messages will be the same.
90+
self.__wrapped__.__enter__
91+
92+
# and finally, yield the traced cursor.
93+
return self
94+
95+
96+
class FetchTracedCursor(TracedCursor):
97+
"""
98+
Sub-class of :class:`TracedCursor` that also instruments `fetchone`, `fetchall`, and `fetchmany` methods.
99+
100+
We do not trace these functions by default since they can get very noisy (e.g. `fetchone` with 100k rows).
101+
"""
75102
def fetchone(self, *args, **kwargs):
76103
""" Wraps the cursor.fetchone method"""
77104
span_name = '{}.{}'.format(self._self_datadog_name, 'fetchone')
@@ -101,25 +128,18 @@ def fetchmany(self, *args, **kwargs):
101128
return self._trace_method(self.__wrapped__.fetchmany, span_name, self._self_last_execute_operation, extra_tags,
102129
*args, **kwargs)
103130

104-
def callproc(self, proc, args):
105-
""" Wraps the cursor.callproc method"""
106-
self._self_last_execute_operation = proc
107-
return self._trace_method(self.__wrapped__.callproc, self._self_datadog_name, proc, {}, proc, args)
108-
109-
def __enter__(self):
110-
# previous versions of the dbapi didn't support context managers. let's
111-
# reference the func that would be called to ensure that errors
112-
# messages will be the same.
113-
self.__wrapped__.__enter__
114-
115-
# and finally, yield the traced cursor.
116-
return self
117-
118131

119132
class TracedConnection(wrapt.ObjectProxy):
120133
""" TracedConnection wraps a Connection with tracing code. """
121134

122-
def __init__(self, conn, pin=None, cursor_cls=TracedCursor):
135+
def __init__(self, conn, pin=None, cursor_cls=None):
136+
# Set default cursor class if one was not provided
137+
if not cursor_cls:
138+
# Do not trace `fetch*` methods by default
139+
cursor_cls = TracedCursor
140+
if config.dbapi2.trace_fetch_methods:
141+
cursor_cls = FetchTracedCursor
142+
123143
super(TracedConnection, self).__init__(conn)
124144
name = _get_vendor(conn)
125145
self._self_datadog_name = '{}.connection'.format(name)

ddtrace/contrib/django/middleware.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from .conf import settings
55
from .compat import user_is_authenticated, get_resolver
66

7-
from ...ext import http
7+
from ...constants import EVENT_SAMPLE_RATE_KEY
88
from ...contrib import func_name
9+
from ...ext import http
910
from ...propagation.http import HTTPPropagator
11+
from ...settings import config
1012

1113
# 3p
1214
from django.core.exceptions import MiddlewareNotUsed
@@ -118,6 +120,10 @@ def process_request(self, request):
118120
span_type=http.TYPE,
119121
)
120122

123+
# Configure trace search sample rate
124+
if config.django.event_sample_rate is not None:
125+
span.set_tag(EVENT_SAMPLE_RATE_KEY, config.django.event_sample_rate)
126+
121127
span.set_tag(http.METHOD, request.method)
122128
span.set_tag(http.URL, request.path)
123129
_set_req_span(request, span)

ddtrace/contrib/falcon/middleware.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from ddtrace.ext import http as httpx
44
from ddtrace.http import store_request_headers, store_response_headers
55
from ddtrace.propagation.http import HTTPPropagator
6+
67
from ...compat import iteritems
8+
from ...constants import EVENT_SAMPLE_RATE_KEY
79
from ...ext import AppTypes
810
from ...settings import config
911

@@ -37,6 +39,10 @@ def process_request(self, req, resp):
3739
span_type=httpx.TYPE,
3840
)
3941

42+
# Configure trace search sample rate
43+
if config.falcon.event_sample_rate is not None:
44+
span.set_tag(EVENT_SAMPLE_RATE_KEY, config.falcon.event_sample_rate)
45+
4046
span.set_tag(httpx.METHOD, req.method)
4147
span.set_tag(httpx.URL, req.url)
4248

ddtrace/contrib/flask/patch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ddtrace import config, Pin
99

10+
from ...constants import EVENT_SAMPLE_RATE_KEY
1011
from ...ext import AppTypes
1112
from ...ext import http
1213
from ...propagation.http import HTTPPropagator
@@ -284,6 +285,10 @@ def traced_wsgi_app(pin, wrapped, instance, args, kwargs):
284285
# We will override this below in `traced_dispatch_request` when we have a `RequestContext` and possibly a url rule
285286
resource = u'{} {}'.format(request.method, request.path)
286287
with pin.tracer.trace('flask.request', service=pin.service, resource=resource, span_type=http.TYPE) as s:
288+
# Configure trace search sample rate
289+
if config.flask.event_sample_rate is not None:
290+
s.set_tag(EVENT_SAMPLE_RATE_KEY, config.flask.event_sample_rate)
291+
287292
s.set_tag(FLASK_VERSION, flask_version_str)
288293

289294
# Wrap the `start_response` handler to extract response code

ddtrace/contrib/molten/patch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import molten
55

66
from ... import Pin, config
7+
from ...constants import EVENT_SAMPLE_RATE_KEY
78
from ...ext import AppTypes, http
89
from ...propagation.http import HTTPPropagator
910
from ...utils.formats import asbool, get_env
@@ -83,6 +84,10 @@ def patch_app_call(wrapped, instance, args, kwargs):
8384
pin.tracer.context_provider.activate(context)
8485

8586
with pin.tracer.trace('molten.request', service=pin.service, resource=resource) as span:
87+
# Configure trace search sample rate
88+
if config.molten.event_sample_rate is not None:
89+
span.set_tag(EVENT_SAMPLE_RATE_KEY, config.molten.event_sample_rate)
90+
8691
@wrapt.function_wrapper
8792
def _w_start_response(wrapped, instance, args, kwargs):
8893
""" Patch respond handling to set metadata """

0 commit comments

Comments
 (0)