Skip to content

Commit b678001

Browse files
authored
Merge branch 'master' into feat/grpc-aio-integration
2 parents b0e6d19 + 52eb367 commit b678001

Some content is hidden

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

45 files changed

+1540
-450
lines changed

.craft.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ targets:
1414
- name: python
1515
versions:
1616
# The number of versions must be, at most, the maximum number of
17-
# runtimes AWS Lambda permits for a layer.
17+
# runtimes AWS Lambda permits for a layer (currently 15).
1818
# On the other hand, AWS Lambda does not support every Python runtime.
1919
# The supported runtimes are available in the following link:
2020
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-python.html
21-
- python3.6
2221
- python3.7
2322
- python3.8
2423
- python3.9
24+
- python3.10
25+
- python3.11
2526
license: MIT
2627
- name: sentry-pypi
2728
internalPypiRepo: getsentry/pypi

.github/workflows/test-common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
fail-fast: false
3333
matrix:
34-
python-version: ["3.5","3.6","3.7","3.8","3.9","3.10","3.11"]
34+
python-version: ["3.5","3.6","3.7","3.8","3.9","3.10","3.11","3.12"]
3535
# python3.6 reached EOL and is no longer being supported on
3636
# new versions of hosted runners on Github Actions
3737
# ubuntu-20.04 is the last version that supported python3.6

.github/workflows/test-integration-aws_lambda.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ permissions:
1818
contents: read
1919

2020
env:
21+
SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID: ${{ secrets.SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID }}
22+
SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY: ${{ secrets.SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY }}
2123
BUILD_CACHE_KEY: ${{ github.sha }}
2224
CACHED_BUILD_PATHS: |
2325
${{ github.workspace }}/dist-serverless
@@ -31,7 +33,7 @@ jobs:
3133
strategy:
3234
fail-fast: false
3335
matrix:
34-
python-version: ["3.7"]
36+
python-version: ["3.9"]
3537
# python3.6 reached EOL and is no longer being supported on
3638
# new versions of hosted runners on Github Actions
3739
# ubuntu-20.04 is the last version that supported python3.6

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# Changelog
22

3+
## 1.34.0
4+
5+
### Various fixes & improvements
6+
- Added Python 3.12 support (#2471, #2483)
7+
- Handle missing `connection_kwargs` in `patch_redis_client` (#2482) by @szokeasaurusrex
8+
- Run common test suite on Python 3.12 (#2479) by @sentrivana
9+
10+
## 1.33.1
11+
12+
### Various fixes & improvements
13+
14+
- Make parse_version work in utils.py itself. (#2474) by @antonpirker
15+
16+
## 1.33.0
17+
18+
### Various fixes & improvements
19+
20+
- New: Added `error_sampler` option (#2456) by @szokeasaurusrex
21+
- Python 3.12: Detect interpreter in shutdown state on thread spawn (#2468) by @mitsuhiko
22+
- Patch eventlet under Sentry SDK (#2464) by @szokeasaurusrex
23+
- Mitigate CPU spikes when sending lots of events with lots of data (#2449) by @antonpirker
24+
- Make `debug` option also configurable via environment (#2450) by @antonpirker
25+
- Make sure `get_dsn_parameters` is an actual function (#2441) by @sentrivana
26+
- Bump pytest-localserver, add compat comment (#2448) by @sentrivana
27+
- AWS Lambda: Update compatible runtimes for AWS Lambda layer (#2453) by @antonpirker
28+
- AWS Lambda: Load AWS Lambda secrets in Github CI (#2153) by @antonpirker
29+
- Redis: Connection attributes in `redis` database spans (#2398) by @antonpirker
30+
- Falcon: Falcon integration checks response status before reporting error (#2465) by @szokeasaurusrex
31+
- Quart: Support Quart 0.19 onwards (#2403) by @pgjones
32+
- Sanic: Sanic integration initial version (#2419) by @szokeasaurusrex
33+
- Django: Fix parsing of Django `path` patterns (#2452) by @sentrivana
34+
- Django: Add Django 4.2 to test suite (#2462) by @sentrivana
35+
- Polish changelog (#2434) by @sentrivana
36+
- Update CONTRIBUTING.md (#2443) by @krishvsoni
37+
- Update README.md (#2435) by @sentrivana
38+
339
## 1.32.0
440

541
### Various fixes & improvements

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Before you can contribute, you will need to [fork the `sentry-python` repository
3333
### Create a Virtual Environment
3434

3535
To keep your Python development environment and packages separate from the ones
36-
used by your operation system, create a virtual environment:
36+
used by your operation system, create a [virtual environment](https://docs.python.org/3/tutorial/venv.html):
3737

3838
```bash
3939
cd sentry-python

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ apidocs-hotfix: apidocs
6060
.PHONY: apidocs-hotfix
6161

6262
aws-lambda-layer: dist
63-
$(VENV_PATH)/bin/pip install urllib3
64-
$(VENV_PATH)/bin/pip install certifi
63+
$(VENV_PATH)/bin/pip install -r aws-lambda-layer-requirements.txt
6564
$(VENV_PATH)/bin/python -m scripts.build_aws_lambda_layer
6665
.PHONY: aws-lambda-layer

aws-lambda-layer-requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
certifi
2+
3+
# In Lambda functions botocore is used, and botocore is not
4+
# yet supporting urllib3 1.27.0 never mind 2+.
5+
# So we pin this here to make our Lambda layer work with
6+
# Lambda Function using Python 3.7+
7+
urllib3<1.27

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
3131
author = "Sentry Team and Contributors"
3232

33-
release = "1.32.0"
33+
release = "1.34.0"
3434
version = ".".join(release.split(".")[:2]) # The short X.Y version.
3535

3636

scripts/aws-cleanup.sh

100644100755
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#!/bin/sh
2-
# Delete all AWS Lambda functions
2+
#
3+
# Helper script to clean up AWS Lambda functions created
4+
# by the test suite (tests/integrations/aws_lambda/test_aws.py).
5+
#
6+
# This will delete all Lambda functions named `test_function_*`.
7+
#
38

9+
export AWS_DEFAULT_REGION="us-east-1"
410
export AWS_ACCESS_KEY_ID="$SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID"
511
export AWS_SECRET_ACCESS_KEY="$SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY"
6-
export AWS_IAM_ROLE="$SENTRY_PYTHON_TEST_AWS_IAM_ROLE"
712

8-
for func in $(aws lambda list-functions | jq -r .Functions[].FunctionName); do
13+
for func in $(aws lambda list-functions --output text --query 'Functions[?starts_with(FunctionName, `test_`) == `true`].FunctionName'); do
914
echo "Deleting $func"
10-
aws lambda delete-function --function-name $func
15+
aws lambda delete-function --function-name "$func"
1116
done
17+
18+
echo "All done! Have a nice day!"

scripts/aws-deploy-local-layer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ aws lambda publish-layer-version \
2222
--region "eu-central-1" \
2323
--zip-file "fileb://dist/$ZIP" \
2424
--description "Local test build of SentryPythonServerlessSDK (can be deleted)" \
25-
--compatible-runtimes python3.6 python3.7 python3.8 python3.9
25+
--compatible-runtimes python3.7 python3.8 python3.9 python3.10 python3.11 \
2626
--no-cli-pager
2727

2828
echo "Done deploying zipped Lambda layer to AWS as 'SentryPythonServerlessSDK-local-dev'."

scripts/build_aws_lambda_layer.py

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import os
22
import shutil
33
import subprocess
4+
import sys
45
import tempfile
6+
from typing import TYPE_CHECKING
57

68
from sentry_sdk.consts import VERSION as SDK_VERSION
79

10+
if TYPE_CHECKING:
11+
from typing import Optional
12+
813
DIST_PATH = "dist" # created by "make dist" that is called by "make aws-lambda-layer"
914
PYTHON_SITE_PACKAGES = "python" # see https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path
1015

@@ -13,18 +18,38 @@ class LayerBuilder:
1318
def __init__(
1419
self,
1520
base_dir, # type: str
21+
out_zip_filename=None, # type: Optional[str]
1622
):
1723
# type: (...) -> None
1824
self.base_dir = base_dir
1925
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)
20-
self.out_zip_filename = f"sentry-python-serverless-{SDK_VERSION}.zip"
26+
self.out_zip_filename = (
27+
f"sentry-python-serverless-{SDK_VERSION}.zip"
28+
if out_zip_filename is None
29+
else out_zip_filename
30+
)
2131

2232
def make_directories(self):
2333
# type: (...) -> None
2434
os.makedirs(self.python_site_packages)
2535

2636
def install_python_packages(self):
2737
# type: (...) -> None
38+
# Install requirements for Lambda Layer (these are more limited than the SDK requirements,
39+
# because Lambda does not support the newest versions of some packages)
40+
subprocess.check_call(
41+
[
42+
sys.executable,
43+
"-m",
44+
"pip",
45+
"install",
46+
"-r",
47+
"aws-lambda-layer-requirements.txt",
48+
"--target",
49+
self.python_site_packages,
50+
],
51+
)
52+
2853
sentry_python_sdk = os.path.join(
2954
DIST_PATH,
3055
f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lamber-layer"
@@ -34,6 +59,7 @@ def install_python_packages(self):
3459
"pip",
3560
"install",
3661
"--no-cache-dir", # always access PyPI
62+
"--no-deps", # the right depencencies have been installed in the call above
3763
"--quiet",
3864
sentry_python_sdk,
3965
"--target",
@@ -80,13 +106,34 @@ def zip(self):
80106
)
81107

82108

83-
def build_packaged_zip():
84-
with tempfile.TemporaryDirectory() as base_dir:
85-
layer_builder = LayerBuilder(base_dir)
86-
layer_builder.make_directories()
87-
layer_builder.install_python_packages()
88-
layer_builder.create_init_serverless_sdk_package()
89-
layer_builder.zip()
109+
def build_packaged_zip(base_dir=None, make_dist=False, out_zip_filename=None):
110+
if base_dir is None:
111+
base_dir = tempfile.mkdtemp()
112+
113+
if make_dist:
114+
# Same thing that is done by "make dist"
115+
# (which is a dependency of "make aws-lambda-layer")
116+
subprocess.check_call(
117+
[sys.executable, "setup.py", "sdist", "bdist_wheel", "-d", DIST_PATH],
118+
)
119+
120+
layer_builder = LayerBuilder(base_dir, out_zip_filename=out_zip_filename)
121+
layer_builder.make_directories()
122+
layer_builder.install_python_packages()
123+
layer_builder.create_init_serverless_sdk_package()
124+
layer_builder.zip()
125+
126+
# Just for debugging
127+
dist_path = os.path.abspath(DIST_PATH)
128+
print("Created Lambda Layer package with this information:")
129+
print(" - Base directory for generating package: {}".format(layer_builder.base_dir))
130+
print(
131+
" - Created Python SDK distribution (in `{}`): {}".format(dist_path, make_dist)
132+
)
133+
if not make_dist:
134+
print(" If 'False' we assume it was already created (by 'make dist')")
135+
print(" - Package zip filename: {}".format(layer_builder.out_zip_filename))
136+
print(" - Copied package zip to: {}".format(dist_path))
90137

91138

92139
if __name__ == "__main__":
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID: ${{ secrets.SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID }}
2+
SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY: ${{ secrets.SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY }}

scripts/split-tox-gh-actions/ci-yaml.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ permissions:
1818
contents: read
1919

2020
env:
21+
{{ aws_credentials }}
2122
BUILD_CACHE_KEY: ${{ github.sha }}
2223
CACHED_BUILD_PATHS: |
2324
${{ github.workspace }}/dist-serverless

scripts/split-tox-gh-actions/split-tox-gh-actions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TEMPLATE_FILE = TEMPLATE_DIR / "ci-yaml.txt"
2929
TEMPLATE_FILE_SERVICES = TEMPLATE_DIR / "ci-yaml-services.txt"
3030
TEMPLATE_FILE_SETUP_DB = TEMPLATE_DIR / "ci-yaml-setup-db.txt"
31+
TEMPLATE_FILE_AWS_CREDENTIALS = TEMPLATE_DIR / "ci-yaml-aws-credentials.txt"
3132
TEMPLATE_SNIPPET_TEST = TEMPLATE_DIR / "ci-yaml-test-snippet.txt"
3233
TEMPLATE_SNIPPET_TEST_PY27 = TEMPLATE_DIR / "ci-yaml-test-py27-snippet.txt"
3334

@@ -40,6 +41,10 @@
4041
"clickhouse_driver",
4142
]
4243

44+
FRAMEWORKS_NEEDING_AWS = [
45+
"aws_lambda",
46+
]
47+
4348
MATRIX_DEFINITION = """
4449
strategy:
4550
fail-fast: false
@@ -128,6 +133,11 @@ def write_yaml_file(
128133
f = open(TEMPLATE_FILE_SETUP_DB, "r")
129134
out += "".join(f.readlines())
130135

136+
elif template_line.strip() == "{{ aws_credentials }}":
137+
if current_framework in FRAMEWORKS_NEEDING_AWS:
138+
f = open(TEMPLATE_FILE_AWS_CREDENTIALS, "r")
139+
out += "".join(f.readlines())
140+
131141
elif template_line.strip() == "{{ additional_uses }}":
132142
if current_framework in FRAMEWORKS_NEEDING_CLICKHOUSE:
133143
out += ADDITIONAL_USES_CLICKHOUSE

sentry_sdk/client.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ def _get_options(*args, **kwargs):
109109
if rv["environment"] is None:
110110
rv["environment"] = os.environ.get("SENTRY_ENVIRONMENT") or "production"
111111

112+
if rv["debug"] is None:
113+
rv["debug"] = os.environ.get("SENTRY_DEBUG", "False").lower() in (
114+
"true",
115+
"1",
116+
"t",
117+
)
118+
112119
if rv["server_name"] is None and hasattr(socket, "gethostname"):
113120
rv["server_name"] = socket.gethostname()
114121

@@ -447,12 +454,34 @@ def _should_capture(
447454
def _should_sample_error(
448455
self,
449456
event, # type: Event
457+
hint, # type: Hint
450458
):
451459
# type: (...) -> bool
452-
not_in_sample_rate = (
453-
self.options["sample_rate"] < 1.0
454-
and random.random() >= self.options["sample_rate"]
455-
)
460+
sampler = self.options.get("error_sampler", None)
461+
462+
if callable(sampler):
463+
with capture_internal_exceptions():
464+
sample_rate = sampler(event, hint)
465+
else:
466+
sample_rate = self.options["sample_rate"]
467+
468+
try:
469+
not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate
470+
except TypeError:
471+
parameter, verb = (
472+
("error_sampler", "returned")
473+
if callable(sampler)
474+
else ("sample_rate", "contains")
475+
)
476+
logger.warning(
477+
"The provided %s %s an invalid value of %s. The value should be a float or a bool. Defaulting to sampling the event."
478+
% (parameter, verb, repr(sample_rate))
479+
)
480+
481+
# If the sample_rate has an invalid value, we should sample the event, since the default behavior
482+
# (when no sample_rate or error_sampler is provided) is to sample all events.
483+
not_in_sample_rate = False
484+
456485
if not_in_sample_rate:
457486
# because we will not sample this event, record a "lost event".
458487
if self.transport:
@@ -549,7 +578,7 @@ def capture_event(
549578
if (
550579
not is_transaction
551580
and not is_checkin
552-
and not self._should_sample_error(event)
581+
and not self._should_sample_error(event, hint)
553582
):
554583
return None
555584

0 commit comments

Comments
 (0)