From 4fdbbf648f0e1eb56e0ff3869039276674dd08af Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Jun 2025 12:19:12 +0200 Subject: [PATCH 1/6] feat(python): Add sentry_logs_level option to Loguru, Logging integration --- .../python/integrations/logging/index.mdx | 14 ++++++++-- .../python/integrations/loguru/index.mdx | 27 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/docs/platforms/python/integrations/logging/index.mdx b/docs/platforms/python/integrations/logging/index.mdx index b817408e435b97..1d504540d68dc4 100644 --- a/docs/platforms/python/integrations/logging/index.mdx +++ b/docs/platforms/python/integrations/logging/index.mdx @@ -72,8 +72,9 @@ sentry_sdk.init( # ... integrations=[ LoggingIntegration( - level=logging.INFO, # Capture info and above as breadcrumbs - event_level=logging.INFO # Send records as events + level=logging.INFO, # Capture INFO and above as breadcrumbs + event_level=logging.INFO # Send INFO records as events + sentry_logs_level=logging.WARNING, # Capture WARNING and above as logs ), ], ) @@ -85,6 +86,15 @@ 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 logs as long as the `enable_logs` experimental option is `True`: + + ```python + sentry_sdk.init( + # ... + _experiments={"enable_logs": True}, + ) + ``` + The Sentry Python 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`. diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 9bd471101724ad..0e9b297131ec2a 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -108,15 +108,14 @@ from loguru import logger from sentry_sdk.integrations.loguru import LoguruIntegration from sentry_sdk.integrations.loguru import LoggingLevels -sentry_loguru = LoguruIntegration( - level=LoggingLevels.INFO.value, # Capture info and above as breadcrumbs - event_level=LoggingLevels.ERROR.value # Send errors as events -) - sentry_sdk.init( # ... integrations=[ - sentry_loguru, + LoguruIntegration( + level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs + event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events + sentry_logs_level=LoggingLevels.ERROR.value, # Capture WARNING and above as logs + ) ], ) ``` @@ -133,6 +132,22 @@ sentry_sdk.init( Default: `ERROR` +- `sentry_logs_level` + + The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as logs. If set to `None`, the SDK won't send records as logs. + + This option is used for fine-tuning the Sentry logs experience. You need to have the experimental `enable_logs` option set to `True` to capture Loguru logs. + + ```python + sentry_sdk.init( + # ... + _experiments={"enable_logs": True}, + ) + ``` + + Default: `INFO` + + ## Supported Versions - Loguru: 0.5+ From fe99afc8e9ab3f5191b13b165eb50ac211637294 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Jun 2025 12:28:15 +0200 Subject: [PATCH 2/6] syntax --- docs/platforms/python/integrations/logging/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/logging/index.mdx b/docs/platforms/python/integrations/logging/index.mdx index 1d504540d68dc4..386065995ae5cc 100644 --- a/docs/platforms/python/integrations/logging/index.mdx +++ b/docs/platforms/python/integrations/logging/index.mdx @@ -73,7 +73,7 @@ sentry_sdk.init( integrations=[ LoggingIntegration( level=logging.INFO, # Capture INFO and above as breadcrumbs - event_level=logging.INFO # Send INFO records as events + event_level=logging.INFO, # Send INFO records as events sentry_logs_level=logging.WARNING, # Capture WARNING and above as logs ), ], From 8c7af47eb1ed5d20a3842deae99c6d534502c7b0 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Jun 2025 12:53:42 +0200 Subject: [PATCH 3/6] fix comment --- docs/platforms/python/integrations/loguru/index.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 0e9b297131ec2a..747ffcf7f8ee8d 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -112,9 +112,9 @@ sentry_sdk.init( # ... integrations=[ LoguruIntegration( - level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs - event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events - sentry_logs_level=LoggingLevels.ERROR.value, # Capture WARNING and above as logs + level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs + event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events + sentry_logs_level=LoggingLevels.WARNING.value, # Capture WARNING and above as logs ) ], ) From ba133698fde5fcdd98ca0eaa62b4d878a139e2bd Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Jun 2025 14:11:04 +0200 Subject: [PATCH 4/6] Update docs/platforms/python/integrations/loguru/index.mdx Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com> --- docs/platforms/python/integrations/loguru/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index 747ffcf7f8ee8d..d157f67c19a5c2 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -136,7 +136,7 @@ sentry_sdk.init( The Sentry Python SDK will capture log records with a level higher than or equal to `sentry_logs_level` as logs. If set to `None`, the SDK won't send records as logs. - This option is used for fine-tuning the Sentry logs experience. You need to have the experimental `enable_logs` option set to `True` to capture Loguru 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). ```python sentry_sdk.init( From 5125c411a1a0ecbb0a15122da065d7dc76817125 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Jun 2025 14:10:15 +0200 Subject: [PATCH 5/6] Set levels to defaults --- docs/platforms/python/integrations/logging/index.mdx | 6 +++--- docs/platforms/python/integrations/loguru/index.mdx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/platforms/python/integrations/logging/index.mdx b/docs/platforms/python/integrations/logging/index.mdx index 386065995ae5cc..9683270ad88101 100644 --- a/docs/platforms/python/integrations/logging/index.mdx +++ b/docs/platforms/python/integrations/logging/index.mdx @@ -72,9 +72,9 @@ sentry_sdk.init( # ... integrations=[ LoggingIntegration( - level=logging.INFO, # Capture INFO and above as breadcrumbs - event_level=logging.INFO, # Send INFO records as events - sentry_logs_level=logging.WARNING, # Capture WARNING and above as logs + level=logging.INFO, # Capture INFO and above as breadcrumbs + event_level=logging.ERROR, # Send ERROR records as events + sentry_logs_level=logging.INFO, # Capture INFO and above as logs ), ], ) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index d157f67c19a5c2..acb180b4d03a50 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -112,9 +112,9 @@ sentry_sdk.init( # ... integrations=[ LoguruIntegration( - level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs - event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events - sentry_logs_level=LoggingLevels.WARNING.value, # Capture WARNING and above as logs + level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs + event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events + sentry_logs_level=LoggingLevels.INFO.value, # Capture WARNING and above as logs ) ], ) From d7e6399fb892b81b9366ebe81b0b9ba617020e5c Mon Sep 17 00:00:00 2001 From: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com> Date: Thu, 12 Jun 2025 14:14:20 +0200 Subject: [PATCH 6/6] Update docs/platforms/python/integrations/loguru/index.mdx --- docs/platforms/python/integrations/loguru/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/loguru/index.mdx b/docs/platforms/python/integrations/loguru/index.mdx index acb180b4d03a50..8301995f88219e 100644 --- a/docs/platforms/python/integrations/loguru/index.mdx +++ b/docs/platforms/python/integrations/loguru/index.mdx @@ -114,7 +114,7 @@ sentry_sdk.init( LoguruIntegration( level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events - sentry_logs_level=LoggingLevels.INFO.value, # Capture WARNING and above as logs + sentry_logs_level=LoggingLevels.INFO.value, # Capture INFO and above as logs ) ], )