Skip to content

Commit 14595b7

Browse files
Kyle-Verhoogmergify[bot]majorgreysDarcyRaynerDDYun-Kim
authored
Update 0.48 branch (#2265)
* fix typo in filter debug line (#2213) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * feat: support space separated DD_TAGS value (#2196) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Add sync mode to AgentWriter (#2206) * feat(agent): support aws lambda extension * chore: fix flake8 issue with test * chore: add release note for datadog lambda extension * chore: fix import order * chore: fix flake8 issue * [serverless] fix broken test * remove unused import * separate out sync writer changes * add integration tests for sync writer Co-authored-by: DarcyRaynerDD <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * ci: run django test suite with ddtrace enabled (#2203) * Run django test suite with ddtrace enabled * Added pylibmc install to fix build error * Added django/ddtrace install commands to separate blocks * Fixed annotation * Installed generic version of ddtrace instead of checking out * Added documentation * Changed working directory, removed inherently failing test * Reverted working directory change * Reverted skipping specific test, added pythonpath * Added more docs Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * ci: run flask test suite with ddtrace enabled (#2190) * ci: run flask test suite with ddtrace enabled * Update .github/workflows/flask.yml Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Kyle Verhoog <[email protected]> * docs: add note about pip version requirement (#2220) * handle logwriter configure (#2219) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * test: move __init__ to utils (#2217) Having code in tests/__init__ makes ddtrace being imported before we have a chance to do anything, such as calling gevent.monkey.patch_all. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * refactor: distributed_tracing_enabled usages to trace_utils helper (#2216) * Modified trace util helper to account for inconsistencies in distributed_tracing config key, refactored usages * Refactored traceutils helper * Made int_config optional in the trace_util helper, updated affected integration files * Removed erroneous code addition to pyramid/trace.py * Make tracer tests less noisy (#2221) monkeypatch.setenv warns if the value given is not an instance of the base string type. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * refactor(worker): replace regular thread by PeriodicThread (#2205) Co-authored-by: Tahir H. Butt <[email protected]> * Disable known failing Django tests (#2224) * Disable known failing Django tests * fix yaml multiline string Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * test(botocore): add test case for firehose args (#2227) This change adds a test case for #2204 to ensure that the params.Records argument is excluded from the span tags. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * refactor: move ddtrace.profiling._attr to ddtrace.utils (#2230) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Adding urllib3 integration (#1148) * draft of urllib3 integration * black formatting * set request tags on the span before the call is made in case of errors * rename span name and support retry tags based on CR feedback * add tests and fix a few small bugs * fix flake8 * add tests and circleci config * flake8 fixes * Update ddtrace/contrib/urllib3/__init__.py Co-Authored-By: Tahir H. Butt <[email protected]> * use dd compat for urlparse and unparse * use SpanType constants for type of span use SpanTypes.HTTP * fix tests * fix flake8 from merge conflict resolution * adapt to latest changes on master * adopt latest standards for integrations Use Pin to add patch information to urllib3 requests. Also use riot for configuring the test environment * apply checklist points * wip: make tests pass * set tags on exception also fixed the tests to override HTTP configuration where required * docs(urllib3): add urllib3 integration docs * fix service name handling * fix copy-pasta errors and improve documentation * Update ddtrace/contrib/urllib3/__init__.py Co-authored-by: Kyle Verhoog <[email protected]> * Update riotfile.py Co-authored-by: Kyle Verhoog <[email protected]> * remove unused imports from test sources * use the new get_argument_value utility * Update tests/contrib/urllib3/test_urllib3.py Co-authored-by: Kyle Verhoog <[email protected]> * Update ddtrace/contrib/urllib3/patch.py Co-authored-by: Kyle Verhoog <[email protected]> * commit Tahir's suggestions * fix TracerTestCase import Co-authored-by: Tahir H. Butt <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Kyle Verhoog <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Yun Kim <[email protected]> * Revert writer.write argument change (#2232) This is a breaking change which we're going to make at a later date. * Make processor private on Tracer (#2233) This isn't something we want to make public yet. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * fix(profiling): make sure PeriodicCollector start withing service lock (#2214) This makes sure the periodic collectors are started while the service lock is held to avoid race conditions while starting the services. This has no impact in practice since the Profiler class was made thread safe with #2179. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * refactor(forksafe): simplify code (#2222) This simplifies the code to use a banal decorator approach rather than a weird lambda-passed-as-argument-based 😉 It also adds typing and an `unregister` function to allow for… unregistering a function! Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * chore: correct typing hints for span.meta (#2237) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Lambda extension support (#2092) * feat(agent): support aws lambda extension * chore: fix flake8 issue with test * chore: add release note for datadog lambda extension * chore: fix import order * chore: fix flake8 issue * [serverless] fix broken test * remove unused import * Add docs, type hints Co-authored-by: Kyle Verhoog <[email protected]> Co-authored-by: Kyle Verhoog <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Yun Kim <[email protected]> * fix(span): ensure ID args have the correct type (#2243) Among all the arguments of the Span constructor, the ones bearing IDs are the most important type-wise. This change adds checks to ensure that span_id, trace_id and parent_id all have the expected type. The rationale for adding the check at construction time is so that this error could be caught as soon as possible, rather than defer it to later processing stages, thus avoiding invalid entries in the processing queue. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * fix: only warn if using uwsgi with ddtrace-run (#2202) * fix: only warn if using uwsgi with ddtrace-run * remove DeprecationWarning prefix * update message Co-authored-by: Brett Langdon <[email protected]> * Update ISSUE_TEMPLATE.md (#2248) * Use multiproject pipeline to deploy to reliability env (#2249) * Use multiproject pipeline for reliability env deploy * Use default branch Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * style(pymongo): format pymongo (#2250) * fix: handle text types in _set_str_tag (#2218) * chore: correct typing hints for span.meta * fix: handle text types in _set_str_tag * chore: correct typing hints for span.meta * fix: handle text types in _set_str_tag * fix: handle text types in _set_str_tag * flake8 * add doc string, fix test * fix grpc traceback tag Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Tahir H. Butt <[email protected]> Co-authored-by: DarcyRaynerDD <[email protected]> Co-authored-by: Yun Kim <[email protected]> Co-authored-by: Julien Danjou <[email protected]> Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Brett Langdon <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Justin <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Darcy Rayner <[email protected]> Co-authored-by: Laplie Anderson <[email protected]>
1 parent 66eab83 commit 14595b7

File tree

175 files changed

+2744
-1692
lines changed

Some content is hidden

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

175 files changed

+2744
-1692
lines changed

.circleci/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,16 @@ jobs:
928928
wait: rediscluster
929929
pattern: '^rediscluster_contrib-'
930930

931+
urllib3:
932+
<<: *contrib_job
933+
docker:
934+
- image: *ddtrace_dev_image
935+
- *httpbin_local
936+
resource_class: *resource_class
937+
steps:
938+
- run_test:
939+
pattern: 'urllib3'
940+
931941
vertica:
932942
<<: *contrib_job
933943
docker:
@@ -1106,6 +1116,7 @@ requires_tests: &requires_tests
11061116
- test_logging
11071117
- tracer
11081118
- tornado
1119+
- urllib3
11091120
- vertica
11101121
- wsgi
11111122
- build-docker-ci-image
@@ -1209,6 +1220,7 @@ workflows:
12091220
- test_logging: *requires_pre_test
12101221
- tornado: *requires_pre_test
12111222
- tracer: *requires_pre_test
1223+
- urllib3: *requires_pre_test
12121224
- vertica: *requires_pre_test
12131225
- wsgi: *requires_pre_test
12141226
- build-docker-ci-image: *requires_pre_test

.github/ISSUE_TEMPLATE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ library.
88

99
### Which version of dd-trace-py are you using?
1010

11+
### Which version of pip are you using?
12+
13+
_ddtrace requires pip>=18 to install one of our pre-built wheels_
14+
1115
### Which version of the libraries are you using?
1216

1317
You can copy/paste the output of `pip freeze` here.

.github/workflows/django.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: django-testsuite
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
jobs:
7+
django-testsuite-3_1_7:
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
working-directory: django
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
path: ddtrace
16+
- uses: actions/checkout@v2
17+
with:
18+
repository: django/django
19+
ref: 3.1.7
20+
path: django
21+
- uses: actions/setup-python@v2
22+
with:
23+
python-version: "3.8"
24+
- name: Install pylibmc's libmemcached package
25+
# Django-specific: pylibmc in Ubuntu requires libmemcached package
26+
run: sudo apt install libmemcached-dev zlib1g
27+
- name: Install dependencies
28+
# Django-specific: separate dependencies for tests
29+
run: pip install -r tests/requirements/py3.txt
30+
- name: Install ddtrace
31+
run: pip install ../ddtrace
32+
- name: Install django
33+
run: pip install ../django
34+
- name: Set Pythonpath
35+
run: echo "PYTHONPATH=." >> $GITHUB_ENV
36+
- name: Disable unsupported tests
37+
run: |
38+
# Note: test_supports_json_field_operational_error will fail with the tracer
39+
# DEV: Insert @skipUnless before the test definition
40+
# DEV: We need to escape the space indenting
41+
sed -i'' '/def test_supports_json_field_operational_error/i \ \ \ \ @skipUnless(False, "test not supported by dd-trace-py")' tests/backends/sqlite/test_features.py
42+
- name: Run tests
43+
# django.tests.requests module interferes with requests library patching in the tracer -> disable requests patch
44+
run: DD_TRACE_REQUESTS_ENABLED=0 ddtrace-run tests/runtests.py
45+
46+

.github/workflows/flask.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: flask-testsuite
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
flask-testsuite-1_1_2:
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: flask
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
path: ddtrace
17+
- uses: actions/checkout@v2
18+
with:
19+
repository: pallets/flask
20+
ref: 1.1.2
21+
path: flask
22+
- uses: actions/setup-python@v2
23+
with:
24+
python-version: '3.8'
25+
- name: Install tox
26+
run: pip install tox
27+
- name: Create tox env
28+
run: tox -e py38 --notest
29+
- name: Inject ddtrace
30+
run: .tox/py38/bin/pip install ../ddtrace
31+
- name: Add pytest configuration for ddtrace
32+
run: echo -e "[pytest]\nddtrace-patch-all = 1" > pytest.ini
33+
- name: Run tests
34+
# test_exception_propagation is broken upstream
35+
run: tox -e py38 -- -k 'not test_exception_propagation'

.gitlab-ci.yml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
stages:
22
- deploy
33

4-
variables:
5-
INDEX_FILE: index.txt
6-
74
.common: &common
85
tags: [ "runner:main", "size:large" ]
96

10-
copy_to_s3:
11-
<<: *common
7+
deploy_to_reliability_env:
128
stage: deploy
13-
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
14-
rules:
15-
- if: '$CI_COMMIT_BRANCH == "master"'
16-
when: on_success
17-
- if: '$CI_COMMIT_BRANCH == "staging"'
18-
when: on_success
19-
script:
20-
- export ACCESS_KEY_ID=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-py.secret_key_id --with-decryption --query "Parameter.Value" --out text)
21-
- export SECRET_ACCESS_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-py.secret_sec_key_id --with-decryption --query "Parameter.Value" --out text)
22-
- export AWS_ACCESS_KEY_ID=$ACCESS_KEY_ID
23-
- export AWS_SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY
24-
- echo $CI_COMMIT_REF_NAME >> $INDEX_FILE
25-
- echo $CI_COMMIT_SHA >> $INDEX_FILE
26-
- echo $GITLAB_USER_NAME >> $INDEX_FILE
27-
- aws s3 cp $INDEX_FILE s3://datadog-reliability-env/python/$INDEX_FILE
9+
when: on_success
10+
trigger:
11+
project: DataDog/datadog-reliability-env
12+
variables:
13+
UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME
14+
UPSTREAM_PROJECT_ID: $CI_PROJECT_ID
15+
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
16+
UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA
17+
FORCE_TRIGGER: $FORCE_TRIGGER

ddtrace/_worker.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import threading
21
from typing import Optional
32

3+
from .internal import periodic
44
from .internal.logger import get_logger
55

66

@@ -34,11 +34,11 @@ def __init__(
3434
:param daemon: Whether the worker should be a daemon.
3535
"""
3636

37-
self._thread = threading.Thread(target=self._target, name=name)
37+
self._thread = periodic.PeriodicThread(
38+
interval, target=self.run_periodic, name=name, on_shutdown=self.on_shutdown
39+
)
3840
self._thread.daemon = daemon
39-
self._stop = threading.Event()
4041
self.started = False
41-
self.interval = interval
4242

4343
def start(self):
4444
# type: () -> None
@@ -51,7 +51,7 @@ def stop(self):
5151
# type: () -> None
5252
"""Stop the worker."""
5353
_LOG.debug("Stopping %s thread", self._thread.name)
54-
self._stop.set()
54+
self._thread.stop()
5555

5656
def is_alive(self):
5757
# type: () -> bool
@@ -61,25 +61,12 @@ def join(self, timeout=None):
6161
# type: (Optional[float]) -> None
6262
return self._thread.join(timeout)
6363

64-
def _target(self):
65-
# type: () -> None
66-
while not self._stop.wait(self.interval):
67-
self.run_periodic()
68-
self._on_shutdown()
69-
7064
@staticmethod
7165
def run_periodic():
7266
# type: () -> None
7367
"""Method executed every interval."""
74-
pass
7568

76-
def _on_shutdown(self):
77-
# type: () -> None
78-
_LOG.debug("Shutting down %s thread", self._thread.name)
79-
self.on_shutdown()
80-
81-
@staticmethod
82-
def on_shutdown():
69+
def on_shutdown(self):
8370
# type: () -> None
8471
"""Method ran on worker shutdown."""
85-
pass
72+
_LOG.debug("Shutting down %s thread", self._thread.name)

ddtrace/commands/ddtrace_run.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ def main():
107107
if os.path.basename(executable) == "uwsgi":
108108
print(
109109
(
110-
"ddtrace-run is not supported with uwsgi. "
111-
"See https://ddtrace.readthedocs.io/en/stable/advanced_usage.html#uwsgi for details."
110+
"ddtrace-run has known compatibility issues with uWSGI where the "
111+
"tracer is not started properly in uWSGI workers which can cause "
112+
"broken behavior. It is recommended you remove ddtrace-run and "
113+
"update your uWSGI configuration following "
114+
"https://ddtrace.readthedocs.io/en/stable/advanced_usage.html#uwsgi."
112115
)
113116
)
114-
sys.exit(1)
115117

116118
try:
117119
# Raises OSError for permissions errors in Python 2

ddtrace/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
reraise = six.reraise
5050
reload_module = six.moves.reload_module # type: ignore[attr-defined]
5151

52+
ensure_text = six.ensure_text
5253
stringify = six.text_type
5354
string_type = six.string_types[0]
5455
binary_type = six.binary_type

ddtrace/contrib/aiohttp/middlewares.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from ...constants import SPAN_MEASURED_KEY
99
from ...ext import SpanTypes
1010
from ...ext import http
11-
from ...propagation.http import HTTPPropagator
1211
from ..asyncio import context_provider
1312

1413

@@ -34,14 +33,9 @@ def attach_context(request):
3433
# application configs
3534
tracer = app[CONFIG_KEY]["tracer"]
3635
service = app[CONFIG_KEY]["service"]
37-
distributed_tracing = app[CONFIG_KEY]["distributed_tracing_enabled"]
3836

3937
# Create a new context based on the propagated information.
40-
if distributed_tracing:
41-
context = HTTPPropagator.extract(request.headers)
42-
# Only need to active the new context if something was propagated
43-
if context.trace_id:
44-
tracer.context_provider.activate(context)
38+
trace_utils.activate_distributed_headers(tracer, int_config=app[CONFIG_KEY], request_headers=request.headers)
4539

4640
# trace the handler
4741
request_span = tracer.trace(

ddtrace/contrib/asgi/middleware.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
66
from ddtrace.ext import SpanTypes
77
from ddtrace.ext import http
8-
from ddtrace.propagation.http import HTTPPropagator
98

109
from .. import trace_utils
1110
from ...compat import reraise
@@ -88,10 +87,9 @@ async def __call__(self, scope, receive, send):
8887

8988
headers = _extract_headers(scope)
9089

91-
if self.integration_config.distributed_tracing:
92-
context = HTTPPropagator.extract(headers)
93-
if context.trace_id:
94-
self.tracer.context_provider.activate(context)
90+
trace_utils.activate_distributed_headers(
91+
self.tracer, int_config=self.integration_config, request_headers=headers
92+
)
9593

9694
resource = "{} {}".format(scope["method"], scope["path"])
9795

0 commit comments

Comments
 (0)