Skip to content

Commit a78055b

Browse files
authored
Merge pull request #918 from DataDog/0.25-dev
0.25.0
2 parents 4313f38 + 02c3e7a commit a78055b

File tree

184 files changed

+22439
-2070
lines changed

Some content is hidden

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

184 files changed

+22439
-2070
lines changed

.circleci/config.yml

Lines changed: 69 additions & 91 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ For example to run the tests for `redis-py` 2.10 on Python 3.5 and 3.6:
6262

6363
$ ./scripts/ddtest tox -e '{py35,py36}-redis{210}'
6464

65+
If you want to run a list of tox environment (as CircleCI does) based on a
66+
pattern, you can use the following command:
67+
68+
$ scripts/ddtest scripts/run-tox-scenario '^futures_contrib-'
6569

6670
### Continuous Integration
6771

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.24.0'
7+
__version__ = '0.25.0'
88

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

ddtrace/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class API(object):
102102
"""
103103
def __init__(self, hostname, port, headers=None, encoder=None, priority_sampling=False):
104104
self.hostname = hostname
105-
self.port = port
105+
self.port = int(port)
106106

107107
self._headers = headers or {}
108108
self._version = None
@@ -158,11 +158,11 @@ def send_traces(self, traces):
158158

159159
# the API endpoint is not available so we should downgrade the connection and re-try the call
160160
if response.status in [404, 415] and self._fallback:
161-
log.debug('calling endpoint "%s" but received %s; downgrading API', self._traces, response.status)
161+
log.debug("calling endpoint '%s' but received %s; downgrading API", self._traces, response.status)
162162
self._downgrade()
163163
return self.send_traces(traces)
164164

165-
log.debug("reported %d traces in %.5fs", len(traces), time.time() - start)
165+
log.debug('reported %d traces in %.5fs', len(traces), time.time() - start)
166166
return response
167167

168168
@deprecated(message='Sending services to the API is no longer necessary', version='1.0.0')
@@ -177,7 +177,7 @@ def _put(self, endpoint, data, count=0):
177177
headers = dict(self._headers)
178178
headers[TRACE_COUNT_HEADER] = str(count)
179179

180-
conn.request("PUT", endpoint, data, headers)
180+
conn.request('PUT', endpoint, data, headers)
181181

182182
# Parse the HTTPResponse into an API.Response
183183
# DEV: This will call `resp.read()` which must happen before the `conn.close()` below,

ddtrace/bootstrap/sitecustomize.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,43 @@
2020
# immediately patch logging if trace id injected
2121
from ddtrace import patch; patch(logging=True) # noqa
2222

23-
debug = os.environ.get("DATADOG_TRACE_DEBUG")
23+
debug = os.environ.get('DATADOG_TRACE_DEBUG')
2424

2525
# Set here a default logging format for basicConfig
2626

2727
# DEV: Once basicConfig is called here, future calls to it cannot be used to
2828
# change the formatter since it applies the formatter to the root handler only
2929
# upon initializing it the first time.
3030
# See https://github.com/python/cpython/blob/112e4afd582515fcdcc0cde5012a4866e5cfda12/Lib/logging/__init__.py#L1550
31-
if debug and debug.lower() == "true":
31+
if debug and debug.lower() == 'true':
3232
logging.basicConfig(level=logging.DEBUG, format=DD_LOG_FORMAT)
3333
else:
3434
logging.basicConfig(format=DD_LOG_FORMAT)
3535

3636
log = get_logger(__name__)
3737

3838
EXTRA_PATCHED_MODULES = {
39-
"bottle": True,
40-
"django": True,
41-
"falcon": True,
42-
"flask": True,
43-
"pylons": True,
44-
"pyramid": True,
39+
'bottle': True,
40+
'django': True,
41+
'falcon': True,
42+
'flask': True,
43+
'pylons': True,
44+
'pyramid': True,
4545
}
4646

4747

4848
def update_patched_modules():
49-
modules_to_patch = os.environ.get("DATADOG_PATCH_MODULES")
49+
modules_to_patch = os.environ.get('DATADOG_PATCH_MODULES')
5050
if not modules_to_patch:
5151
return
5252
for patch in modules_to_patch.split(','):
5353
if len(patch.split(':')) != 2:
54-
log.debug("skipping malformed patch instruction")
54+
log.debug('skipping malformed patch instruction')
5555
continue
5656

5757
module, should_patch = patch.split(':')
5858
if should_patch.lower() not in ['true', 'false']:
59-
log.debug("skipping malformed patch instruction for %s", module)
59+
log.debug('skipping malformed patch instruction for %s', module)
6060
continue
6161

6262
EXTRA_PATCHED_MODULES.update({module: should_patch.lower() == 'true'})
@@ -81,22 +81,22 @@ def add_global_tags(tracer):
8181
# Respect DATADOG_* environment variables in global tracer configuration
8282
# TODO: these variables are deprecated; use utils method and update our documentation
8383
# correct prefix should be DD_*
84-
enabled = os.environ.get("DATADOG_TRACE_ENABLED")
84+
enabled = os.environ.get('DATADOG_TRACE_ENABLED')
8585
hostname = os.environ.get('DD_AGENT_HOST', os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME'))
86-
port = os.environ.get("DATADOG_TRACE_AGENT_PORT")
87-
priority_sampling = os.environ.get("DATADOG_PRIORITY_SAMPLING")
86+
port = os.environ.get('DATADOG_TRACE_AGENT_PORT')
87+
priority_sampling = os.environ.get('DATADOG_PRIORITY_SAMPLING')
8888

8989
opts = {}
9090

91-
if enabled and enabled.lower() == "false":
92-
opts["enabled"] = False
91+
if enabled and enabled.lower() == 'false':
92+
opts['enabled'] = False
9393
patch = False
9494
if hostname:
95-
opts["hostname"] = hostname
95+
opts['hostname'] = hostname
9696
if port:
97-
opts["port"] = int(port)
97+
opts['port'] = int(port)
9898
if priority_sampling:
99-
opts["priority_sampling"] = asbool(priority_sampling)
99+
opts['priority_sampling'] = asbool(priority_sampling)
100100

101101
opts['collect_metrics'] = asbool(get_env('runtime_metrics', 'enabled'))
102102

@@ -110,12 +110,12 @@ def add_global_tags(tracer):
110110
update_patched_modules()
111111
from ddtrace import patch_all; patch_all(**EXTRA_PATCHED_MODULES) # noqa
112112

113-
debug = os.environ.get("DATADOG_TRACE_DEBUG")
114-
if debug and debug.lower() == "true":
113+
debug = os.environ.get('DATADOG_TRACE_DEBUG')
114+
if debug and debug.lower() == 'true':
115115
tracer.debug_logging = True
116116

117117
if 'DATADOG_ENV' in os.environ:
118-
tracer.set_tags({"env": os.environ["DATADOG_ENV"]})
118+
tracer.set_tags({'env': os.environ['DATADOG_ENV']})
119119

120120
if 'DD_TRACE_GLOBAL_TAGS' in os.environ:
121121
add_global_tags(tracer)
@@ -145,4 +145,4 @@ def add_global_tags(tracer):
145145
loaded = True
146146
except Exception as e:
147147
loaded = False
148-
log.warn("error configuring Datadog tracing", exc_info=True)
148+
log.warn('error configuring Datadog tracing', exc_info=True)

ddtrace/commands/ddtrace_run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import sys
55
import logging
66

7-
debug = os.environ.get("DATADOG_TRACE_DEBUG")
8-
if debug and debug.lower() == "true":
7+
debug = os.environ.get('DATADOG_TRACE_DEBUG')
8+
if debug and debug.lower() == 'true':
99
logging.basicConfig(level=logging.DEBUG)
1010

1111
# Do not use `ddtrace.internal.logger.get_logger` here
@@ -50,33 +50,33 @@ def _add_bootstrap_to_pythonpath(bootstrap_dir):
5050
python_path = os.environ.get('PYTHONPATH', '')
5151

5252
if python_path:
53-
new_path = "%s%s%s" % (bootstrap_dir, os.path.pathsep, os.environ['PYTHONPATH'])
53+
new_path = '%s%s%s' % (bootstrap_dir, os.path.pathsep, os.environ['PYTHONPATH'])
5454
os.environ['PYTHONPATH'] = new_path
5555
else:
5656
os.environ['PYTHONPATH'] = bootstrap_dir
5757

5858

5959
def main():
60-
if len(sys.argv) < 2 or sys.argv[1] == "-h":
60+
if len(sys.argv) < 2 or sys.argv[1] == '-h':
6161
print(USAGE)
6262
return
6363

64-
log.debug("sys.argv: %s", sys.argv)
64+
log.debug('sys.argv: %s', sys.argv)
6565

6666
root_dir = _ddtrace_root()
67-
log.debug("ddtrace root: %s", root_dir)
67+
log.debug('ddtrace root: %s', root_dir)
6868

6969
bootstrap_dir = os.path.join(root_dir, 'bootstrap')
70-
log.debug("ddtrace bootstrap: %s", bootstrap_dir)
70+
log.debug('ddtrace bootstrap: %s', bootstrap_dir)
7171

7272
_add_bootstrap_to_pythonpath(bootstrap_dir)
73-
log.debug("PYTHONPATH: %s", os.environ['PYTHONPATH'])
74-
log.debug("sys.path: %s", sys.path)
73+
log.debug('PYTHONPATH: %s', os.environ['PYTHONPATH'])
74+
log.debug('sys.path: %s', sys.path)
7575

7676
executable = sys.argv[1]
7777

7878
# Find the executable path
7979
executable = spawn.find_executable(executable)
80-
log.debug("program executable: %s", executable)
80+
log.debug('program executable: %s', executable)
8181

8282
os.execl(executable, executable, *sys.argv[2:])

ddtrace/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
ORIGIN_KEY = '_dd.origin'
66

77
NUMERIC_TAGS = (ANALYTICS_SAMPLE_RATE_KEY, )
8+
9+
MANUAL_DROP_KEY = 'manual.drop'
10+
MANUAL_KEEP_KEY = 'manual.keep'

ddtrace/contrib/aiohttp/middlewares.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def on_prepare(request, response):
9999
request_span.resource = resource
100100
request_span.set_tag('http.method', request.method)
101101
request_span.set_tag('http.status_code', response.status)
102-
request_span.set_tag('http.url', request.path)
102+
request_span.set_tag(http.URL, request.url.with_query(None))
103103
request_span.finish()
104104

105105

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
The Algoliasearch__ integration will add tracing to your Algolia searches.
3+
4+
::
5+
6+
from ddtrace import patch_all
7+
patch_all()
8+
9+
from algoliasearch import algoliasearch
10+
client = alogliasearch.Client(<ID>, <API_KEY>)
11+
index = client.init_index(<INDEX_NAME>)
12+
index.search("your query", args={"attributesToRetrieve": "attribute1,attribute1"})
13+
14+
Configuration
15+
~~~~~~~~~~~~~
16+
17+
.. py:data:: ddtrace.config.algoliasearch['collect_query_text']
18+
19+
Whether to pass the text of your query onto Datadog. Since this may contain sensitive data it's off by default
20+
21+
Default: ``False``
22+
23+
.. __: https://www.algolia.com
24+
"""
25+
26+
from ...utils.importlib import require_modules
27+
28+
with require_modules(['algoliasearch', 'algoliasearch.version']) as missing_modules:
29+
if not missing_modules:
30+
from .patch import patch, unpatch
31+
32+
__all__ = ['patch', 'unpatch']

0 commit comments

Comments
 (0)