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
25 changes: 24 additions & 1 deletion docs/platforms/python/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Please note that the Sentry server [limits HTTP request body size](https://devel

The number of characters after which the values containing text in the event payload will be truncated.

In SDK versions prior to 2.34.0, the default was 1024.
In SDK versions prior to `2.34.0`, the default was `1024`.

</SdkOption>

Expand Down Expand Up @@ -245,8 +245,19 @@ The callback typically gets a second argument (called a "hint") which contains t

</SdkOption>

<SdkOption name="before_send_log" type='Optional[Callable[Log, Hint] -> Optional[Log]]' defaultValue='None'>

A function that will be called for each log. It can be used to modify the log
before it's sent to Sentry or to filter specific logs out altogether (if it returns
`None`).

New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.

</SdkOption>

<PlatformContent includePath="/performance/traces-sampler-config-option" />


## Transport Options

Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.
Expand Down Expand Up @@ -412,3 +423,15 @@ In `trace` mode, the profiler starts and stops automatically based on active spa
A number between `0` and `1`, controlling the percentage chance a given session will be profiled. The sampling decision is evaluated only once at SDK initialization.

</SdkOption>


## Logs Options

<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.

New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.

</SdkOption>
4 changes: 1 addition & 3 deletions docs/platforms/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ uv add "sentry-sdk"

Configuration should happen as **early as possible** in your application's lifecycle.



```python
import sentry_sdk

Expand All @@ -69,7 +67,7 @@ sentry_sdk.init(
# ___PRODUCT_OPTION_START___ logs

# Enable logs to be sent to Sentry
_experiments={"enable_logs": True},
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
)
```
Expand Down
10 changes: 4 additions & 6 deletions docs/platforms/python/integrations/logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ main()
- `"An exception happened"` will send the current exception from `sys.exc_info()` with the stack trace and everything to the Sentry Python SDK. If there's no exception, the current stack will be attached.
- The debug message `"I am ignored"` will not surface anywhere. To capture it, you need to lower `level` to `DEBUG` (See below).

Log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` experimental option is `True`.
Log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` option is `True`.

```python
import logging
import sentry_sdk

sentry_sdk.init(
# ...
_experiments={
"enable_logs": True,
},
enable_logs=True,
)

logging.info("I will be sent to Sentry logs")
Expand Down Expand Up @@ -102,12 +100,12 @@ You can pass the following keyword arguments to `LoggingIntegration()`:

- `event_level` (default `ERROR`): The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events as long as the logger itself is set to output records of those log levels (see note below). If a value of `None` occurs, the SDK won't send log records as events.

- `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` experimental option is `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 the `enable_logs` option is `True`.

```python
sentry_sdk.init(
# ...
_experiments={"enable_logs": True},
enable_logs=True,
)
```

Expand Down
10 changes: 4 additions & 6 deletions docs/platforms/python/integrations/loguru/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ logger.exception("An exception happened")
- `"An exception happened"` will send the current exception from `sys.exc_info()` with the stack trace to Sentry. If there's no exception, the current stack will be attached.
- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`.

Loguru log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` experimental option is `True`.
Loguru log records can additionally also be captured as [Sentry logs](/platforms/python/logs/) as long as the `enable_logs` option is `True`.

```python
import sentry_sdk
from loguru import logger

sentry_sdk.init(
# ...
_experiments={
"enable_logs": True,
},
enable_logs=True,
)

logger.info("I will be sent to Sentry logs")
Expand Down Expand Up @@ -152,12 +150,12 @@ sentry_sdk.init(

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.

To capture Loguru log records as Sentry logs, you must enable the experimental `enable_logs` option when initializing the SDK (regardless of the `sentry_logs_level` setting).
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).

```python
sentry_sdk.init(
# ...
_experiments={"enable_logs": True},
enable_logs=True,
)
```

Expand Down
4 changes: 1 addition & 3 deletions platform-includes/getting-started-config/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ sentry_sdk.init(
# ___PRODUCT_OPTION_START___ logs

# Enable logs to be sent to Sentry
_experiments={
"enable_logs": True,
},
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
)
```
26 changes: 7 additions & 19 deletions platform-includes/logs/integrations/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import logging

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True,
},
enable_logs=True,
)

# Your existing logging setup
Expand All @@ -31,9 +29,7 @@ from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True
},
enable_logs=True,
integrations=[
# Only send WARNING (and higher) logs to Sentry logs,
# even if the logger is set to a lower level.
Expand Down Expand Up @@ -62,9 +58,7 @@ from sentry_sdk.integrations.logging import LoggingIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True
},
enable_logs=True,
integrations=[
LoggingIntegration(sentry_logs_level=None), # Do not monkeypatch the sentry handler
],
Expand All @@ -84,9 +78,7 @@ from loguru import logger

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True,
},
enable_logs=True,
)

loguru.debug("In this example, debug events will not be sent to Sentry logs.")
Expand All @@ -102,9 +94,7 @@ from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True
},
enable_logs=True,
integrations=[
# Only send WARNING (and higher) logs to Sentry logs
LoguruIntegration(sentry_logs_level=LoggingLevels.WARNING.value),
Expand All @@ -125,10 +115,8 @@ from sentry_sdk.integrations.loguru import LoguruIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
# In general, we want to capture logs as Sentry logs...
"enable_logs": True,
},
# In general, we want to capture logs as Sentry logs...
enable_logs=True,
integrations=[
# ...just not from Loguru
LoguruIntegration(sentry_logs_level=None),
Expand Down
10 changes: 4 additions & 6 deletions platform-includes/logs/options/python.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### before_send_log

To filter logs, or update them before they are sent to Sentry, you can use the `_experiments["before_send_log"]` option.
To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option.

```python
import sentry_sdk
Expand All @@ -15,10 +15,8 @@ def before_log(log: Log, _hint: Hint) -> Optional[Log]:

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True,
"before_send_log": before_log,
},
enable_logs=True,
before_send_log=before_log,
)
```

Expand All @@ -31,4 +29,4 @@ The log dict has the following keys:
- `body`: (`str`) The log message.
- `attributes`: (`dict[str, str | bool | float | int]`) Additional attributes to be sent with the log.
- `time_unix_nano`: (`int`) The timestamp of the log in nanoseconds since the Unix epoch.
- `trace_id`: (`Optional[str]`) The trace ID of the trace this log belongs to.
- `trace_id`: (`Optional[str]`) The trace ID of the trace this log belongs to.
6 changes: 2 additions & 4 deletions platform-includes/logs/setup/python.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
To enable logging, you need to initialize the SDK with the `_experiments["enable_logs"]` option set to `True`.
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `True`.

```python
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
_experiments={
"enable_logs": True,
},
enable_logs=True,
)
```