Skip to content
35 changes: 35 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- The UnraisableHookIntegration is now enabled by default.
- We now don't suppress chained exceptions in the ASGI and asyncio integrations by default. The related `suppress_asgi_chained_exceptions` experimental option was removed.

### Logging

- The standard library logging integration is not auto-enabled by default anymore. To continue using it, add it to the `integrations` list in your `sentry_sdk.init()`:

```python
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
integrations=[
LoggingIntegration(),
]
)
```

- The `level` integration option is now called `breadcrumb_level`.
- The `sentry_logs_level` integration option is now called `level`.
- The `capture_sentry_logs` option was removed. Use `level=None` to disable log capture.
- The `ignore_logger` helper was renamed to `ignore_logger_for_breadcrumbs_and_events`.
- The `ignore_logger_for_sentry_logs` helper was renamed to `ignore_logger`.
- `SentryHandler` was removed. Use `EventHandler` instead.
- When you enable the integration by adding `LoggingIntegration` to your `sentry_sdk.init()`, it'll start capturing Sentry logs and breadcrumbs. Creating events from logs can be enabled by providing additional integration options.

| Old name | New name | Old default | New default | Description |
| --- | --- | --- | --- | --- |
| `level` | `breadcrumb_level` | `INFO` | `INFO` | Captures logs of that level and higher as breadcrumbs. |
| `event_level` | `event_level` | `ERROR` | `None` | Captures logs of that level and higher as events. |
| `sentry_logs_level` | `level` | `INFO` | `INFO` | Captures logs of that level and higher as Sentry logs. |
| `capture_sentry_logs` | removed | `False` | n/a | Allows to opt out of instrumenting logs as Sentry logs. Use `level` (previously `sentry_logs_level`) to adjust what should be captured instead. |
| `ignore_logger` | `ignore_logger_for_events` | n/a | n/a | Loggers that match this name will not create breadcrumbs and events. |
| `unignore_logger` | `unignore_logger_for_events` | n/a | n/a | Loggers that match this name will create breadcrumbs and events again. |
| `ignore_logger_for_sentry_logs` | `ignore_logger` | n/a | n/a | Loggers that match this name will not create Sentry logs. |
| `unignore_logger_for_sentry_logs` | `unignore_logger` | n/a | n/a | Loggers that match this name will create Sentry logs again. |


## Removed

- The SDK no longer supports Python 3.6. The oldest supported version is now 3.7.
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def iter_default_integrations(
"sentry_sdk.integrations.atexit.AtexitIntegration",
"sentry_sdk.integrations.dedupe.DedupeIntegration",
"sentry_sdk.integrations.excepthook.ExcepthookIntegration",
"sentry_sdk.integrations.logging.LoggingIntegration",
"sentry_sdk.integrations.modules.ModulesIntegration",
"sentry_sdk.integrations.stdlib.StdlibIntegration",
"sentry_sdk.integrations.threading.ThreadingIntegration",
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
_filter_headers,
request_body_within_bounds,
)
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import (
Expand Down Expand Up @@ -113,7 +113,7 @@ def setup_once() -> None:
# accidentally overwrite a status of "ok" with "error".
_register_control_flow_exception(HTTPException)

ignore_logger("aiohttp.server")
ignore_logger_for_events("aiohttp.server")

old_handle = Application._handle

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/ariadne.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sentry_sdk import capture_event, get_client
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.utils import (
capture_internal_exceptions,
Expand Down Expand Up @@ -45,7 +45,7 @@ def setup_once() -> None:
version = package_version("ariadne")
_check_minimum_version(AriadneIntegration, version)

ignore_logger("ariadne")
ignore_logger_for_events("ariadne")

_patch_graphql()

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SegmentNameSource
from sentry_sdk.tracing_utils import has_span_streaming_enabled
Expand Down Expand Up @@ -64,7 +64,7 @@ def setup_once() -> None:

_register_control_flow_exception(ARQ_CONTROL_FLOW_EXCEPTIONS) # type: ignore

ignore_logger("arq.worker")
ignore_logger_for_events("arq.worker")


def patch_enqueue_job() -> None:
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sentry_sdk
from sentry_sdk.integrations import Integration, _check_minimum_version
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -39,8 +39,8 @@ def setup_once() -> None:
version = parse_version(BEAM_VERSION)
_check_minimum_version(BeamIntegration, version)

ignore_logger("root")
ignore_logger("bundle_processor.create")
ignore_logger_for_events("root")
ignore_logger_for_events("bundle_processor.create")

function_patches = ["process", "start_bundle", "finish_bundle", "setup"]
for func_name in function_patches:
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
_setup_celery_beat_signals,
)
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.traces import SegmentNameSource, StreamedSpan, get_current_span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
Expand Down Expand Up @@ -84,12 +84,12 @@ def setup_once() -> None:
# This logger logs every status of every task that ran on the worker.
# Meaning that every task's breadcrumbs are full of stuff like "Task
# <foo> raised unexpected <bar>".
ignore_logger("celery.worker.job")
ignore_logger("celery.app.trace")
ignore_logger_for_events("celery.worker.job")
ignore_logger_for_events("celery.app.trace")

# This is stdout/err redirected to a logger, can't deal with this
# (need event_level=logging.WARN to reproduce)
ignore_logger("celery.redirected")
ignore_logger_for_events("celery.redirected")


def _set_status(status: str) -> None:
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
DEFAULT_HTTP_METHODS_TO_CAPTURE,
RequestExtractor,
)
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import add_global_event_processor, should_send_default_pii
from sentry_sdk.serializer import add_global_repr_processor, add_repr_sequence_type
Expand Down Expand Up @@ -156,8 +156,8 @@ def setup_once() -> None:
# Patch in our custom middleware.

# logs an error for every 500
ignore_logger("django.server")
ignore_logger("django.request")
ignore_logger_for_events("django.server")
ignore_logger_for_events("django.request")

from django.core.handlers.wsgi import WSGIHandler

Expand Down Expand Up @@ -889,7 +889,7 @@ def _rollback(self: "BaseDatabaseWrapper") -> None:
BaseDatabaseWrapper.connect = connect
BaseDatabaseWrapper._commit = _commit
BaseDatabaseWrapper._rollback = _rollback
ignore_logger("django.db.backends")
ignore_logger_for_events("django.db.backends")


def _set_db_data(
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_check_minimum_version,
)
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.tracing_utils import has_span_streaming_enabled
Expand Down Expand Up @@ -85,7 +85,7 @@ def setup_once() -> None:
# The `LitestarIntegration`` provides an after_exception hook (see `patch_app_init` below) to create a Sentry event
# from an exception, which ends up being called during step 2 above. However, the Sentry `LoggingIntegration` will
# by default create a Sentry event from error logs made in step 1 if we do not prevent it from doing so.
ignore_logger("litestar")
ignore_logger_for_events("litestar")


class SentryLitestarASGIMiddleware(SentryAsgiMiddleware):
Expand Down
Loading
Loading