Skip to content

Commit d17d325

Browse files
feat(python): Add sentry_logs_level option to Loguru, logging integration (#14015)
## DESCRIBE YOUR PR Since we started supporting Sentry logs via the logging integration (and more recently Loguru), we haven't added the new `sentry_logs_level` option used to fine-tune which logs should be captured. Adding it here. Direct links to preview: - [logging](https://sentry-docs-git-ivana-pythonsentry-logs-level.sentry.dev/platforms/python/integrations/logging/#options) - [Loguru](https://sentry-docs-git-ivana-pythonsentry-logs-level.sentry.dev/platforms/python/integrations/loguru/#options) ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
1 parent 60f32dc commit d17d325

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ sentry_sdk.init(
7272
# ...
7373
integrations=[
7474
LoggingIntegration(
75-
level=logging.INFO, # Capture info and above as breadcrumbs
76-
event_level=logging.INFO # Send records as events
75+
level=logging.INFO, # Capture INFO and above as breadcrumbs
76+
event_level=logging.ERROR, # Send ERROR records as events
77+
sentry_logs_level=logging.INFO, # Capture INFO and above as logs
7778
),
7879
],
7980
)
@@ -85,6 +86,15 @@ You can pass the following keyword arguments to `LoggingIntegration()`:
8586

8687
- `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.
8788

89+
- `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`:
90+
91+
```python
92+
sentry_sdk.init(
93+
# ...
94+
_experiments={"enable_logs": True},
95+
)
96+
```
97+
8898
<Alert title="Note">
8999

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

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,14 @@ from loguru import logger
108108
from sentry_sdk.integrations.loguru import LoguruIntegration
109109
from sentry_sdk.integrations.loguru import LoggingLevels
110110

111-
sentry_loguru = LoguruIntegration(
112-
level=LoggingLevels.INFO.value, # Capture info and above as breadcrumbs
113-
event_level=LoggingLevels.ERROR.value # Send errors as events
114-
)
115-
116111
sentry_sdk.init(
117112
# ...
118113
integrations=[
119-
sentry_loguru,
114+
LoguruIntegration(
115+
level=LoggingLevels.INFO.value, # Capture INFO and above as breadcrumbs
116+
event_level=LoggingLevels.ERROR.value, # Send ERROR logs as events
117+
sentry_logs_level=LoggingLevels.INFO.value, # Capture INFO and above as logs
118+
)
120119
],
121120
)
122121
```
@@ -133,6 +132,22 @@ sentry_sdk.init(
133132

134133
Default: `ERROR`
135134

135+
- `sentry_logs_level`
136+
137+
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.
138+
139+
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).
140+
141+
```python
142+
sentry_sdk.init(
143+
# ...
144+
_experiments={"enable_logs": True},
145+
)
146+
```
147+
148+
Default: `INFO`
149+
150+
136151
## Supported Versions
137152

138153
- Loguru: 0.5+

0 commit comments

Comments
 (0)