Skip to content

Commit 896fcb7

Browse files
authored
Merge branch 'master' into txiao/feat/set-active-thread-id-for-quart
2 parents 073e658 + 72455f4 commit 896fcb7

34 files changed

+1238
-218
lines changed

Diff for: .github/workflows/test-common.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# ubuntu-20.04 is the last version that supported python3.6
3030
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
3131
os: [ubuntu-20.04]
32-
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10"]
32+
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
3333
services:
3434
postgres:
3535
image: postgres

Diff for: .github/workflows/test-integration-huey.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test huey
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/**
8+
9+
pull_request:
10+
11+
# Cancel in progress workflows on pull_requests.
12+
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
16+
17+
permissions:
18+
contents: read
19+
20+
env:
21+
BUILD_CACHE_KEY: ${{ github.sha }}
22+
CACHED_BUILD_PATHS: |
23+
${{ github.workspace }}/dist-serverless
24+
25+
jobs:
26+
test:
27+
name: huey, python ${{ matrix.python-version }}, ${{ matrix.os }}
28+
runs-on: ${{ matrix.os }}
29+
timeout-minutes: 45
30+
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
python-version: ["2.7","3.5","3.6","3.7","3.8","3.9","3.10","3.11"]
35+
# python3.6 reached EOL and is no longer being supported on
36+
# new versions of hosted runners on Github Actions
37+
# ubuntu-20.04 is the last version that supported python3.6
38+
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
39+
os: [ubuntu-20.04]
40+
41+
steps:
42+
- uses: actions/checkout@v3
43+
- uses: actions/setup-python@v4
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
47+
- name: Setup Test Env
48+
run: |
49+
pip install codecov "tox>=3,<4"
50+
51+
- name: Test huey
52+
timeout-minutes: 45
53+
shell: bash
54+
run: |
55+
set -x # print commands that are executed
56+
coverage erase
57+
58+
./scripts/runtox.sh "${{ matrix.python-version }}-huey" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
59+
coverage combine .coverage*
60+
coverage xml -i
61+
codecov --file coverage.xml
62+
63+
check_required_tests:
64+
name: All huey tests passed or skipped
65+
needs: test
66+
# Always run this, even if a dependent job failed
67+
if: always()
68+
runs-on: ubuntu-20.04
69+
steps:
70+
- name: Check for failures
71+
if: contains(needs.test.result, 'failure')
72+
run: |
73+
echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1

Diff for: CHANGELOG.md

+110
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,115 @@
11
# Changelog
22

3+
## 1.15.0
4+
5+
### Various fixes & improvements
6+
7+
- New: Add [Huey](https://huey.readthedocs.io/en/latest/) Integration (#1555) by @Zhenay
8+
9+
This integration will create performance spans when Huey tasks will be enqueued and when they will be executed.
10+
11+
Usage:
12+
13+
Task definition in `demo.py`:
14+
15+
```python
16+
import time
17+
18+
from huey import SqliteHuey, crontab
19+
20+
import sentry_sdk
21+
from sentry_sdk.integrations.huey import HueyIntegration
22+
23+
sentry_sdk.init(
24+
dsn="...",
25+
integrations=[
26+
HueyIntegration(),
27+
],
28+
traces_sample_rate=1.0,
29+
)
30+
31+
huey = SqliteHuey(filename='/tmp/demo.db')
32+
33+
@huey.task()
34+
def add_numbers(a, b):
35+
return a + b
36+
```
37+
38+
Running the tasks in `run.py`:
39+
40+
```python
41+
from demo import add_numbers, flaky_task, nightly_backup
42+
43+
import sentry_sdk
44+
from sentry_sdk.integrations.huey import HueyIntegration
45+
from sentry_sdk.tracing import TRANSACTION_SOURCE_COMPONENT, Transaction
46+
47+
48+
def main():
49+
sentry_sdk.init(
50+
dsn="...",
51+
integrations=[
52+
HueyIntegration(),
53+
],
54+
traces_sample_rate=1.0,
55+
)
56+
57+
with sentry_sdk.start_transaction(name="testing_huey_tasks", source=TRANSACTION_SOURCE_COMPONENT):
58+
r = add_numbers(1, 2)
59+
60+
if __name__ == "__main__":
61+
main()
62+
```
63+
64+
- Profiling: Do not send single sample profiles (#1879) by @Zylphrex
65+
- Profiling: Add additional test coverage for profiler (#1877) by @Zylphrex
66+
- Profiling: Always use builtin time.sleep (#1869) by @Zylphrex
67+
- Profiling: Defaul in_app decision to None (#1855) by @Zylphrex
68+
- Profiling: Remove use of threading.Event (#1864) by @Zylphrex
69+
- Profiling: Enable profiling on all transactions (#1797) by @Zylphrex
70+
- FastAPI: Fix check for Starlette in FastAPI integration (#1868) by @antonpirker
71+
- Flask: Do not overwrite default for username with email address in FlaskIntegration (#1873) by @homeworkprod
72+
- Tests: Add py3.11 to test-common (#1871) by @Zylphrex
73+
- Fix: Don't log whole event in before_send / event_processor drops (#1863) by @sl0thentr0py
74+
75+
## 1.14.0
76+
77+
### Various fixes & improvements
78+
79+
- Add `before_send_transaction` (#1840) by @antonpirker
80+
81+
Adds a hook (similar to `before_send`) that is called for all transaction events (performance releated data).
82+
83+
Usage:
84+
85+
```python
86+
import sentry_sdk
87+
88+
def strip_sensitive_data(event, hint):
89+
# modify event here (or return `None` if you want to drop the event entirely)
90+
return event
91+
92+
sentry_sdk.init(
93+
# ...
94+
before_send_transaction=strip_sensitive_data,
95+
)
96+
```
97+
98+
See also: https://docs.sentry.io/platforms/python/configuration/filtering/#using-platformidentifier-namebefore-send-transaction-
99+
100+
- Django: Always remove values of Django session related cookies. (#1842) by @antonpirker
101+
- Profiling: Enable profiling for ASGI frameworks (#1824) by @Zylphrex
102+
- Profiling: Better gevent support (#1822) by @Zylphrex
103+
- Profiling: Add profile context to transaction (#1860) by @Zylphrex
104+
- Profiling: Use co_qualname in python 3.11 (#1831) by @Zylphrex
105+
- OpenTelemetry: fix Use dict for sentry-trace context instead of tuple (#1847) by @AbhiPrasad
106+
- OpenTelemetry: fix extra dependency (#1825) by @bernardotorres
107+
- OpenTelemetry: fix NoOpSpan updates scope (#1834) by @Zylphrex
108+
- OpenTelemetry: Make sure to noop when there is no DSN (#1852) by @antonpirker
109+
- FastAPI: Fix middleware being patched multiple times (#1841) by @JohnnyDeuss
110+
- Starlette: Avoid import of pkg_resource with Starlette integration (#1836) by @mgu
111+
- Removed code coverage target (#1862) by @antonpirker
112+
3113
## 1.13.0
4114

5115
### Various fixes & improvements

Diff for: codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ coverage:
55
patch:
66
default: false
77
python:
8-
target: 90%
8+
target: 65%
99
comment: false
1010
ignore:
1111
- "tests"

Diff for: docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
copyright = "2019, Sentry Team and Contributors"
3030
author = "Sentry Team and Contributors"
3131

32-
release = "1.13.0"
32+
release = "1.15.0"
3333
version = ".".join(release.split(".")[:2]) # The short X.Y version.
3434

3535

Diff for: mypy.ini

+2
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ disallow_untyped_defs = False
6363
ignore_missing_imports = True
6464
[mypy-flask.signals]
6565
ignore_missing_imports = True
66+
[mypy-huey.*]
67+
ignore_missing_imports = True

Diff for: sentry_sdk/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def _prepare_event(
241241
with capture_internal_exceptions():
242242
new_event = before_send(event, hint or {})
243243
if new_event is None:
244-
logger.info("before send dropped event (%s)", event)
244+
logger.info("before send dropped event")
245245
if self.transport:
246246
self.transport.record_lost_event(
247247
"before_send", data_category="error"
@@ -254,7 +254,7 @@ def _prepare_event(
254254
with capture_internal_exceptions():
255255
new_event = before_send_transaction(event, hint or {})
256256
if new_event is None:
257-
logger.info("before send transaction dropped event (%s)", event)
257+
logger.info("before send transaction dropped event")
258258
if self.transport:
259259
self.transport.record_lost_event(
260260
"before_send", data_category="transaction"

Diff for: sentry_sdk/consts.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
DEFAULT_QUEUE_SIZE = 100
4545
DEFAULT_MAX_BREADCRUMBS = 100
4646

47+
SENSITIVE_DATA_SUBSTITUTE = "[Filtered]"
48+
4749

4850
class INSTRUMENTER:
4951
SENTRY = "sentry"
@@ -70,6 +72,8 @@ class OP:
7072
QUEUE_SUBMIT_CELERY = "queue.submit.celery"
7173
QUEUE_TASK_CELERY = "queue.task.celery"
7274
QUEUE_TASK_RQ = "queue.task.rq"
75+
QUEUE_SUBMIT_HUEY = "queue.submit.huey"
76+
QUEUE_TASK_HUEY = "queue.task.huey"
7377
SUBPROCESS = "subprocess"
7478
SUBPROCESS_WAIT = "subprocess.wait"
7579
SUBPROCESS_COMMUNICATE = "subprocess.communicate"
@@ -142,4 +146,4 @@ def _get_default_options():
142146
del _get_default_options
143147

144148

145-
VERSION = "1.13.0"
149+
VERSION = "1.15.0"

Diff for: sentry_sdk/hub.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentry_sdk.consts import INSTRUMENTER
99
from sentry_sdk.scope import Scope
1010
from sentry_sdk.client import Client
11+
from sentry_sdk.profiler import Profile
1112
from sentry_sdk.tracing import NoOpSpan, Span, Transaction
1213
from sentry_sdk.session import Session
1314
from sentry_sdk.utils import (
@@ -548,6 +549,9 @@ def start_transaction(
548549
sampling_context.update(custom_sampling_context)
549550
transaction._set_initial_sampling_decision(sampling_context=sampling_context)
550551

552+
profile = Profile(transaction, hub=self)
553+
profile._set_initial_sampling_decision(sampling_context=sampling_context)
554+
551555
# we don't bother to keep spans if we already know we're not going to
552556
# send the transaction
553557
if transaction.sampled:

Diff for: sentry_sdk/integrations/asgi.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from sentry_sdk.hub import Hub, _should_send_default_pii
1515
from sentry_sdk.integrations._wsgi_common import _filter_headers
1616
from sentry_sdk.integrations.modules import _get_installed_modules
17-
from sentry_sdk.profiler import start_profiling
1817
from sentry_sdk.sessions import auto_session_tracking
1918
from sentry_sdk.tracing import (
2019
SOURCE_FOR_STYLE,
@@ -176,7 +175,7 @@ async def _run_app(self, scope, callback):
176175

177176
with hub.start_transaction(
178177
transaction, custom_sampling_context={"asgi_scope": scope}
179-
), start_profiling(transaction, hub):
178+
):
180179
# XXX: Would be cool to have correct span status, but we
181180
# would have to wrap send(). That is a bit hard to do with
182181
# the current abstraction over ASGI 2/3.

Diff for: sentry_sdk/integrations/django/__init__.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import weakref
77

88
from sentry_sdk._types import MYPY
9-
from sentry_sdk.consts import OP
9+
from sentry_sdk.consts import OP, SENSITIVE_DATA_SUBSTITUTE
1010
from sentry_sdk.hub import Hub, _should_send_default_pii
1111
from sentry_sdk.scope import add_global_event_processor
1212
from sentry_sdk.serializer import add_global_repr_processor
1313
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_URL
1414
from sentry_sdk.tracing_utils import record_sql_queries
1515
from sentry_sdk.utils import (
16+
AnnotatedValue,
1617
HAS_REAL_CONTEXTVARS,
1718
CONTEXTVARS_ERROR_MESSAGE,
1819
logger,
@@ -28,6 +29,7 @@
2829

2930
try:
3031
from django import VERSION as DJANGO_VERSION
32+
from django.conf import settings as django_settings
3133
from django.core import signals
3234

3335
try:
@@ -476,8 +478,20 @@ def env(self):
476478
return self.request.META
477479

478480
def cookies(self):
479-
# type: () -> Dict[str, str]
480-
return self.request.COOKIES
481+
# type: () -> Dict[str, Union[str, AnnotatedValue]]
482+
privacy_cookies = [
483+
django_settings.CSRF_COOKIE_NAME,
484+
django_settings.SESSION_COOKIE_NAME,
485+
]
486+
487+
clean_cookies = {} # type: Dict[str, Union[str, AnnotatedValue]]
488+
for (key, val) in self.request.COOKIES.items():
489+
if key in privacy_cookies:
490+
clean_cookies[key] = SENSITIVE_DATA_SUBSTITUTE
491+
else:
492+
clean_cookies[key] = val
493+
494+
return clean_cookies
481495

482496
def raw_data(self):
483497
# type: () -> bytes

Diff for: sentry_sdk/integrations/django/asgi.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88

99
import asyncio
10-
import threading
1110

1211
from sentry_sdk import Hub, _functools
1312
from sentry_sdk._types import MYPY
@@ -92,7 +91,7 @@ async def sentry_wrapped_callback(request, *args, **kwargs):
9291

9392
with hub.configure_scope() as sentry_scope:
9493
if sentry_scope.profile is not None:
95-
sentry_scope.profile.active_thread_id = threading.current_thread().ident
94+
sentry_scope.profile.update_active_thread_id()
9695

9796
with hub.start_span(
9897
op=OP.VIEW_RENDER, description=request.resolver_match.view_name

Diff for: sentry_sdk/integrations/django/views.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import threading
2-
31
from sentry_sdk.consts import OP
42
from sentry_sdk.hub import Hub
53
from sentry_sdk._types import MYPY
@@ -79,7 +77,7 @@ def sentry_wrapped_callback(request, *args, **kwargs):
7977
# set the active thread id to the handler thread for sync views
8078
# this isn't necessary for async views since that runs on main
8179
if sentry_scope.profile is not None:
82-
sentry_scope.profile.active_thread_id = threading.current_thread().ident
80+
sentry_scope.profile.update_active_thread_id()
8381

8482
with hub.start_span(
8583
op=OP.VIEW_RENDER, description=request.resolver_match.view_name

0 commit comments

Comments
 (0)