Skip to content

Commit a1f13af

Browse files
feat(python): Replace experimental logs options with regular ones (#14513)
We'll be promoting the `enable_logs` and `before_send_log` options to regular SDK options. (We'll still keep the experimental counterparts until 3.0.) --------- Co-authored-by: Alex Krawiec <[email protected]>
1 parent c4a97a6 commit a1f13af

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

docs/platforms/python/configuration/options.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Please note that the Sentry server [limits HTTP request body size](https://devel
176176

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

179-
In SDK versions prior to 2.34.0, the default was 1024.
179+
In SDK versions prior to `2.34.0`, the default was `1024`.
180180

181181
</SdkOption>
182182

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

246246
</SdkOption>
247247

248+
<SdkOption name="before_send_log" type='Optional[Callable[Log, Hint] -> Optional[Log]]' defaultValue='None'>
249+
250+
A function that will be called for each log. It can be used to modify the log
251+
before it's sent to Sentry or to filter specific logs out altogether (if it returns
252+
`None`).
253+
254+
New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.
255+
256+
</SdkOption>
257+
248258
<PlatformContent includePath="/performance/traces-sampler-config-option" />
249259

260+
250261
## Transport Options
251262

252263
Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.
@@ -412,3 +423,15 @@ In `trace` mode, the profiler starts and stops automatically based on active spa
412423
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.
413424

414425
</SdkOption>
426+
427+
428+
## Logs Options
429+
430+
<SdkOption name="enable_logs" type='bool' defaultValue='False'>
431+
432+
Enables Sentry structured logs, allowing you to use the `sentry_sdk.logger` APIs
433+
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.
434+
435+
New in SDK version `2.35.0`. Prior to `2.35.0`, this option was experimental.
436+
437+
</SdkOption>

docs/platforms/python/integrations/logging/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ main()
5454
- `"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.
5555
- The debug message `"I am ignored"` will not surface anywhere. To capture it, you need to lower `level` to `DEBUG` (See below).
5656

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

5959
```python
6060
import logging
@@ -129,7 +129,7 @@ You can pass the following keyword arguments to `LoggingIntegration()`:
129129

130130
- `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.
131131

132-
- `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`.
132+
- `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`.
133133

134134
```python
135135
sentry_sdk.init(

docs/platforms/python/integrations/loguru/index.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,15 @@ logger.exception("An exception happened")
6868
- `"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.
6969
- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`.
7070

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

7373
```python
7474
import sentry_sdk
7575
from loguru import logger
7676

7777
sentry_sdk.init(
7878
# ...
79-
_experiments={
80-
"enable_logs": True,
81-
},
79+
enable_logs=True,
8280
)
8381

8482
logger.info("I will be sent to Sentry logs")
@@ -152,7 +150,7 @@ sentry_sdk.init(
152150

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

155-
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).
153+
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).
156154

157155
```python
158156
sentry_sdk.init(

platform-includes/logs/setup/python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To enable logging, you need to initialize the SDK with the `_experiments["enable_logs"]` option set to `True`.
1+
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `True`.
22

33
```python
44
sentry_sdk.init(

0 commit comments

Comments
 (0)