Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/platforms/python/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,10 @@ Self-hosted Sentry users should set this option to `False`, as standalone `gen_a

<SdkOption name="enable_logs" type='bool' defaultValue='False'>

Enables Sentry structured logs, allowing you to use the `sentry_sdk.logger` APIs
to send logs to Sentry. This option must be set to `True` to automatically capture logs from Python’s built-in logging module or other supported logging integrations.
Starting from `2.68.0`, this option has no effect. The `sentry_sdk.logger` API works standalone. Automatic capture of logs by integrations is off by default and can be toggled on the integration level with the `capture_sentry_logs` integration option. See the [Logs documentation](/platforms/python/logs#other-logging-integrations) for more details.

New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.
In older SDK versions (prior to `2.68`), this option had to be set to `True` to be able to use the `sentry_sdk.logger` API. It also enabled automatic capture of logs from the standard library `logging` module as well as from Loguru.

Made no-op in version `2.68.0`. New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.

</SdkOption>
8 changes: 1 addition & 7 deletions docs/platforms/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ sentry_sdk.init(
# see https://docs.sentry.io/platforms/python/configuration/options/#profile_lifecycle for more info
profile_lifecycle="trace",
# ___PRODUCT_OPTION_END___ profiling
# ___PRODUCT_OPTION_START___ logs

# Enable logs to be sent to Sentry
# see https://docs.sentry.io/platforms/python/configuration/options/#enable_logs for more info
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
)
```

Expand Down Expand Up @@ -242,7 +236,7 @@ with sentry_sdk.start_transaction(op="task", name="Transaction Name"):
<SplitSection>
<SplitSectionText>

To verify that Sentry catches your logs, add some log statements to your application:
To verify that Sentry catches your logs (which are enabled by default), add some log statements to your application:

</SplitSectionText>
<SplitSectionCode>
Expand Down
7 changes: 1 addition & 6 deletions docs/platforms/python/integrations/django/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ uv add sentry-sdk
Choose the features you want to configure, and this guide will show you how:

<OnboardingOptionButtons
options={["error-monitoring", "performance", "profiling", "logs"]}
options={["error-monitoring", "performance", "profiling"]}
/>

To configure the Sentry SDK, initialize it in your `settings.py` file:
Expand All @@ -58,11 +58,6 @@ sentry_sdk.init(
# there is an active span.
profile_lifecycle="trace",
# ___PRODUCT_OPTION_END___ profiling
# ___PRODUCT_OPTION_START___ logs

# Enable logs to be sent to Sentry
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
)
```

Expand Down
33 changes: 19 additions & 14 deletions docs/platforms/python/integrations/logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The logging integration adds support for the `logging` framework from Python's s

<Alert level="info" title="Sentry Logs">

Enable the Sentry Logs feature with `sentry_sdk.init(enable_logs=True)` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.
Enable the Sentry Logs feature with `LoggingIntegration(capture_sentry_logs=True)` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.

</Alert>

Expand All @@ -25,17 +25,20 @@ uv add "sentry-sdk"

## Configure

To capture log records as [Sentry logs](/platforms/python/logs/), set `enable_logs` to `True`. The logging integration is a default integration, so it will be enabled automatically when you initialize the Sentry SDK.
The logging integration is a default integration, so it will be enabled automatically when you initialize the Sentry SDK. To capture log records as [Sentry logs](/platforms/python/logs/), set `capture_sentry_logs` to `True` on the integration.

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

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
enable_logs=True,
integrations=[
LoggingIntegration(capture_sentry_logs=True),
],
)
```

Expand All @@ -56,7 +59,7 @@ This will capture both logs and send them to Sentry Logs. Additionally, an error

## Behavior

As long as `enable_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs if the log level set in the `logging` module is `INFO` or below. The threshold can be configured via the [`sentry_logs_level` option](#options).
When `capture_sentry_logs` is `True`, logs with a level of `INFO` and higher will be captured as Sentry logs if the log level set in the `logging` module is `INFO` or below. The threshold can be configured via the [`sentry_logs_level` option](#options).

Additionally, the logging integration will create an error event from all `ERROR`-level logs. This feature is configurable via the [`event_level` integration option](#options).

Expand All @@ -66,10 +69,13 @@ Additionally, the logging integration will create an error event from all `ERROR
import logging

import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
...,
enable_logs=True,
integrations=[
LoggingIntegration(capture_sentry_logs=True),
],
)

# The following will be captured as Sentry logs:
Expand All @@ -96,10 +102,13 @@ When sending log records as Sentry logs, any fields provided in the `extra` dict
```python
import logging
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
# ...
enable_logs=True,
integrations=[
LoggingIntegration(capture_sentry_logs=True),
],
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -136,6 +145,7 @@ sentry_sdk.init(
# ...
integrations=[
LoggingIntegration(
capture_sentry_logs=True, # Capture log records as Sentry logs
sentry_logs_level=logging.INFO, # Capture INFO and above as logs
level=logging.INFO, # Capture INFO and above as breadcrumbs
event_level=logging.ERROR, # Send ERROR records as events
Expand All @@ -146,14 +156,9 @@ sentry_sdk.init(

You can pass the following keyword arguments to `LoggingIntegration()`:

- `sentry_logs_level` (default `INFO`): The Sentry Python SDK will capture records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/) as long as the `enable_logs` option is `True`.
- `capture_sentry_logs` (default `False`): Set to `True` to capture log records as [Sentry structured logs](/platforms/python/logs/).

```python
sentry_sdk.init(
# ...
enable_logs=True,
)
```
- `sentry_logs_level` (default `INFO`): The Sentry Python SDK will capture records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/) as long as `capture_sentry_logs` is `True`.

- `level` (default `INFO`): The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If a value of `None` occurs, the SDK won't send log records as breadcrumbs.

Expand Down Expand Up @@ -197,7 +202,7 @@ See the [API documentation](https://getsentry.github.io/sentry-python/integratio

<Expandable title="Logs not appearing in Sentry">

First, make sure you have the `enable_logs=True` option in your `sentry_sdk.init()` and you're on the latest version of the SDK.
First, make sure you're on the latest version of the SDK. If you're using the `sentry_sdk.logger` API directly (e.g., `sentry_sdk.logger.info(...)`), logs are sent automatically. If you're using Python's `logging` module and want those log records captured as Sentry logs, make sure you have `capture_sentry_logs=True` set on your `LoggingIntegration`.

The SDK will honor the configured level of each logger (set with `logger.setLevel(level)` or `logging.basicConfig(level=level)`). That means that you will not see any `INFO` or `DEBUG` events from a logger with the level set to `WARNING`, regardless of how you configure the integration. If not set explicitly, the logging level defaults to `WARNING`.

Expand Down
34 changes: 19 additions & 15 deletions docs/platforms/python/integrations/loguru/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The [`logging`](/platforms/python/integrations/logging) integration provides mos

<Alert level="info" title="Sentry Logs for Loguru">

Enable the Sentry Logs feature with `sentry_sdk.init(enable_logs=True)` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.
Enable the Sentry Logs feature with `LoguruIntegration(capture_sentry_logs=True)` to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place.

</Alert>

Expand All @@ -28,17 +28,20 @@ uv add sentry-sdk

## Configure

To capture Loguru log records as [Sentry logs](/platforms/python/logs/), set `enable_logs` to `True`. The integration itself doesn't need to be added manually. If you have the `loguru` package in your dependencies, the Loguru integration will be enabled automatically when you initialize the Sentry SDK.
If you have the `loguru` package in your dependencies, the Loguru integration will be enabled automatically when you initialize the Sentry SDK. To capture Loguru log records as [Sentry logs](/platforms/python/logs/), set `capture_sentry_logs` to `True` on the integration.

```python
import sentry_sdk
from sentry_sdk.integrations.loguru import LoguruIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
enable_logs=True,
integrations=[
LoguruIntegration(capture_sentry_logs=True),
],
)
```

Expand All @@ -60,7 +63,7 @@ This will capture both logs and send them to Sentry Logs. Additionally, an error

## Behavior

Logs with a level of `INFO` and higher will be captured as Sentry logs as long as `enable_logs` is `True` and the log level set in the `logging` module is `INFO` or below. The threshold can be configured via the [`sentry_logs_level` option](#options).
Logs with a level of `INFO` and higher will be captured as Sentry logs as long as `capture_sentry_logs` is `True` and the log level set in the `logging` module is `INFO` or below. The threshold can be configured via the [`sentry_logs_level` option](#options).

Additionally, the Loguru integration will create an error event from all `ERROR`-level logs. This feature is configurable via the [`event_level` integration option](#options).

Expand All @@ -71,10 +74,13 @@ The following snippet demonstrates the default behavior:
```python
import sentry_sdk
from loguru import logger
from sentry_sdk.integrations.loguru import LoguruIntegration

sentry_sdk.init(
...,
enable_logs=True,
integrations=[
LoguruIntegration(capture_sentry_logs=True),
],
)

# The following will be captured as Sentry logs:
Expand Down Expand Up @@ -138,6 +144,7 @@ sentry_sdk.init(
# ...
integrations=[
LoguruIntegration(
capture_sentry_logs=True, # Capture Loguru logs as Sentry logs
sentry_logs_level=LoggingLevels.INFO.value, # Capture INFO and above as logs
level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs
event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events
Expand All @@ -147,18 +154,15 @@ sentry_sdk.init(
```


- `sentry_logs_level`
- `capture_sentry_logs`

The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/). If set to `None`, the SDK won't send records as logs.
Set to `True` to capture Loguru log records as [Sentry structured logs](/platforms/python/logs/).

To capture Loguru log records as Sentry logs, you must enable the `enable_logs` option when initializing the SDK (regardless of the `sentry_logs_level` setting).
Default: `False`

- `sentry_logs_level`

```python
sentry_sdk.init(
# ...
enable_logs=True,
)
```
The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as [Sentry structured logs](/platforms/python/logs/). If set to `None`, the SDK won't send records as logs. Only applies when `capture_sentry_logs` is `True`.

Default: `INFO`

Expand All @@ -178,7 +182,7 @@ sentry_sdk.init(

<Expandable title="Logs not appearing in Sentry">

First, make sure you have the `enable_logs=True` option in your `sentry_sdk.init()` and you're on the latest version of the SDK.
First, make sure you're on the latest version of the SDK. If you're using the `sentry_sdk.logger` API directly (e.g., `sentry_sdk.logger.info(...)`), logs are sent automatically. If you're using Loguru and want those log records captured as Sentry logs, make sure you have `capture_sentry_logs=True` set on your `LoguruIntegration`.

Your logs could be missing because of the logging level of the logger. The SDK will honor the configured level of each logger. That means that you won't see any `INFO` or `DEBUG` data in Sentry from a logger with the level set to `WARNING`, regardless of how you configure the integration.

Expand Down
6 changes: 1 addition & 5 deletions docs/platforms/python/integrations/otlp/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For the OpenTelemetry SDK, you need to [configure instrumentation](https://opent
For the Sentry SDK, add the `OTLPIntegration` to your existing configuration.

<OnboardingOptionButtons
options={["error-monitoring", "logs"]}
options={["error-monitoring"]}
/>

```python
Expand All @@ -42,10 +42,6 @@ sentry_sdk.init(
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# ___PRODUCT_OPTION_START___ logs
# Enable logs to be sent to Sentry
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
integrations=[
OTLPIntegration(),
],
Expand Down
7 changes: 1 addition & 6 deletions platform-includes/getting-started-config/python.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<OnboardingOptionButtons
options={["error-monitoring", "performance", "profiling", "logs"]}
options={["error-monitoring", "performance", "profiling"]}
/>

```python
Expand All @@ -23,10 +23,5 @@ sentry_sdk.init(
# there is an active span.
profile_lifecycle="trace",
# ___PRODUCT_OPTION_END___ profiling
# ___PRODUCT_OPTION_START___ logs

# Enable logs to be sent to Sentry
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
)
```
1 change: 0 additions & 1 deletion platform-includes/logs/options/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def before_log(log: Log, _hint: Hint) -> Optional[Log]:

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
enable_logs=True,
before_send_log=before_log,
)
```
Expand Down
3 changes: 1 addition & 2 deletions platform-includes/logs/setup/python.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `True`.
Logging is enabled by default, no extra configuration needed.

```python
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
enable_logs=True,
)
```
Loading