From 22e5c247bb2d6699d026841e48b778c05809c77e Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Sat, 8 Apr 2023 13:24:42 +0200 Subject: [PATCH 1/9] Add docs for `loguru` integration (Again) mostly copied from `logging` docs --- src/platforms/python/guides/loguru/index.mdx | 95 ++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/platforms/python/guides/loguru/index.mdx diff --git a/src/platforms/python/guides/loguru/index.mdx b/src/platforms/python/guides/loguru/index.mdx new file mode 100644 index 0000000000000..5170a820b2896 --- /dev/null +++ b/src/platforms/python/guides/loguru/index.mdx @@ -0,0 +1,95 @@ +--- +title: Loguru +description: Learn about using Sentry with loguru. +--- + +[Loguru](https://github.com/Delgan/loguru#readme) is a package for stupidly simple logging. The most of the work in +integration is handled by [`logging`](/platforms/python/guides/logging) integration, so the most of the examples there +will work with loguru. + +Integration supports `0.5.0` (released in 2020-05-17) and upper. + +The installation of integration is handled automatically on `sentry_sdk.init()` call. The same as with logging, you can +control what levels will be sent to Sentry. + +```python +import sentry_sdk +from loguru import logger + +# You can also import our enum with log levels, as it isn't in loguru itself. +from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration + +# All of this is already happening by default! +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( + dsn="___PUBLIC_DSN___", + integrations=[ + sentry_loguru, + ], + + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + # We recommend adjusting this value in production, + traces_sample_rate=1.0, +) +``` + +## Usage + +```python +from loguru import logger + +logger.debug("I am ignored") +logger.info("I am a breadcrumb") +logger.error("I am an event", extra=dict(bar=43)) +logger.exception("An exception happened") +``` + +- There will be an error event with the message `"I am an event"`. +- `"I am a breadcrumb"` will be attached as a breadcrumb to that event. +- `bar` will end up in the event's `extra` attributes. +- `"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` in `LoguruIntegration` args. + +## Ignoring a logger + +Sometimes a logger is extremely noisy and spams you with pointless errors. You can completely ignore that logger by calling `ignore_logger`: + +```python +# As most of the logic is proxied to `logging` integration, we use it instead of `loguru` integration. +from sentry_sdk.integrations.logging import ignore_logger + + +ignore_logger("a.spammy.logger") + +logger = logging.getLogger("a.spammy.logger") +logger.error("hi") # no error sent to sentry +``` + +You can also use `before-send` and `before-breadcrumb` to ignore +only certain messages. See [_Filtering Events_](configuration/filtering/) for more information. + +## Options + +You can pass the following keyword arguments to `LoggingIntegration()`: + +- `level` (default `INFO`): The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If a value of `None` occurs, the SDK won't send log records as breadcrumbs. + +- `event_level` (default `ERROR`): The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If a value of `None` occurs, the SDK won't send log records as events. + + + +Because of the Loguru's architecture, The Sentry Python SDK will log only levels provided into `LoguruIntegration`. So if your main logger (that outputs to stdout) configured to log trace messages too, you will not see them in Sentry reports. + + + +## Handler classes + +Instead of using `LoguruIntegration`, you can use two regular logging `logging.Handler` subclasses that the integration exports (`LoguruEventHandler` and `LoguruBreadcrumbHandler`). + +**Usually, you don't need this.** You _can_ use this together with `default_integrations=False` if you want to opt into what the Sentry Python SDK captures. However, correctly setting up logging is difficult. Also, an opt-in approach to capturing data will miss errors you may not think of on your own. + +See the [API documentation](https://getsentry.github.io/sentry-python/integrations.html#module-sentry_sdk.integrations.loguru) for more information. From 3857d0b4507860605b44cbf32d461c7d47aa1b31 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 9 May 2023 20:41:27 +0200 Subject: [PATCH 2/9] Small fixes and improvements --- src/platforms/python/guides/loguru/index.mdx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/platforms/python/guides/loguru/index.mdx b/src/platforms/python/guides/loguru/index.mdx index 5170a820b2896..ab79a959533d0 100644 --- a/src/platforms/python/guides/loguru/index.mdx +++ b/src/platforms/python/guides/loguru/index.mdx @@ -24,6 +24,7 @@ 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( dsn="___PUBLIC_DSN___", integrations=[ @@ -65,8 +66,12 @@ from sentry_sdk.integrations.logging import ignore_logger ignore_logger("a.spammy.logger") +# this will work with `logging`'s logger too logger = logging.getLogger("a.spammy.logger") logger.error("hi") # no error sent to sentry +# and with loguru (in `a.spammy.logger` module) +from loguru import logger +logger.error("hi") # again, no record ``` You can also use `before-send` and `before-breadcrumb` to ignore @@ -74,7 +79,7 @@ only certain messages. See [_Filtering Events_](configuration/filtering/) for mo ## Options -You can pass the following keyword arguments to `LoggingIntegration()`: +You can pass the following keyword arguments to `LoguruIntegration()`: - `level` (default `INFO`): The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If a value of `None` occurs, the SDK won't send log records as breadcrumbs. @@ -90,6 +95,6 @@ Because of the Loguru's architecture, The Sentry Python SDK will log only levels Instead of using `LoguruIntegration`, you can use two regular logging `logging.Handler` subclasses that the integration exports (`LoguruEventHandler` and `LoguruBreadcrumbHandler`). -**Usually, you don't need this.** You _can_ use this together with `default_integrations=False` if you want to opt into what the Sentry Python SDK captures. However, correctly setting up logging is difficult. Also, an opt-in approach to capturing data will miss errors you may not think of on your own. +**Usually, you don't need this.** You _can_ use this together with `default_integrations=False` if you want to opt into what the Sentry Python SDK captures. -See the [API documentation](https://getsentry.github.io/sentry-python/integrations.html#module-sentry_sdk.integrations.loguru) for more information. +See [the source code](https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/loguru.py) for more information about API. From ec2ef944cce4c6d98f12baf0591a3acec8cd04d6 Mon Sep 17 00:00:00 2001 From: Perchun Pak Date: Wed, 10 May 2023 08:04:32 +0000 Subject: [PATCH 3/9] Move loguru docs to configuration directory --- .../index.mdx => common/configuration/integrations/loguru.mdx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/platforms/python/{guides/loguru/index.mdx => common/configuration/integrations/loguru.mdx} (100%) diff --git a/src/platforms/python/guides/loguru/index.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx similarity index 100% rename from src/platforms/python/guides/loguru/index.mdx rename to src/platforms/python/common/configuration/integrations/loguru.mdx From c0e507a7c70dc4c54540b265679b816c023abfc7 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 10 May 2023 11:41:48 +0200 Subject: [PATCH 4/9] Updated docs to be more consistent with other docs pages. --- .../configuration/integrations/asyncio.mdx | 2 +- .../integrations/gnu_backtrace.mdx | 2 +- .../configuration/integrations/grpc.mdx | 2 +- .../configuration/integrations/httpx.mdx | 2 +- .../configuration/integrations/loguru.mdx | 101 ++++++++++-------- .../configuration/integrations/pure_eval.mdx | 2 +- .../configuration/integrations/pymongo.mdx | 2 +- .../configuration/integrations/redis.mdx | 2 +- .../configuration/integrations/socket.mdx | 2 +- .../configuration/integrations/sqlalchemy.mdx | 2 +- .../configuration/integrations/wsgi.mdx | 2 +- 11 files changed, 68 insertions(+), 53 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/asyncio.mdx b/src/platforms/python/common/configuration/integrations/asyncio.mdx index 103edd535567c..b56e2f6fa0429 100644 --- a/src/platforms/python/common/configuration/integrations/asyncio.mdx +++ b/src/platforms/python/common/configuration/integrations/asyncio.mdx @@ -1,7 +1,7 @@ --- title: asyncio description: "Learn about the asyncio integration and how it adds support for applications the asyncio module." -sidebar_order: 11 +sidebar_order: 20 --- The `AsyncioIntegration` integrates with applications doing concurrent code execution using Pythons [asyncio](https://docs.python.org/3/library/asyncio.html) module. diff --git a/src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx b/src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx index a152f006ee769..a6abce3e5476b 100644 --- a/src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx +++ b/src/platforms/python/common/configuration/integrations/gnu_backtrace.mdx @@ -1,7 +1,7 @@ --- title: GNU Backtrace description: "Learn about the GNU backtrace integration and how to add it to your integrations list." -sidebar_order: 70 +sidebar_order: 50 --- diff --git a/src/platforms/python/common/configuration/integrations/grpc.mdx b/src/platforms/python/common/configuration/integrations/grpc.mdx index d358551d6183d..8dc3063e92927 100644 --- a/src/platforms/python/common/configuration/integrations/grpc.mdx +++ b/src/platforms/python/common/configuration/integrations/grpc.mdx @@ -1,7 +1,7 @@ --- title: GRPC description: "Learn about the gRPC integration and how it adds support for the grpcio grpc client and server." -sidebar_order: 80 +sidebar_order: 60 --- The [gRPC](https://grpc.io/) integration instruments all incoming requests and outgoing unary-unary, unary-stream grpc diff --git a/src/platforms/python/common/configuration/integrations/httpx.mdx b/src/platforms/python/common/configuration/integrations/httpx.mdx index d4c3124b4a90d..18229c7b0e411 100644 --- a/src/platforms/python/common/configuration/integrations/httpx.mdx +++ b/src/platforms/python/common/configuration/integrations/httpx.mdx @@ -1,7 +1,7 @@ --- title: HTTPX description: "Learn about the HTTPX integration and how it adds support for the HTTPX HTTP client." -sidebar_order: 80 +sidebar_order: 70 --- The [HTTPX](https://www.python-httpx.org/) integration instruments outgoing HTTP requests using either the sync or the async HTTPX clients. diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index ab79a959533d0..85750cd5a0aae 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -1,44 +1,39 @@ --- title: Loguru description: Learn about using Sentry with loguru. +sidebar_order: 80 --- -[Loguru](https://github.com/Delgan/loguru#readme) is a package for stupidly simple logging. The most of the work in -integration is handled by [`logging`](/platforms/python/guides/logging) integration, so the most of the examples there -will work with loguru. +The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. -Integration supports `0.5.0` (released in 2020-05-17) and upper. +Most of the work is handled by the [`logging`](/platforms/python/guides/logging) integration, so most of the examples there will work with loguru. -The installation of integration is handled automatically on `sentry_sdk.init()` call. The same as with logging, you can -control what levels will be sent to Sentry. +## Install -```python -import sentry_sdk -from loguru import logger +Install `sentry-sdk` from PyPI with the `loguru` extra. -# You can also import our enum with log levels, as it isn't in loguru itself. -from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration +```bash +pip install --upgrade 'sentry-sdk[loguru]' +``` -# All of this is already happening by default! -sentry_loguru = LoguruIntegration( - level=LoggingLevels.INFO.value, # Capture info and above as breadcrumbs - event_level=LoggingLevels.ERROR.value # Send errors as events -) +## Configure + +```python +import sentry_sdk +from sentry_sdk.integrations.loguru import LoguruIntegration sentry_sdk.init( dsn="___PUBLIC_DSN___", integrations=[ - sentry_loguru, + LoguruIntegration(), ], - - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for performance monitoring. - # We recommend adjusting this value in production, - traces_sample_rate=1.0, ) ``` -## Usage + +## Behavior + +By default log records with a level of `INFO` or higher will be added as breadcrumbs to Sentry events. For log records with a level of `ERROR` or higher a Sentry issue will be created: ```python from loguru import logger @@ -51,50 +46,70 @@ logger.exception("An exception happened") - There will be an error event with the message `"I am an event"`. - `"I am a breadcrumb"` will be attached as a breadcrumb to that event. -- `bar` will end up in the event's `extra` attributes. -- `"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` in `LoguruIntegration` args. +- `bar` will end up in the `extra` attributes of that event. +- `"An exception happened"` will send the current exception from `sys.exc_info()` with the stack trace to the 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, you need to lower `level` to `DEBUG` in `LoguruIntegration`. -## Ignoring a logger +### Ignoring a logger -Sometimes a logger is extremely noisy and spams you with pointless errors. You can completely ignore that logger by calling `ignore_logger`: +Sometimes a logger can be noisy. You can ignore that logger by calling `ignore_logger`: ```python # As most of the logic is proxied to `logging` integration, we use it instead of `loguru` integration. from sentry_sdk.integrations.logging import ignore_logger - ignore_logger("a.spammy.logger") -# this will work with `logging`'s logger too -logger = logging.getLogger("a.spammy.logger") -logger.error("hi") # no error sent to sentry # and with loguru (in `a.spammy.logger` module) from loguru import logger logger.error("hi") # again, no record ``` -You can also use `before-send` and `before-breadcrumb` to ignore -only certain messages. See [_Filtering Events_](configuration/filtering/) for more information. +You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See [_Filtering Events_](configuration/filtering/) for more information. ## Options You can pass the following keyword arguments to `LoguruIntegration()`: -- `level` (default `INFO`): The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If a value of `None` occurs, the SDK won't send log records as breadcrumbs. +```python +import sentry_sdk +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( + dsn="___PUBLIC_DSN___", + integrations=[ + sentry_loguru, + ], +) +``` + + + +The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs. + +- Default: `INFO` + + -- `event_level` (default `ERROR`): The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If a value of `None` occurs, the SDK won't send log records as events. + - +The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If set to `None`, the SDK won't send log records as events. -Because of the Loguru's architecture, The Sentry Python SDK will log only levels provided into `LoguruIntegration`. So if your main logger (that outputs to stdout) configured to log trace messages too, you will not see them in Sentry reports. +- Default: `ERROR` - -## Handler classes + -Instead of using `LoguruIntegration`, you can use two regular logging `logging.Handler` subclasses that the integration exports (`LoguruEventHandler` and `LoguruBreadcrumbHandler`). -**Usually, you don't need this.** You _can_ use this together with `default_integrations=False` if you want to opt into what the Sentry Python SDK captures. +## Supported Versions -See [the source code](https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/loguru.py) for more information about API. +- Loguru: 0.5+ +- Python: 3.5+ diff --git a/src/platforms/python/common/configuration/integrations/pure_eval.mdx b/src/platforms/python/common/configuration/integrations/pure_eval.mdx index e031f6e47d328..c074964197de1 100644 --- a/src/platforms/python/common/configuration/integrations/pure_eval.mdx +++ b/src/platforms/python/common/configuration/integrations/pure_eval.mdx @@ -1,7 +1,7 @@ --- title: Enhanced Locals description: "Learn about `pure_eval` and how to add it to your integrations list." -sidebar_order: 50 +sidebar_order: 40 --- diff --git a/src/platforms/python/common/configuration/integrations/pymongo.mdx b/src/platforms/python/common/configuration/integrations/pymongo.mdx index 5169c8d3794fe..8555fd0664aac 100644 --- a/src/platforms/python/common/configuration/integrations/pymongo.mdx +++ b/src/platforms/python/common/configuration/integrations/pymongo.mdx @@ -1,7 +1,7 @@ --- title: PyMongo description: "Learn about the PyMongo integration and how it adds support for connections to MongoDB databases." -sidebar_order: 160 +sidebar_order: 100 redirect_from: - /platforms/python/guides/pymongo/ --- diff --git a/src/platforms/python/common/configuration/integrations/redis.mdx b/src/platforms/python/common/configuration/integrations/redis.mdx index 44cd3a876e5cc..a6ba58e1df986 100644 --- a/src/platforms/python/common/configuration/integrations/redis.mdx +++ b/src/platforms/python/common/configuration/integrations/redis.mdx @@ -1,7 +1,7 @@ --- title: Redis description: "Learn about importing the Redis integration." -sidebar_order: 180 +sidebar_order: 110 --- diff --git a/src/platforms/python/common/configuration/integrations/socket.mdx b/src/platforms/python/common/configuration/integrations/socket.mdx index 2d16769875e50..484799be0aad4 100644 --- a/src/platforms/python/common/configuration/integrations/socket.mdx +++ b/src/platforms/python/common/configuration/integrations/socket.mdx @@ -1,7 +1,7 @@ --- title: SOCKET description: "Learn about the Socket integration and how it adds support network actions." -sidebar_order: 80 +sidebar_order: 90 --- Use this integration to create spans for dns resolves and connection creations. diff --git a/src/platforms/python/common/configuration/integrations/sqlalchemy.mdx b/src/platforms/python/common/configuration/integrations/sqlalchemy.mdx index eeacfbebbf839..9825f5b9df08f 100644 --- a/src/platforms/python/common/configuration/integrations/sqlalchemy.mdx +++ b/src/platforms/python/common/configuration/integrations/sqlalchemy.mdx @@ -1,7 +1,7 @@ --- title: SQLAlchemy description: "Learn about importing the SQLAlchemy integration and how it captures queries from SQLAlchemy as breadcrumbs." -sidebar_order: 190 +sidebar_order: 120 redirect_from: - /platforms/python/guides/aws-lambda/integrations/sqlalchemy/ - /platforms/python/guides/logging/integrations/sqlalchemy/ diff --git a/src/platforms/python/common/configuration/integrations/wsgi.mdx b/src/platforms/python/common/configuration/integrations/wsgi.mdx index 4ddae095dd6ec..e4a999829b9cc 100644 --- a/src/platforms/python/common/configuration/integrations/wsgi.mdx +++ b/src/platforms/python/common/configuration/integrations/wsgi.mdx @@ -1,7 +1,7 @@ --- title: WSGI description: "Learn about the WSGI integration and how it adds support for WSGI applications." -sidebar_order: 220 +sidebar_order: 130 redirect_from: - /platforms/python/guides/wsgi/ --- From a575097fcc1c9e18b970d0dce5089c934cc76c09 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 10 May 2023 13:13:50 +0200 Subject: [PATCH 5/9] Fixed link --- .../python/common/configuration/integrations/loguru.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index 85750cd5a0aae..70dcc720314f9 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -65,7 +65,7 @@ from loguru import logger logger.error("hi") # again, no record ``` -You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See [_Filtering Events_](configuration/filtering/) for more information. +You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See Filtering Events for more information. ## Options From 4ed8f73b637f1f3a315771dd7f56c1bce5486de4 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 10 May 2023 13:28:56 +0200 Subject: [PATCH 6/9] Fixed markup --- .../configuration/integrations/loguru.mdx | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index 70dcc720314f9..acf7b82639723 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -30,7 +30,6 @@ sentry_sdk.init( ) ``` - ## Behavior By default log records with a level of `INFO` or higher will be added as breadcrumbs to Sentry events. For log records with a level of `ERROR` or higher a Sentry issue will be created: @@ -91,23 +90,17 @@ sentry_sdk.init( ) ``` - - -The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs. - -- Default: `INFO` - - - - +- `level` -The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If set to `None`, the SDK won't send log records as events. + The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs. -- Default: `ERROR` + Default: `INFO` +- `event_level` - + The Sentry Python SDK will report log records with a level higher than or equal to `event_level` as events. If set to `None`, the SDK won't send log records as events. + Default: `ERROR` ## Supported Versions From 63f4e09e46f0ad7eb6fa2f46769f376780289f68 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Sat, 13 May 2023 18:37:59 +0200 Subject: [PATCH 7/9] Apply suggestions from ~~code~~ grammar review --- .../configuration/integrations/loguru.mdx | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index acf7b82639723..d6e19a6f395cc 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -1,16 +1,16 @@ --- title: Loguru -description: Learn about using Sentry with loguru. +description: Learn about using Sentry with Loguru. sidebar_order: 80 --- The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. -Most of the work is handled by the [`logging`](/platforms/python/guides/logging) integration, so most of the examples there will work with loguru. +Most of the work is handled by the [`logging`](/platforms/python/guides/logging) integration, so most of the examples there will work with Loguru. ## Install -Install `sentry-sdk` from PyPI with the `loguru` extra. +Install `sentry-sdk` from PyPI with the Loguru extra. ```bash pip install --upgrade 'sentry-sdk[loguru]' @@ -18,6 +18,8 @@ pip install --upgrade 'sentry-sdk[loguru]' ## Configure +Add `LoguruIntegration()` to your integrations list: + ```python import sentry_sdk from sentry_sdk.integrations.loguru import LoguruIntegration @@ -32,7 +34,7 @@ sentry_sdk.init( ## Behavior -By default log records with a level of `INFO` or higher will be added as breadcrumbs to Sentry events. For log records with a level of `ERROR` or higher a Sentry issue will be created: +By default, logs with a level of `INFO` or higher will be added as breadcrumbs to Sentry events. Sentry issue will be created for logs with a level of `ERROR` or higher: ```python from loguru import logger @@ -43,23 +45,23 @@ logger.error("I am an event", extra=dict(bar=43)) logger.exception("An exception happened") ``` -- There will be an error event with the message `"I am an event"`. +- An error event with the message `"I am an event"` will be created. - `"I am a breadcrumb"` will be attached as a breadcrumb to that event. - `bar` will end up in the `extra` attributes of that event. -- `"An exception happened"` will send the current exception from `sys.exc_info()` with the stack trace to the 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, you need to lower `level` to `DEBUG` in `LoguruIntegration`. +- `"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`. ### Ignoring a logger -Sometimes a logger can be noisy. You can ignore that logger by calling `ignore_logger`: +Loggers can be noisy. You can ignore a logger by calling `ignore_logger`: ```python -# As most of the logic is proxied to `logging` integration, we use it instead of `loguru` integration. +# Since most of the logic is proxied to `logging` integration, we use it instead of the Loguru integration. from sentry_sdk.integrations.logging import ignore_logger ignore_logger("a.spammy.logger") -# and with loguru (in `a.spammy.logger` module) +# and with Loguru (in `a.spammy.logger` module) from loguru import logger logger.error("hi") # again, no record ``` @@ -92,7 +94,7 @@ sentry_sdk.init( - `level` - The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK completely ignores any log record with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs. + The Sentry Python SDK will record log records with a level higher than or equal to `level` as breadcrumbs. Inversely, the SDK ignores any log record with a level lower than this one. If set to `None`, the SDK won't send log records as breadcrumbs. Default: `INFO` From a7733c0c5a411c5f049cc76ce1d292893ec3160c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 15 May 2023 10:22:55 +0200 Subject: [PATCH 8/9] Resolved one discussion --- .../python/common/configuration/integrations/loguru.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index d6e19a6f395cc..0b283f04bb60e 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -6,7 +6,7 @@ sidebar_order: 80 The [Loguru](https://github.com/Delgan/loguru#readme) integration lets you capture log messages and send them to Sentry. -Most of the work is handled by the [`logging`](/platforms/python/guides/logging) integration, so most of the examples there will work with Loguru. +The [`logging`](/platforms/python/guides/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru. ## Install @@ -49,7 +49,7 @@ logger.exception("An exception happened") - `"I am a breadcrumb"` will be attached as a breadcrumb to that event. - `bar` will end up in the `extra` attributes of that event. - `"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`. +- The debug message `"I am ignored"` will not be captured by Sentry. To capture it, set `level` to `DEBUG` or lower in `LoguruIntegration`. ### Ignoring a logger From 6fd804f89e039409551fa907bc75d3ade58f307b Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 15 May 2023 10:37:02 +0200 Subject: [PATCH 9/9] Resolved some confusion --- .../configuration/integrations/loguru.mdx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/loguru.mdx b/src/platforms/python/common/configuration/integrations/loguru.mdx index 0b283f04bb60e..41687b12eeeb5 100644 --- a/src/platforms/python/common/configuration/integrations/loguru.mdx +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -53,17 +53,29 @@ logger.exception("An exception happened") ### Ignoring a logger -Loggers can be noisy. You can ignore a logger by calling `ignore_logger`: +Loggers can be noisy. You can ignore a logger by calling `ignore_logger`. + +Since most of the logic is proxied to `logging` integration, we use it instead of the Loguru integration: ```python -# Since most of the logic is proxied to `logging` integration, we use it instead of the Loguru integration. +# Import form `logging` integration from sentry_sdk.integrations.logging import ignore_logger ignore_logger("a.spammy.logger") +``` -# and with Loguru (in `a.spammy.logger` module) +In `a.spammy.logger` module: + +```python from loguru import logger -logger.error("hi") # again, no record +logger.error("hi") # No error is sent to Sentry +``` + +This will work with `logging`'s logger too + +```python +logger = logging.getLogger("a.spammy.logger") +logger.error("hi") # Again, no error sent to Sentry ``` You can also use `before-send` and `before-breadcrumb` to ignore only certain messages. See Filtering Events for more information.