diff --git a/.github/workflows/test-integrations-ai.yml b/.github/workflows/test-integrations-ai.yml index dd230a6461..c7cf4a1d85 100644 --- a/.github/workflows/test-integrations-ai.yml +++ b/.github/workflows/test-integrations-ai.yml @@ -78,7 +78,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -150,7 +150,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml diff --git a/.github/workflows/test-integrations-aws-lambda.yml b/.github/workflows/test-integrations-aws.yml similarity index 93% rename from .github/workflows/test-integrations-aws-lambda.yml rename to .github/workflows/test-integrations-aws.yml index c9837c08d0..67c0ec31c7 100644 --- a/.github/workflows/test-integrations-aws-lambda.yml +++ b/.github/workflows/test-integrations-aws.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test AWS Lambda +name: Test AWS on: push: branches: @@ -52,8 +52,8 @@ jobs: - name: Check permissions on repo branch if: github.event_name == 'push' run: true - test-aws_lambda-pinned: - name: AWS Lambda (pinned) + test-aws-pinned: + name: AWS (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -97,7 +97,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -112,13 +112,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned AWS Lambda tests passed - needs: test-aws_lambda-pinned + name: All pinned AWS tests passed + needs: test-aws-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-aws_lambda-pinned.result, 'failure') || contains(needs.test-aws_lambda-pinned.result, 'skipped') + if: contains(needs.test-aws-pinned.result, 'failure') || contains(needs.test-aws-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-cloud-computing.yml b/.github/workflows/test-integrations-cloud.yml similarity index 92% rename from .github/workflows/test-integrations-cloud-computing.yml rename to .github/workflows/test-integrations-cloud.yml index 3217811539..62d67200a5 100644 --- a/.github/workflows/test-integrations-cloud-computing.yml +++ b/.github/workflows/test-integrations-cloud.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Cloud Computing +name: Test Cloud on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-cloud_computing-latest: - name: Cloud Computing (latest) + test-cloud-latest: + name: Cloud (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -74,7 +74,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -88,8 +88,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-cloud_computing-pinned: - name: Cloud Computing (pinned) + test-cloud-pinned: + name: Cloud (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -142,7 +142,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -157,13 +157,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Cloud Computing tests passed - needs: test-cloud_computing-pinned + name: All pinned Cloud tests passed + needs: test-cloud-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-cloud_computing-pinned.result, 'failure') || contains(needs.test-cloud_computing-pinned.result, 'skipped') + if: contains(needs.test-cloud-pinned.result, 'failure') || contains(needs.test-cloud-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-common.yml b/.github/workflows/test-integrations-common.yml index 912eb3b18c..6983a079ef 100644 --- a/.github/workflows/test-integrations-common.yml +++ b/.github/workflows/test-integrations-common.yml @@ -62,7 +62,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml diff --git a/.github/workflows/test-integrations-databases.yml b/.github/workflows/test-integrations-dbs.yml similarity index 95% rename from .github/workflows/test-integrations-databases.yml rename to .github/workflows/test-integrations-dbs.yml index 2cdcd9d3b9..1612dfb432 100644 --- a/.github/workflows/test-integrations-databases.yml +++ b/.github/workflows/test-integrations-dbs.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Databases +name: Test DBs on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-databases-latest: - name: Databases (latest) + test-dbs-latest: + name: DBs (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -101,7 +101,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -115,8 +115,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-databases-pinned: - name: Databases (pinned) + test-dbs-pinned: + name: DBs (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -196,7 +196,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -211,13 +211,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Databases tests passed - needs: test-databases-pinned + name: All pinned DBs tests passed + needs: test-dbs-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-databases-pinned.result, 'failure') || contains(needs.test-databases-pinned.result, 'skipped') + if: contains(needs.test-dbs-pinned.result, 'failure') || contains(needs.test-dbs-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-graphql.yml b/.github/workflows/test-integrations-graphql.yml index 522dc2acc1..57d14cff10 100644 --- a/.github/workflows/test-integrations-graphql.yml +++ b/.github/workflows/test-integrations-graphql.yml @@ -74,7 +74,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -142,7 +142,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml diff --git a/.github/workflows/test-integrations-miscellaneous.yml b/.github/workflows/test-integrations-misc.yml similarity index 93% rename from .github/workflows/test-integrations-miscellaneous.yml rename to .github/workflows/test-integrations-misc.yml index 03d6559108..5f2baa5759 100644 --- a/.github/workflows/test-integrations-miscellaneous.yml +++ b/.github/workflows/test-integrations-misc.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Miscellaneous +name: Test Misc on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-miscellaneous-latest: - name: Miscellaneous (latest) + test-misc-latest: + name: Misc (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -86,7 +86,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -100,8 +100,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-miscellaneous-pinned: - name: Miscellaneous (pinned) + test-misc-pinned: + name: Misc (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -166,7 +166,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -181,13 +181,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Miscellaneous tests passed - needs: test-miscellaneous-pinned + name: All pinned Misc tests passed + needs: test-misc-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-miscellaneous-pinned.result, 'failure') || contains(needs.test-miscellaneous-pinned.result, 'skipped') + if: contains(needs.test-misc-pinned.result, 'failure') || contains(needs.test-misc-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-networking.yml b/.github/workflows/test-integrations-network.yml similarity index 93% rename from .github/workflows/test-integrations-networking.yml rename to .github/workflows/test-integrations-network.yml index 31342151e9..7c1c343aac 100644 --- a/.github/workflows/test-integrations-networking.yml +++ b/.github/workflows/test-integrations-network.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Networking +name: Test Network on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-networking-latest: - name: Networking (latest) + test-network-latest: + name: Network (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -74,7 +74,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -88,8 +88,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-networking-pinned: - name: Networking (pinned) + test-network-pinned: + name: Network (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -142,7 +142,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -157,13 +157,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Networking tests passed - needs: test-networking-pinned + name: All pinned Network tests passed + needs: test-network-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-networking-pinned.result, 'failure') || contains(needs.test-networking-pinned.result, 'skipped') + if: contains(needs.test-network-pinned.result, 'failure') || contains(needs.test-network-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-data-processing.yml b/.github/workflows/test-integrations-tasks.yml similarity index 94% rename from .github/workflows/test-integrations-data-processing.yml rename to .github/workflows/test-integrations-tasks.yml index 128463a66a..1c4259ac05 100644 --- a/.github/workflows/test-integrations-data-processing.yml +++ b/.github/workflows/test-integrations-tasks.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Data Processing +name: Test Tasks on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-data_processing-latest: - name: Data Processing (latest) + test-tasks-latest: + name: Tasks (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -92,7 +92,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -106,8 +106,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-data_processing-pinned: - name: Data Processing (pinned) + test-tasks-pinned: + name: Tasks (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -178,7 +178,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -193,13 +193,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Data Processing tests passed - needs: test-data_processing-pinned + name: All pinned Tasks tests passed + needs: test-tasks-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-data_processing-pinned.result, 'failure') || contains(needs.test-data_processing-pinned.result, 'skipped') + if: contains(needs.test-tasks-pinned.result, 'failure') || contains(needs.test-tasks-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-web-frameworks-1.yml b/.github/workflows/test-integrations-web-1.yml similarity index 93% rename from .github/workflows/test-integrations-web-frameworks-1.yml rename to .github/workflows/test-integrations-web-1.yml index 706feb385f..6a6a01e8ff 100644 --- a/.github/workflows/test-integrations-web-frameworks-1.yml +++ b/.github/workflows/test-integrations-web-1.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Web Frameworks 1 +name: Test Web 1 on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-web_frameworks_1-latest: - name: Web Frameworks 1 (latest) + test-web_1-latest: + name: Web 1 (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -92,7 +92,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -106,8 +106,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-web_frameworks_1-pinned: - name: Web Frameworks 1 (pinned) + test-web_1-pinned: + name: Web 1 (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -178,7 +178,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -193,13 +193,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Web Frameworks 1 tests passed - needs: test-web_frameworks_1-pinned + name: All pinned Web 1 tests passed + needs: test-web_1-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-web_frameworks_1-pinned.result, 'failure') || contains(needs.test-web_frameworks_1-pinned.result, 'skipped') + if: contains(needs.test-web_1-pinned.result, 'failure') || contains(needs.test-web_1-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/.github/workflows/test-integrations-web-frameworks-2.yml b/.github/workflows/test-integrations-web-2.yml similarity index 94% rename from .github/workflows/test-integrations-web-frameworks-2.yml rename to .github/workflows/test-integrations-web-2.yml index f700952e00..11cfc20612 100644 --- a/.github/workflows/test-integrations-web-frameworks-2.yml +++ b/.github/workflows/test-integrations-web-2.yml @@ -1,6 +1,6 @@ # Do not edit this file. This file is generated automatically by executing # python scripts/split-tox-gh-actions/split-tox-gh-actions.py -name: Test Web Frameworks 2 +name: Test Web 2 on: push: branches: @@ -20,8 +20,8 @@ env: CACHED_BUILD_PATHS: | ${{ github.workspace }}/dist-serverless jobs: - test-web_frameworks_2-latest: - name: Web Frameworks 2 (latest) + test-web_2-latest: + name: Web 2 (latest) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -98,7 +98,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -112,8 +112,8 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: .junitxml verbose: true - test-web_frameworks_2-pinned: - name: Web Frameworks 2 (pinned) + test-web_2-pinned: + name: Web 2 (pinned) timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: @@ -190,7 +190,7 @@ jobs: coverage xml - name: Upload coverage to Codecov if: ${{ !cancelled() }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml @@ -205,13 +205,13 @@ jobs: files: .junitxml verbose: true check_required_tests: - name: All pinned Web Frameworks 2 tests passed - needs: test-web_frameworks_2-pinned + name: All pinned Web 2 tests passed + needs: test-web_2-pinned # Always run this, even if a dependent job failed if: always() runs-on: ubuntu-20.04 steps: - name: Check for failures - if: contains(needs.test-web_frameworks_2-pinned.result, 'failure') || contains(needs.test-web_frameworks_2-pinned.result, 'skipped') + if: contains(needs.test-web_2-pinned.result, 'failure') || contains(needs.test-web_2-pinned.result, 'skipped') run: | echo "One of the dependent jobs has failed. You may need to re-run it." && exit 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index c47d0e0458..dbb35eb1eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +## 2.19.0 + +### Various fixes & improvements + +- New: introduce `rust_tracing` integration. See https://docs.sentry.io/platforms/python/integrations/rust_tracing/ (#3717) by @matt-codecov +- Auto enable Litestar integration (#3540) by @provinzkraut +- Deprecate `sentry_sdk.init` context manager (#3729) by @szokeasaurusrex +- feat(spotlight): Send PII to Spotlight when no DSN is set (#3804) by @BYK +- feat(spotlight): Add info logs when Sentry is enabled (#3735) by @BYK +- feat(spotlight): Inject Spotlight button on Django (#3751) by @BYK +- feat(spotlight): Auto enable cache_spans for Spotlight on DEBUG (#3791) by @BYK +- fix(logging): Handle parameter `stack_info` for the `LoggingIntegration` (#3745) by @gmcrocetti +- fix(pure-eval): Make sentry-sdk[pure-eval] installable with pip==24.0 (#3757) by @sentrivana +- fix(rust_tracing): include_tracing_fields arg to control unvetted data in rust_tracing integration (#3780) by @matt-codecov +- fix(aws) Fix aws lambda tests (by reducing event size) (#3770) by @antonpirker +- fix(arq): fix integration with Worker settings as a dict (#3742) by @saber-solooki +- fix(httpx): Prevent Sentry baggage duplication (#3728) by @szokeasaurusrex +- fix(falcon): Don't exhaust request body stream (#3768) by @szokeasaurusrex +- fix(integrations): Check `retries_left` before capturing exception (#3803) by @malkovro +- fix(openai): Use name instead of description (#3807) by @sourceful-rob +- test(gcp): Only run GCP tests when they should (#3721) by @szokeasaurusrex +- chore: Shorten CI workflow names (#3805) by @sentrivana +- chore: Test with pyspark prerelease (#3760) by @sentrivana +- build(deps): bump codecov/codecov-action from 4.6.0 to 5.0.2 (#3792) by @dependabot +- build(deps): bump actions/checkout from 4.2.1 to 4.2.2 (#3691) by @dependabot + ## 2.18.0 ### Various fixes & improvements diff --git a/docs/conf.py b/docs/conf.py index 6d33e5809a..55d5295381 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -31,7 +31,7 @@ copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year) author = "Sentry Team and Contributors" -release = "2.18.0" +release = "2.19.0" version = ".".join(release.split(".")[:2]) # The short X.Y version. diff --git a/scripts/split-tox-gh-actions/split-tox-gh-actions.py b/scripts/split-tox-gh-actions/split-tox-gh-actions.py index c0bf2a7a09..c4b8f3e5e5 100755 --- a/scripts/split-tox-gh-actions/split-tox-gh-actions.py +++ b/scripts/split-tox-gh-actions/split-tox-gh-actions.py @@ -65,18 +65,18 @@ "openai", "huggingface_hub", ], - "AWS Lambda": [ + "AWS": [ # this is separate from Cloud Computing because only this one test suite # needs to run with access to GitHub secrets "aws_lambda", ], - "Cloud Computing": [ + "Cloud": [ "boto3", "chalice", "cloud_resource_context", "gcp", ], - "Data Processing": [ + "Tasks": [ "arq", "beam", "celery", @@ -86,7 +86,7 @@ "rq", "spark", ], - "Databases": [ + "DBs": [ "asyncpg", "clickhouse_driver", "pymongo", @@ -100,19 +100,19 @@ "graphene", "strawberry", ], - "Networking": [ + "Network": [ "gevent", "grpc", "httpx", "requests", ], - "Web Frameworks 1": [ + "Web 1": [ "django", "flask", "starlette", "fastapi", ], - "Web Frameworks 2": [ + "Web 2": [ "aiohttp", "asgi", "bottle", @@ -124,7 +124,7 @@ "starlite", "tornado", ], - "Miscellaneous": [ + "Misc": [ "launchdarkly", "loguru", "openfeature", diff --git a/scripts/split-tox-gh-actions/templates/test_group.jinja b/scripts/split-tox-gh-actions/templates/test_group.jinja index 9055070c72..4560a7d42d 100644 --- a/scripts/split-tox-gh-actions/templates/test_group.jinja +++ b/scripts/split-tox-gh-actions/templates/test_group.jinja @@ -92,7 +92,7 @@ - name: Upload coverage to Codecov if: {% raw %}${{ !cancelled() }}{% endraw %} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %} files: coverage.xml diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index b1e7868031..db2cc19110 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -128,7 +128,11 @@ def _get_options(*args, **kwargs): rv["traces_sample_rate"] = 1.0 if rv["event_scrubber"] is None: - rv["event_scrubber"] = EventScrubber(send_default_pii=rv["send_default_pii"]) + rv["event_scrubber"] = EventScrubber( + send_default_pii=( + False if rv["send_default_pii"] is None else rv["send_default_pii"] + ) + ) if rv["socket_options"] and not isinstance(rv["socket_options"], list): logger.warning( @@ -451,7 +455,11 @@ def should_send_default_pii(self): Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry. """ - return self.options.get("send_default_pii", False) + result = self.options.get("send_default_pii") + if result is None: + result = not self.options["dsn"] and self.spotlight is not None + + return result @property def dsn(self): diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index a6531c6c30..6750e85f99 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -492,6 +492,7 @@ class OP: # This type exists to trick mypy and PyCharm into thinking `init` and `Client` # take these arguments (even though they take opaque **kwargs) class ClientConstructor: + def __init__( self, dsn=None, # type: Optional[str] @@ -509,7 +510,7 @@ def __init__( transport=None, # type: Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]] transport_queue_size=DEFAULT_QUEUE_SIZE, # type: int sample_rate=1.0, # type: float - send_default_pii=False, # type: bool + send_default_pii=None, # type: Optional[bool] http_proxy=None, # type: Optional[str] https_proxy=None, # type: Optional[str] ignore_errors=[], # type: Sequence[Union[type, str]] # noqa: B006 @@ -580,4 +581,4 @@ def _get_default_options(): del _get_default_options -VERSION = "2.18.0" +VERSION = "2.19.0" diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index 32528246af..12336a939b 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -95,6 +95,7 @@ def iter_default_integrations(with_auto_enabling_integrations): "sentry_sdk.integrations.huey.HueyIntegration", "sentry_sdk.integrations.huggingface_hub.HuggingfaceHubIntegration", "sentry_sdk.integrations.langchain.LangchainIntegration", + "sentry_sdk.integrations.litestar.LitestarIntegration", "sentry_sdk.integrations.loguru.LoguruIntegration", "sentry_sdk.integrations.openai.OpenAIIntegration", "sentry_sdk.integrations.pymongo.PyMongoIntegration", diff --git a/sentry_sdk/integrations/django/caching.py b/sentry_sdk/integrations/django/caching.py index 4bd7cb7236..39d1679183 100644 --- a/sentry_sdk/integrations/django/caching.py +++ b/sentry_sdk/integrations/django/caching.py @@ -132,10 +132,22 @@ def _get_address_port(settings): return address, int(port) if port is not None else None -def patch_caching(): - # type: () -> None +def should_enable_cache_spans(): + # type: () -> bool from sentry_sdk.integrations.django import DjangoIntegration + client = sentry_sdk.get_client() + integration = client.get_integration(DjangoIntegration) + from django.conf import settings + + return integration is not None and ( + (client.spotlight is not None and settings.DEBUG is True) + or integration.cache_spans is True + ) + + +def patch_caching(): + # type: () -> None if not hasattr(CacheHandler, "_sentry_patched"): if DJANGO_VERSION < (3, 2): original_get_item = CacheHandler.__getitem__ @@ -145,8 +157,7 @@ def sentry_get_item(self, alias): # type: (CacheHandler, str) -> Any cache = original_get_item(self, alias) - integration = sentry_sdk.get_client().get_integration(DjangoIntegration) - if integration is not None and integration.cache_spans: + if should_enable_cache_spans(): from django.conf import settings address, port = _get_address_port( @@ -168,8 +179,7 @@ def sentry_create_connection(self, alias): # type: (CacheHandler, str) -> Any cache = original_create_connection(self, alias) - integration = sentry_sdk.get_client().get_integration(DjangoIntegration) - if integration is not None and integration.cache_spans: + if should_enable_cache_spans(): address, port = _get_address_port(self.settings[alias or "default"]) _patch_cache(cache, address, port) diff --git a/sentry_sdk/integrations/falcon.py b/sentry_sdk/integrations/falcon.py index 00ac106e15..ce771d16e7 100644 --- a/sentry_sdk/integrations/falcon.py +++ b/sentry_sdk/integrations/falcon.py @@ -43,6 +43,12 @@ FALCON3 = False +_FALCON_UNSET = None # type: Optional[object] +if FALCON3: # falcon.request._UNSET is only available in Falcon 3.0+ + with capture_internal_exceptions(): + from falcon.request import _UNSET as _FALCON_UNSET # type: ignore[import-not-found, no-redef] + + class FalconRequestExtractor(RequestExtractor): def env(self): # type: () -> Dict[str, Any] @@ -73,27 +79,23 @@ def raw_data(self): else: return None - if FALCON3: - - def json(self): - # type: () -> Optional[Dict[str, Any]] - try: - return self.request.media - except falcon.errors.HTTPBadRequest: - return None - - else: - - def json(self): - # type: () -> Optional[Dict[str, Any]] - try: - return self.request.media - except falcon.errors.HTTPBadRequest: - # NOTE(jmagnusson): We return `falcon.Request._media` here because - # falcon 1.4 doesn't do proper type checking in - # `falcon.Request.media`. This has been fixed in 2.0. - # Relevant code: https://github.com/falconry/falcon/blob/1.4.1/falcon/request.py#L953 - return self.request._media + def json(self): + # type: () -> Optional[Dict[str, Any]] + # fallback to cached_media = None if self.request._media is not available + cached_media = None + with capture_internal_exceptions(): + # self.request._media is the cached self.request.media + # value. It is only available if self.request.media + # has already been accessed. Therefore, reading + # self.request._media will not exhaust the raw request + # stream (self.request.bounded_stream) because it has + # already been read if self.request._media is set. + cached_media = self.request._media + + if cached_media is not _FALCON_UNSET: + return cached_media + + return None class SentryFalconMiddleware: diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 6f80b93f4d..2ddd44489f 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -2,7 +2,7 @@ from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.tracing import BAGGAGE_HEADER_NAME -from sentry_sdk.tracing_utils import should_propagate_trace +from sentry_sdk.tracing_utils import Baggage, should_propagate_trace from sentry_sdk.utils import ( SENSITIVE_DATA_SUBSTITUTE, capture_internal_exceptions, @@ -14,6 +14,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: + from collections.abc import MutableMapping from typing import Any @@ -76,11 +77,9 @@ def send(self, request, **kwargs): key=key, value=value, url=request.url ) ) - if key == BAGGAGE_HEADER_NAME and request.headers.get( - BAGGAGE_HEADER_NAME - ): - # do not overwrite any existing baggage, just append to it - request.headers[key] += "," + value + + if key == BAGGAGE_HEADER_NAME: + _add_sentry_baggage_to_headers(request.headers, value) else: request.headers[key] = value @@ -148,3 +147,21 @@ async def send(self, request, **kwargs): return rv AsyncClient.send = send + + +def _add_sentry_baggage_to_headers(headers, sentry_baggage): + # type: (MutableMapping[str, str], str) -> None + """Add the Sentry baggage to the headers. + + This function directly mutates the provided headers. The provided sentry_baggage + is appended to the existing baggage. If the baggage already contains Sentry items, + they are stripped out first. + """ + existing_baggage = headers.get(BAGGAGE_HEADER_NAME, "") + stripped_existing_baggage = Baggage.strip_sentry_baggage(existing_baggage) + + separator = "," if len(stripped_existing_baggage) > 0 else "" + + headers[BAGGAGE_HEADER_NAME] = ( + stripped_existing_baggage + separator + sentry_baggage + ) diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index e6ac36f3cb..61d335b170 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -137,7 +137,7 @@ def _new_chat_completion_common(f, *args, **kwargs): span = sentry_sdk.start_span( op=consts.OP.OPENAI_CHAT_COMPLETIONS_CREATE, - description="Chat Completion", + name="Chat Completion", origin=OpenAIIntegration.origin, ) span.__enter__() diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index c0df1c5e53..462f3ad30a 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -90,9 +90,13 @@ def sentry_patched_perform_job(self, job, *args, **kwargs): def sentry_patched_handle_exception(self, job, *exc_info, **kwargs): # type: (Worker, Any, *Any, **Any) -> Any - # Note, the order of the `or` here is important, - # because calling `job.is_failed` will change `_status`. - if job._status == JobStatus.FAILED or job.is_failed: + retry = ( + hasattr(job, "retries_left") + and job.retries_left + and job.retries_left > 0 + ) + failed = job._status == JobStatus.FAILED or job.is_failed + if failed and not retry: _capture_exception(exc_info) return old_handle_exception(self, job, *exc_info, **kwargs) diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 50deae10c5..751735f462 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -1,19 +1,19 @@ import sys from functools import partial +from threading import Timer import sentry_sdk from sentry_sdk._werkzeug import get_host, _get_headers from sentry_sdk.api import continue_trace from sentry_sdk.consts import OP -from sentry_sdk.scope import should_send_default_pii +from sentry_sdk.scope import should_send_default_pii, use_isolation_scope, use_scope from sentry_sdk.integrations._wsgi_common import ( DEFAULT_HTTP_METHODS_TO_CAPTURE, _filter_headers, - nullcontext, ) from sentry_sdk.sessions import track_session -from sentry_sdk.scope import use_isolation_scope from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE +from sentry_sdk.tracing_utils import finish_running_transaction from sentry_sdk.utils import ( ContextVar, capture_internal_exceptions, @@ -46,6 +46,9 @@ def __call__(self, status, response_headers, exc_info=None): # type: ignore pass +MAX_TRANSACTION_DURATION_SECONDS = 5 * 60 + + _wsgi_middleware_applied = ContextVar("sentry_wsgi_middleware_applied") @@ -98,6 +101,7 @@ def __call__(self, environ, start_response): _wsgi_middleware_applied.set(True) try: with sentry_sdk.isolation_scope() as scope: + current_scope = sentry_sdk.get_current_scope() with track_session(scope, session_mode="request"): with capture_internal_exceptions(): scope.clear_breadcrumbs() @@ -109,6 +113,7 @@ def __call__(self, environ, start_response): ) method = environ.get("REQUEST_METHOD", "").upper() + transaction = None if method in self.http_methods_to_capture: transaction = continue_trace( @@ -119,27 +124,43 @@ def __call__(self, environ, start_response): origin=self.span_origin, ) - with ( + timer = None + if transaction is not None: sentry_sdk.start_transaction( transaction, custom_sampling_context={"wsgi_environ": environ}, + ).__enter__() + timer = Timer( + MAX_TRANSACTION_DURATION_SECONDS, + _finish_long_running_transaction, + args=(current_scope, scope), ) - if transaction is not None - else nullcontext() - ): - try: - response = self.app( - environ, - partial( - _sentry_start_response, start_response, transaction - ), - ) - except BaseException: - reraise(*_capture_exception()) + timer.start() + + try: + response = self.app( + environ, + partial( + _sentry_start_response, + start_response, + transaction, + ), + ) + except BaseException: + exc_info = sys.exc_info() + _capture_exception(exc_info) + finish_running_transaction(current_scope, exc_info, timer) + reraise(*exc_info) + finally: _wsgi_middleware_applied.set(False) - return _ScopedResponse(scope, response) + return _ScopedResponse( + response=response, + current_scope=current_scope, + isolation_scope=scope, + timer=timer, + ) def _sentry_start_response( # type: ignore @@ -201,13 +222,13 @@ def get_client_ip(environ): return environ.get("REMOTE_ADDR") -def _capture_exception(): - # type: () -> ExcInfo +def _capture_exception(exc_info=None): + # type: (Optional[ExcInfo]) -> ExcInfo """ Captures the current exception and sends it to Sentry. Returns the ExcInfo tuple to it can be reraised afterwards. """ - exc_info = sys.exc_info() + exc_info = exc_info or sys.exc_info() e = exc_info[1] # SystemExit(0) is the only uncaught exception that is expected behavior @@ -225,7 +246,7 @@ def _capture_exception(): class _ScopedResponse: """ - Users a separate scope for each response chunk. + Use separate scopes for each response chunk. This will make WSGI apps more tolerant against: - WSGI servers streaming responses from a different thread/from @@ -234,37 +255,54 @@ class _ScopedResponse: - WSGI servers streaming responses interleaved from the same thread """ - __slots__ = ("_response", "_scope") + __slots__ = ("_response", "_current_scope", "_isolation_scope", "_timer") - def __init__(self, scope, response): - # type: (sentry_sdk.scope.Scope, Iterator[bytes]) -> None - self._scope = scope + def __init__( + self, + response, # type: Iterator[bytes] + current_scope, # type: sentry_sdk.scope.Scope + isolation_scope, # type: sentry_sdk.scope.Scope + timer=None, # type: Optional[Timer] + ): + # type: (...) -> None self._response = response + self._current_scope = current_scope + self._isolation_scope = isolation_scope + self._timer = timer def __iter__(self): # type: () -> Iterator[bytes] iterator = iter(self._response) - while True: - with use_isolation_scope(self._scope): - try: - chunk = next(iterator) - except StopIteration: - break - except BaseException: - reraise(*_capture_exception()) + try: + while True: + with use_isolation_scope(self._isolation_scope): + with use_scope(self._current_scope): + try: + chunk = next(iterator) + except StopIteration: + break + except BaseException: + reraise(*_capture_exception()) + + yield chunk - yield chunk + finally: + with use_isolation_scope(self._isolation_scope): + with use_scope(self._current_scope): + finish_running_transaction(timer=self._timer) def close(self): # type: () -> None - with use_isolation_scope(self._scope): - try: - self._response.close() # type: ignore - except AttributeError: - pass - except BaseException: - reraise(*_capture_exception()) + with use_isolation_scope(self._isolation_scope): + with use_scope(self._current_scope): + try: + finish_running_transaction(timer=self._timer) + self._response.close() # type: ignore + except AttributeError: + pass + except BaseException: + reraise(*_capture_exception()) def _make_wsgi_event_processor(environ, use_x_forwarded_for): @@ -308,3 +346,18 @@ def event_processor(event, hint): return event return event_processor + + +def _finish_long_running_transaction(current_scope, isolation_scope): + # type: (sentry_sdk.scope.Scope, sentry_sdk.scope.Scope) -> None + """ + Make sure we don't keep transactions open for too long. + Triggered after MAX_TRANSACTION_DURATION_SECONDS have passed. + """ + try: + with use_isolation_scope(isolation_scope): + with use_scope(current_scope): + finish_running_transaction() + except AttributeError: + # transaction is not there anymore + pass diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 150e73661e..969e0812e4 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -36,6 +36,9 @@ from types import FrameType + from sentry_sdk._types import ExcInfo + from threading import Timer + SENTRY_TRACE_REGEX = re.compile( "^[ \t]*" # whitespace @@ -609,6 +612,21 @@ def serialize(self, include_third_party=False): return ",".join(items) + @staticmethod + def strip_sentry_baggage(header): + # type: (str) -> str + """Remove Sentry baggage from the given header. + + Given a Baggage header, return a new Baggage header with all Sentry baggage items removed. + """ + return ",".join( + ( + item + for item in header.split(",") + if not Baggage.SENTRY_PREFIX_REGEX.match(item.strip()) + ) + ) + def should_propagate_trace(client, url): # type: (sentry_sdk.client.BaseClient, str) -> bool @@ -724,3 +742,18 @@ def get_current_span(scope=None): if TYPE_CHECKING: from sentry_sdk.tracing import Span + + +def finish_running_transaction(scope=None, exc_info=None, timer=None): + # type: (Optional[sentry_sdk.Scope], Optional[ExcInfo], Optional[Timer]) -> None + if timer is not None: + timer.cancel() + + current_scope = scope or sentry_sdk.get_current_scope() + if current_scope.transaction is not None and hasattr( + current_scope.transaction, "_context_manager_state" + ): + if exc_info is not None: + current_scope.transaction.__exit__(*exc_info) + else: + current_scope.transaction.__exit__(None, None, None) diff --git a/setup.py b/setup.py index 7ac4b56fde..fda3daa229 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def get_file_text(file_name): setup( name="sentry-sdk", - version="2.18.0", + version="2.19.0", author="Sentry Team and Contributors", author_email="hello@sentry.io", url="https://github.com/getsentry/sentry-python", @@ -70,7 +70,7 @@ def get_file_text(file_name): "openfeature": ["openfeature-sdk>=0.7.1"], "opentelemetry": ["opentelemetry-distro>=0.35b0"], "opentelemetry-experimental": ["opentelemetry-distro"], - "pure_eval": ["pure_eval", "executing", "asttokens"], + "pure-eval": ["pure_eval", "executing", "asttokens"], "pymongo": ["pymongo>=3.1"], "pyspark": ["pyspark>=2.4.4"], "quart": ["quart>=0.16.1", "blinker>=1.1"], diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index 0e3f700105..243431fdf5 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -51,7 +51,7 @@ def test_view_exceptions(sentry_init, client, capture_exceptions, capture_events sentry_init(integrations=[DjangoIntegration()], send_default_pii=True) exceptions = capture_exceptions() events = capture_events() - client.get(reverse("view_exc")) + unpack_werkzeug_response(client.get(reverse("view_exc"))) (error,) = exceptions assert isinstance(error, ZeroDivisionError) @@ -72,7 +72,9 @@ def test_ensures_x_forwarded_header_is_honored_in_sdk_when_enabled_in_django( sentry_init(integrations=[DjangoIntegration()], send_default_pii=True) exceptions = capture_exceptions() events = capture_events() - client.get(reverse("view_exc"), headers={"X_FORWARDED_HOST": "example.com"}) + unpack_werkzeug_response( + client.get(reverse("view_exc"), headers={"X_FORWARDED_HOST": "example.com"}) + ) (error,) = exceptions assert isinstance(error, ZeroDivisionError) @@ -91,7 +93,9 @@ def test_ensures_x_forwarded_header_is_not_honored_when_unenabled_in_django( sentry_init(integrations=[DjangoIntegration()], send_default_pii=True) exceptions = capture_exceptions() events = capture_events() - client.get(reverse("view_exc"), headers={"X_FORWARDED_HOST": "example.com"}) + unpack_werkzeug_response( + client.get(reverse("view_exc"), headers={"X_FORWARDED_HOST": "example.com"}) + ) (error,) = exceptions assert isinstance(error, ZeroDivisionError) @@ -103,7 +107,7 @@ def test_ensures_x_forwarded_header_is_not_honored_when_unenabled_in_django( def test_middleware_exceptions(sentry_init, client, capture_exceptions): sentry_init(integrations=[DjangoIntegration()], send_default_pii=True) exceptions = capture_exceptions() - client.get(reverse("middleware_exc")) + unpack_werkzeug_response(client.get(reverse("middleware_exc"))) (error,) = exceptions assert isinstance(error, ZeroDivisionError) @@ -157,7 +161,7 @@ def test_has_trace_if_performance_enabled(sentry_init, client, capture_events): traces_sample_rate=1.0, ) events = capture_events() - client.head(reverse("view_exc_with_msg")) + unpack_werkzeug_response(client.head(reverse("view_exc_with_msg"))) (msg_event, error_event, transaction_event) = events @@ -213,8 +217,10 @@ def test_trace_from_headers_if_performance_enabled(sentry_init, client, capture_ trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - client.head( - reverse("view_exc_with_msg"), headers={"sentry-trace": sentry_trace_header} + unpack_werkzeug_response( + client.head( + reverse("view_exc_with_msg"), headers={"sentry-trace": sentry_trace_header} + ) ) (msg_event, error_event, transaction_event) = events @@ -928,7 +934,7 @@ def test_render_spans(sentry_init, client, capture_events, render_span_tree): for url, expected_line in views_tests: events = capture_events() - client.get(url) + unpack_werkzeug_response(client.get(url)) transaction = events[0] assert expected_line in render_span_tree(transaction) @@ -967,7 +973,7 @@ def test_middleware_spans(sentry_init, client, capture_events, render_span_tree) ) events = capture_events() - client.get(reverse("message")) + unpack_werkzeug_response(client.get(reverse("message"))) message, transaction = events @@ -984,7 +990,7 @@ def test_middleware_spans_disabled(sentry_init, client, capture_events): ) events = capture_events() - client.get(reverse("message")) + unpack_werkzeug_response(client.get(reverse("message"))) message, transaction = events @@ -1008,7 +1014,7 @@ def test_signals_spans(sentry_init, client, capture_events, render_span_tree): ) events = capture_events() - client.get(reverse("message")) + unpack_werkzeug_response(client.get(reverse("message"))) message, transaction = events @@ -1031,7 +1037,7 @@ def test_signals_spans_disabled(sentry_init, client, capture_events): ) events = capture_events() - client.get(reverse("message")) + unpack_werkzeug_response(client.get(reverse("message"))) message, transaction = events @@ -1061,7 +1067,7 @@ def test_signals_spans_filtering(sentry_init, client, capture_events, render_spa ) events = capture_events() - client.get(reverse("send_myapp_custom_signal")) + unpack_werkzeug_response(client.get(reverse("send_myapp_custom_signal"))) (transaction,) = events @@ -1186,7 +1192,7 @@ def test_span_origin(sentry_init, client, capture_events): ) events = capture_events() - client.get(reverse("view_with_signal")) + unpack_werkzeug_response(client.get(reverse("view_with_signal"))) (transaction,) = events @@ -1211,9 +1217,9 @@ def test_transaction_http_method_default(sentry_init, client, capture_events): ) events = capture_events() - client.get("/nomessage") - client.options("/nomessage") - client.head("/nomessage") + unpack_werkzeug_response(client.get("/nomessage")) + unpack_werkzeug_response(client.options("/nomessage")) + unpack_werkzeug_response(client.head("/nomessage")) (event,) = events @@ -1235,9 +1241,9 @@ def test_transaction_http_method_custom(sentry_init, client, capture_events): ) events = capture_events() - client.get("/nomessage") - client.options("/nomessage") - client.head("/nomessage") + unpack_werkzeug_response(client.get("/nomessage")) + unpack_werkzeug_response(client.options("/nomessage")) + unpack_werkzeug_response(client.head("/nomessage")) assert len(events) == 2 diff --git a/tests/integrations/falcon/test_falcon.py b/tests/integrations/falcon/test_falcon.py index 0607d3fdeb..51a1d94334 100644 --- a/tests/integrations/falcon/test_falcon.py +++ b/tests/integrations/falcon/test_falcon.py @@ -460,3 +460,48 @@ def test_span_origin(sentry_init, capture_events, make_client): (_, event) = events assert event["contexts"]["trace"]["origin"] == "auto.http.falcon" + + +def test_falcon_request_media(sentry_init): + # test_passed stores whether the test has passed. + test_passed = False + + # test_failure_reason stores the reason why the test failed + # if test_passed is False. The value is meaningless when + # test_passed is True. + test_failure_reason = "test endpoint did not get called" + + class SentryCaptureMiddleware: + def process_request(self, _req, _resp): + # This capture message forces Falcon event processors to run + # before the request handler runs + sentry_sdk.capture_message("Processing request") + + class RequestMediaResource: + def on_post(self, req, _): + nonlocal test_passed, test_failure_reason + raw_data = req.bounded_stream.read() + + # If the raw_data is empty, the request body stream + # has been exhausted by the SDK. Test should fail in + # this case. + test_passed = raw_data != b"" + test_failure_reason = "request body has been read" + + sentry_init(integrations=[FalconIntegration()]) + + try: + app_class = falcon.App # Falcon ≥3.0 + except AttributeError: + app_class = falcon.API # Falcon <3.0 + + app = app_class(middleware=[SentryCaptureMiddleware()]) + app.add_route("/read_body", RequestMediaResource()) + + client = falcon.testing.TestClient(app) + + client.simulate_post("/read_body", json={"foo": "bar"}) + + # Check that simulate_post actually calls the resource, and + # that the SDK does not exhaust the request body stream. + assert test_passed, test_failure_reason diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 6febb12b8b..e2c37aa5f7 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -394,6 +394,8 @@ def index(): client = app.test_client() response = client.post("/", data=data) assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() event, transaction_event = events @@ -746,6 +748,8 @@ def hi_tx(): with app.test_client() as client: response = client.get("/message_tx") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() message_event, transaction_event = events @@ -938,7 +942,9 @@ def test_response_status_code_not_found_in_transaction_context( envelopes = capture_envelopes() client = app.test_client() - client.get("/not-existing-route") + response = client.get("/not-existing-route") + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() sentry_sdk.get_client().flush() @@ -983,14 +989,21 @@ def test_transaction_http_method_default( events = capture_events() client = app.test_client() + response = client.get("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() response = client.options("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() response = client.head("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() (event,) = events @@ -1020,14 +1033,21 @@ def test_transaction_http_method_custom( events = capture_events() client = app.test_client() + response = client.get("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() response = client.options("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() response = client.head("/nomessage") assert response.status_code == 200 + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + response.close() assert len(events) == 2 diff --git a/tests/integrations/gcp/__init__.py b/tests/integrations/gcp/__init__.py new file mode 100644 index 0000000000..eaf1ba89bb --- /dev/null +++ b/tests/integrations/gcp/__init__.py @@ -0,0 +1,6 @@ +import pytest +import os + + +if "gcp" not in os.environ.get("TOX_ENV_NAME", ""): + pytest.skip("GCP tests only run in GCP environment", allow_module_level=True) diff --git a/tests/integrations/rq/test_rq.py b/tests/integrations/rq/test_rq.py index ffd6f458e1..e445b588be 100644 --- a/tests/integrations/rq/test_rq.py +++ b/tests/integrations/rq/test_rq.py @@ -254,11 +254,6 @@ def test_traces_sampler_gets_correct_values_in_sampling_context( @pytest.mark.skipif( parse_version(rq.__version__) < (1, 5), reason="At least rq-1.5 required" ) -@pytest.mark.skipif( - parse_version(rq.__version__) >= (2,), - reason="Test broke in RQ 2.0. Investigate and fix. " - "See https://github.com/getsentry/sentry-python/issues/3707.", -) def test_job_with_retries(sentry_init, capture_events): sentry_init(integrations=[RqIntegration()]) events = capture_events() diff --git a/tests/integrations/strawberry/test_strawberry.py b/tests/integrations/strawberry/test_strawberry.py index 7b40b238d2..0aab78f443 100644 --- a/tests/integrations/strawberry/test_strawberry.py +++ b/tests/integrations/strawberry/test_strawberry.py @@ -198,7 +198,10 @@ def test_capture_request_if_available_and_send_pii_is_on( client = client_factory(schema) query = "query ErrorQuery { error }" - client.post("/graphql", json={"query": query, "operationName": "ErrorQuery"}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post( + "/graphql", json={"query": query, "operationName": "ErrorQuery"} + ).close() assert len(events) == 1 @@ -253,7 +256,10 @@ def test_do_not_capture_request_if_send_pii_is_off( client = client_factory(schema) query = "query ErrorQuery { error }" - client.post("/graphql", json={"query": query, "operationName": "ErrorQuery"}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post( + "/graphql", json={"query": query, "operationName": "ErrorQuery"} + ).close() assert len(events) == 1 @@ -293,7 +299,8 @@ def test_breadcrumb_no_operation_name( client = client_factory(schema) query = "{ error }" - client.post("/graphql", json={"query": query}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={"query": query}).close() assert len(events) == 1 @@ -332,7 +339,10 @@ def test_capture_transaction_on_error( client = client_factory(schema) query = "query ErrorQuery { error }" - client.post("/graphql", json={"query": query, "operationName": "ErrorQuery"}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post( + "/graphql", json={"query": query, "operationName": "ErrorQuery"} + ).close() assert len(events) == 2 (_, transaction_event) = events @@ -409,7 +419,10 @@ def test_capture_transaction_on_success( client = client_factory(schema) query = "query GreetingQuery { hello }" - client.post("/graphql", json={"query": query, "operationName": "GreetingQuery"}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post( + "/graphql", json={"query": query, "operationName": "GreetingQuery"} + ).close() assert len(events) == 1 (transaction_event,) = events @@ -486,7 +499,8 @@ def test_transaction_no_operation_name( client = client_factory(schema) query = "{ hello }" - client.post("/graphql", json={"query": query}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={"query": query}).close() assert len(events) == 1 (transaction_event,) = events @@ -566,7 +580,8 @@ def test_transaction_mutation( client = client_factory(schema) query = 'mutation Change { change(attribute: "something") }' - client.post("/graphql", json={"query": query}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={"query": query}).close() assert len(events) == 1 (transaction_event,) = events @@ -641,7 +656,8 @@ def test_handle_none_query_gracefully( client_factory = request.getfixturevalue(client_factory) client = client_factory(schema) - client.post("/graphql", json={}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={}).close() assert len(events) == 0, "expected no events to be sent to Sentry" @@ -673,7 +689,8 @@ def test_span_origin( client = client_factory(schema) query = 'mutation Change { change(attribute: "something") }' - client.post("/graphql", json={"query": query}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={"query": query}).close() (event,) = events @@ -715,7 +732,10 @@ def test_span_origin2( client = client_factory(schema) query = "query GreetingQuery { hello }" - client.post("/graphql", json={"query": query, "operationName": "GreetingQuery"}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post( + "/graphql", json={"query": query, "operationName": "GreetingQuery"} + ).close() (event,) = events @@ -757,7 +777,8 @@ def test_span_origin3( client = client_factory(schema) query = "subscription { messageAdded { content } }" - client.post("/graphql", json={"query": query}) + # Close the response to ensure the WSGI cycle is complete and the transaction is finished + client.post("/graphql", json={"query": query}).close() (event,) = events diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 656fc1757f..a4f5ca0623 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -1,7 +1,9 @@ +import time from collections import Counter from unittest import mock import pytest +from sentry_sdk.utils import datetime_from_isoformat from werkzeug.test import Client import sentry_sdk @@ -495,3 +497,80 @@ def dogpark(environ, start_response): (event,) = events assert event["contexts"]["trace"]["origin"] == "auto.dogpark.deluxe" + + +def test_long_running_transaction_finished(sentry_init, capture_events): + # we allow transactions to be 0.5 seconds as a maximum + new_max_duration = 0.5 + + with mock.patch.object( + sentry_sdk.integrations.wsgi, + "MAX_TRANSACTION_DURATION_SECONDS", + new_max_duration, + ): + + def generate_content(): + # This response will take 1.5 seconds to generate + for _ in range(15): + time.sleep(0.1) + yield "ok" + + def long_running_app(environ, start_response): + start_response("200 OK", []) + return generate_content() + + sentry_init(send_default_pii=True, traces_sample_rate=1.0) + app = SentryWsgiMiddleware(long_running_app) + + events = capture_events() + + client = Client(app) + response = client.get("/") + _ = response.get_data() + + (transaction,) = events + + transaction_duration = ( + datetime_from_isoformat(transaction["timestamp"]) + - datetime_from_isoformat(transaction["start_timestamp"]) + ).total_seconds() + assert ( + transaction_duration <= new_max_duration * 1.02 + ) # we allow 2% margin for processing the request + + +def test_long_running_transaction_timer_canceled(sentry_init, capture_events): + # we allow transactions to be 0.5 seconds as a maximum + new_max_duration = 0.5 + + with mock.patch.object( + sentry_sdk.integrations.wsgi, + "MAX_TRANSACTION_DURATION_SECONDS", + new_max_duration, + ): + with mock.patch( + "sentry_sdk.integrations.wsgi._finish_long_running_transaction" + ) as mock_finish: + + def generate_content(): + # This response will take 0.3 seconds to generate + for _ in range(3): + time.sleep(0.1) + yield "ok" + + def long_running_app(environ, start_response): + start_response("200 OK", []) + return generate_content() + + sentry_init(send_default_pii=True, traces_sample_rate=1.0) + app = SentryWsgiMiddleware(long_running_app) + + events = capture_events() + + client = Client(app) + response = client.get("/") + _ = response.get_data() + + (transaction,) = events + + mock_finish.assert_not_called() diff --git a/tests/test_scope.py b/tests/test_scope.py index 0dfa155d11..374a354446 100644 --- a/tests/test_scope.py +++ b/tests/test_scope.py @@ -811,6 +811,24 @@ def test_should_send_default_pii_false(sentry_init): assert should_send_default_pii() is False +def test_should_send_default_pii_default_false(sentry_init): + sentry_init() + + assert should_send_default_pii() is False + + +def test_should_send_default_pii_false_with_dsn_and_spotlight(sentry_init): + sentry_init(dsn="http://key@localhost/1", spotlight=True) + + assert should_send_default_pii() is False + + +def test_should_send_default_pii_true_without_dsn_and_spotlight(sentry_init): + sentry_init(spotlight=True) + + assert should_send_default_pii() is True + + def test_set_tags(): scope = Scope() scope.set_tags({"tag1": "value1", "tag2": "value2"}) diff --git a/tests/test_tracing_utils.py b/tests/test_tracing_utils.py index 239e631156..5c1f70516d 100644 --- a/tests/test_tracing_utils.py +++ b/tests/test_tracing_utils.py @@ -1,7 +1,7 @@ from dataclasses import asdict, dataclass from typing import Optional, List -from sentry_sdk.tracing_utils import _should_be_included +from sentry_sdk.tracing_utils import _should_be_included, Baggage import pytest @@ -94,3 +94,24 @@ def test_should_be_included(test_case, expected): kwargs = asdict(test_case) kwargs.pop("id") assert _should_be_included(**kwargs) == expected + + +@pytest.mark.parametrize( + ("header", "expected"), + ( + ("", ""), + ("foo=bar", "foo=bar"), + (" foo=bar, baz = qux ", " foo=bar, baz = qux "), + ("sentry-trace_id=123", ""), + (" sentry-trace_id = 123 ", ""), + ("sentry-trace_id=123,sentry-public_key=456", ""), + ("foo=bar,sentry-trace_id=123", "foo=bar"), + ("foo=bar,sentry-trace_id=123,baz=qux", "foo=bar,baz=qux"), + ( + "foo=bar,sentry-trace_id=123,baz=qux,sentry-public_key=456", + "foo=bar,baz=qux", + ), + ), +) +def test_strip_sentry_baggage(header, expected): + assert Baggage.strip_sentry_baggage(header) == expected diff --git a/tox.ini b/tox.ini index f3a7ba4ea0..6acff6b8e8 100644 --- a/tox.ini +++ b/tox.ini @@ -647,6 +647,8 @@ deps = spark-v3.1: pyspark~=3.1.0 spark-v3.3: pyspark~=3.3.0 spark-v3.5: pyspark~=3.5.0 + # TODO: update to ~=4.0.0 once stable is out + spark-v4.0: pyspark==4.0.0.dev2 spark-latest: pyspark # Starlette