diff --git a/docs/platforms/python/configuration/options.mdx b/docs/platforms/python/configuration/options.mdx index a16caac7bb578..e14435b658387 100644 --- a/docs/platforms/python/configuration/options.mdx +++ b/docs/platforms/python/configuration/options.mdx @@ -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`. @@ -245,8 +245,19 @@ The callback typically gets a second argument (called a "hint") which contains t + + +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. + + + + ## Transport Options 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 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. + + +## Logs Options + + + +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. + + diff --git a/docs/platforms/python/index.mdx b/docs/platforms/python/index.mdx index b4bacc8a4f480..f979aec1d56c9 100644 --- a/docs/platforms/python/index.mdx +++ b/docs/platforms/python/index.mdx @@ -43,8 +43,6 @@ uv add "sentry-sdk" Configuration should happen as **early as possible** in your application's lifecycle. - - ```python import sentry_sdk @@ -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 ) ``` diff --git a/docs/platforms/python/integrations/logging/index.mdx b/docs/platforms/python/integrations/logging/index.mdx index 9ba52e3c3e2ff..92968d8871366 100644 --- a/docs/platforms/python/integrations/logging/index.mdx +++ b/docs/platforms/python/integrations/logging/index.mdx @@ -54,7 +54,7 @@ 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 @@ -62,9 +62,7 @@ import sentry_sdk sentry_sdk.init( # ... - _experiments={ - "enable_logs": True, - }, + enable_logs=True, ) logging.info("I will be sent to Sentry logs") @@ -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, ) ``` diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 1712da6489a3f..dbced60b7467c 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -68,7 +68,7 @@ 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 @@ -76,9 +76,7 @@ from loguru import logger sentry_sdk.init( # ... - _experiments={ - "enable_logs": True, - }, + enable_logs=True, ) logger.info("I will be sent to Sentry logs") @@ -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, ) ``` diff --git a/platform-includes/getting-started-config/python.mdx b/platform-includes/getting-started-config/python.mdx index ae604a35701e1..a3bee6954f718 100644 --- a/platform-includes/getting-started-config/python.mdx +++ b/platform-includes/getting-started-config/python.mdx @@ -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 ) ``` diff --git a/platform-includes/logs/integrations/python.mdx b/platform-includes/logs/integrations/python.mdx index 7cf4b0bdb5d5a..5814955b2c98d 100644 --- a/platform-includes/logs/integrations/python.mdx +++ b/platform-includes/logs/integrations/python.mdx @@ -8,9 +8,7 @@ import logging sentry_sdk.init( dsn="___PUBLIC_DSN___", - _experiments={ - "enable_logs": True, - }, + enable_logs=True, ) # Your existing logging setup @@ -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. @@ -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 ], @@ -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.") @@ -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), @@ -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), diff --git a/platform-includes/logs/options/python.mdx b/platform-includes/logs/options/python.mdx index 774665118dcdf..df7f590aed7e4 100644 --- a/platform-includes/logs/options/python.mdx +++ b/platform-includes/logs/options/python.mdx @@ -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 @@ -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, ) ``` @@ -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. \ No newline at end of file +- `trace_id`: (`Optional[str]`) The trace ID of the trace this log belongs to. diff --git a/platform-includes/logs/setup/python.mdx b/platform-includes/logs/setup/python.mdx index 4f827fda72645..430d49e48c5ac 100644 --- a/platform-includes/logs/setup/python.mdx +++ b/platform-includes/logs/setup/python.mdx @@ -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, ) ```