Skip to content

Conversation

@sentrivana
Copy link
Contributor

No description provided.

antonpirker and others added 30 commits March 4, 2025 09:10
Handle `None` values in arq configuration gracefully. 
Fixes #3827
Run `generate-test-files.sh` (this will be automated at some point)
)

The URL that works in EC2 does not work in ECS, this can lead to the HTTP request getting stuck.

Fixes #2376
Test Sentry AWS Lambda integration locally instead of creating actual
Lambda function in AWS:

- Create a local AWS Lambda environment using AWS SAM and AWS CDK.
(Docker based)
- Start a local Sentry server that accepts envelopes.
- Run the tests in the local AWS Lambda environment configured with a
DSN that tells the SDK to send data to the local Sentry server.
- Read the captured envelopes from the local Sentry server to assert
their correctness.
- Update CI configuration, so AWS tests are now handled the same as test
suite matrices of other integrations.

There is also a follow-up PR that removes obsolete code handling AWS
authentication data: #4076 (This PR will also fix the one failing test)

Fixes #2795
Instrumenting asyncio projects can be confusing. Here are two
improvements:

- If users try to init the Sentry SDK outside of an async loop, a
warning message will now printed instructing them how to correctly call
init() in async envrionments. Including a link to the docs.

- During shutdown of Python unfinished async tasks emit an error `Task
was destroyed but it is pending!`. This happens if you use Sentry or
not. The error message is confusing and led people to believe the Sentry
instrumentation caused this problem. This is now remediated by
- The tasks is wrapped by Sentry, but we now **set the name of the
wrapped task to include the original** and (and a hint that is has been
wrapped by Sentry) to show that the original task is failing, not just
some Sentry task unknown to the user.
- When shutting down a **info message** is printed, informing that there
could be `Task was destroyed but it is pending!` but that those are OK
and not a problem with the users code or Sentry.


Before this PR the users saw this during shutdown:

```
Exception ignored in: <coroutine object patch_asyncio.<locals>._sentry_task_factory.<locals>._coro_creating_hub_and_span at 0x103ae84f0>
Traceback (most recent call last):
  File "/Users/antonpirker/code/sentry-python/sentry_sdk/integrations/asyncio.py", line 46, in _coro_creating_hub_and_span
    with sentry_sdk.isolation_scope():
  File "/Users/antonpirker/.pyenv/versions/3.12.3/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/Users/antonpirker/code/sentry-python/sentry_sdk/scope.py", line 1732, in isolation_scope
    _current_scope.reset(current_token)
ValueError: <Token var=<ContextVar name='current_scope' default=None at 0x102a87f60> at 0x103b1cfc0> was created in a different Context
Task was destroyed but it is pending!
task: <Task cancelling name='Task-2' coro=<patch_asyncio.<locals>._sentry_task_factory.<locals>._coro_creating_hub_and_span() done, defined at /Users/antonpirker/code/sentry-python/sentry_sdk/integrations/asyncio.py:42> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[gather.<locals>._done_callback() at /Users/antonpirker/.pyenv/versions/3.12.3/lib/python3.12/asyncio/tasks.py:767]>
```

With this PR the users will see this during shutdown:
Note the INFO message on top and also the task name on the bottom.
```
[sentry] INFO: AsyncIO is shutting down. If you see 'Task was destroyed but it is pending!' errors with '_task_with_sentry_span_creation', these are normal during shutdown and not a problem with your code or Sentry.
Exception ignored in: <coroutine object patch_asyncio.<locals>._sentry_task_factory.<locals>._task_with_sentry_span_creation at 0x1028fc4f0>
Traceback (most recent call last):
  File "/Users/antonpirker/code/sentry-python/sentry_sdk/integrations/asyncio.py", line 62, in _task_with_sentry_span_creation
    with sentry_sdk.isolation_scope():
  File "/Users/antonpirker/.pyenv/versions/3.12.3/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/Users/antonpirker/code/sentry-python/sentry_sdk/scope.py", line 1732, in isolation_scope
    _current_scope.reset(current_token)
ValueError: <Token var=<ContextVar name='current_scope' default=None at 0x10193ff10> at 0x1029710c0> was created in a different Context
Task was destroyed but it is pending!
task: <Task cancelling name='long_running_task (Sentry-wrapped)' coro=<patch_asyncio.<locals>._sentry_task_factory.<locals>._task_with_sentry_span_creation() done, defined at /Users/antonpirker/code/sentry-python/sentry_sdk/integrations/asyncio.py:58> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[gather.<locals>._done_callback() at /Users/antonpirker/.pyenv/versions/3.12.3/lib/python3.12/asyncio/tasks.py:767]>
```

Fixes #2908

Improves #2333
This gives us a way to locally run and test our AWS Lambda integration,
without needing a real AWS Lambda account.

This should make development of AWS Lambda support better.

---------

Co-authored-by: Ivana Kellyer <[email protected]>
Nice rendering of log messages containing parameters that are `None`
values does not work. There we coerce `None` values into strings to have
nicer messages in Sentry UI.

Fixes #3660
`request.route` can throw a `RuntimeError: This request is not connected
to a route.`.

Closes #3583
See
#2709 (comment)

If `quart_flask_patch` is imported, it monkeypatches stuff so that the
Quart app appears to be a Flask app. This confuses our Flask
integration, which tries to enable itself and fails.

This commit:

- Makes the Flask integration detect that what it sees as Flask might
actually be Quart.
- Reorganizes the Quart test suite a little to allow to test this case
(a bit tricky since `import quart_flask_patch` needs to happen before
anything else due to its monkeypatching nature).

Closes #2709
We only check `logger.handlers` for existing handlers. This ignores any
potential parent handlers. By using `hasHandlers()`
([docs](https://docs.python.org/3/library/logging.html#logging.Logger.hasHandlers))
instead we take those into account as well.

Closes #3944
Dusting off our Readme a bit. It has been quite some time since it was
last updated.
Logs are coming to sentry!

This commit:
- Adds `sentry_sdk._experimental_logger.{info, warn, ...}` methods
- Adds `_experimental` options for `before_send_log` and `enable_sentry_logs`

There are no tests (yet), and this still uses the otel_log schema.

Example usage:
```python
sentry_sdk.init(
    dsn=...,
    _experiments={"enable_sentry_logs": True},
)

from sentry_sdk import _experimental_logger as sentry_logger
sentry_logger.info('Finished sending answer! #chunks={num_chunks}', num_chunks=10)
```
---------

Co-authored-by: Anton Pirker <[email protected]>
Copied the text from docs.sentry.io and added it to the ApiDocs. (some
parameters are undocumented, it seems)
The `Baggage` class does not enforce mutability. Document this to avoid
confusion.

<!-- Describe your PR here -->

---

Thank you for contributing to `sentry-python`! Please add tests to
validate your changes, and lint your code using `tox -e linters`.

Running the test suite on your PR might require maintainer approval. The
AWS Lambda tests additionally require a maintainer to add a special
label, and they will fail until this label is added.

Co-authored-by: Anton Pirker <[email protected]>
….6 (#4113)

Bumps
[actions/create-github-app-token](https://github.com/actions/create-github-app-token)
from 1.11.5 to 1.11.6.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/create-github-app-token/releases">actions/create-github-app-token's
releases</a>.</em></p>
<blockquote>
<h2>v1.11.6</h2>
<h2><a
href="https://github.com/actions/create-github-app-token/compare/v1.11.5...v1.11.6">1.11.6</a>
(2025-03-03)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><strong>deps:</strong> bump the production-dependencies group with 2
updates (<a
href="https://redirect.github.com/actions/create-github-app-token/issues/210">#210</a>)
(<a
href="https://github.com/actions/create-github-app-token/commit/1ff1dea6a9d1de5b4795e5314291e04acc63c38b">1ff1dea</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/actions/create-github-app-token/commit/21cfef2b496dd8ef5b904c159339626a10ad380e"><code>21cfef2</code></a>
build(release): 1.11.6 [skip ci]</li>
<li><a
href="https://github.com/actions/create-github-app-token/commit/1ff1dea6a9d1de5b4795e5314291e04acc63c38b"><code>1ff1dea</code></a>
fix(deps): bump the production-dependencies group with 2 updates (<a
href="https://redirect.github.com/actions/create-github-app-token/issues/210">#210</a>)</li>
<li>See full diff in <a
href="https://github.com/actions/create-github-app-token/compare/0d564482f06ca65fa9e77e2510873638c82206f2...21cfef2b496dd8ef5b904c159339626a10ad380e">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/create-github-app-token&package-manager=github_actions&previous-version=1.11.5&new-version=1.11.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Anton Pirker <[email protected]>
In Starlette/FastAPI you're able to create subapps. When using
`transaction_style="url"` in our integration, this would throw an
exception because we try to access `route.path` to determine the
transaction name, but `Host` routes have no `path` attribute.

Closes #2631
Regular `tox.ini` update
Loguru has two message levels `TRACE` and `SUCCESS` that are not
available in Sentry breadcrumbs. This PR maps `TRACE` to `debug` and
`SUCCESS` to `info` in Sentry so those breadcrumbs do not show a
confusing error message in the Sentry UI.

Fixes #2759
sentrivana and others added 3 commits March 19, 2025 12:12
…event (#4142)

Imagine an app throws an exception twice, from different places. The
first exception is dropped in the user's `before_send`. The second
exception is not. Should the second exception appear in Sentry?

The current state is that it won't, since `DedupeIntegration` will take
the first, dropped exception into account. When encountering the second
exception, it'll consider it a duplicate and will drop it, even though
the first exception never made it to Sentry.

In this PR, we reset `DedupeIntegration`'s `last-seen` if an event has
been dropped by `before_send`, ensuring that the next exception will be
reported.

Closes #371

---------

Co-authored-by: Anton Pirker <[email protected]>
…on (#4162)

Revert back to using `start_profiler` and `stop_profiler` function names
and deprecate the `*_session` ones instead.

Prior PR that introduced the change we're undoing:
#4056
@codecov
Copy link

codecov bot commented Mar 20, 2025

❌ 903 Tests Failed:

Tests completed Failed Passed Skipped
21991 903 21088 4579
View the top 3 failed test(s) by shortest run time
 tests.integrations.celery.integration_tests.test_celery_beat_cron_monitoring
Stack Traces | 0s run time
.../hostedtoolcache/Python/3.7.17.../x64/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:953: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:728: in exec_module
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
.../celery/integration_tests/__init__.py:7: in <module>
    from celery.beat import Scheduler
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/celery/beat.py:22: in <module>
    from . import __version__, platforms, signals
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/celery/signals.py:14: in <module>
    from .utils.dispatch import Signal
.tox/py3.7-celery-v5.0.5/lib/python3.7.../celery/utils/__init__.py:16: in <module>
    from .nodenames import nodename, nodesplit, worker_direct
.tox/py3.7-celery-v5.0.5/lib/python3.7.../celery/utils/nodenames.py:6: in <module>
    from kombu.entity import Exchange, Queue
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/kombu/entity.py:7: in <module>
    from .serialization import prepare_accept_content
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/kombu/serialization.py:440: in <module>
    for ep, args in entrypoints('kombu.serializers'):  # pragma: no cover
.tox/py3.7-celery-v5.0.5/lib/python3.7.../kombu/utils/compat.py:82: in entrypoints
    for ep in importlib_metadata.entry_points().get(namespace, [])
E   AttributeError: 'EntryPoints' object has no attribute 'get'
 tests.integrations.celery.test_celery
Stack Traces | 0s run time
ImportError while importing test module '.../integrations/celery/test_celery.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
.../hostedtoolcache/Python/3.7.17.../x64/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
.tox/py3.7-celery-v5.0.5/lib/python3.7.../_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
.../integrations/celery/test_celery.py:6: in <module>
    from celery import Celery, VERSION
E   ImportError: cannot import name 'Celery' from 'celery' (.../sentry-python/sentry-python/.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/celery/__init__.py)
 tests.integrations.celery.test_update_celery_task_headers
Stack Traces | 0s run time
.../integrations/celery/beat.py:28: in <module>
    from celery import Task, Celery  # type: ignore
E   ImportError: cannot import name 'Task' from 'celery' (.../sentry-python/sentry-python/.tox/py3.7-celery-v5.0.5/lib/python3.7.../site-packages/celery/__init__.py)

During handling of the above exception, another exception occurred:
.../integrations/celery/test_update_celery_task_headers.py:7: in <module>
    from sentry_sdk.integrations.celery import _update_celery_task_headers
.../integrations/celery/__init__.py:9: in <module>
    from sentry_sdk.integrations.celery.beat import (
.../integrations/celery/beat.py:37: in <module>
    raise DidNotEnable("Celery not installed")
E   sentry_sdk.integrations.DidNotEnable: Celery not installed

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@sentrivana sentrivana merged commit afe6491 into potel-base Mar 20, 2025
85 of 130 checks passed
@sentrivana sentrivana deleted the ivana/potel/sync2 branch March 20, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants