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 new file mode 100644 index 0000000000000..41687b12eeeb5 --- /dev/null +++ b/src/platforms/python/common/configuration/integrations/loguru.mdx @@ -0,0 +1,122 @@ +--- +title: 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. + +The [`logging`](/platforms/python/guides/logging) integration provides most of the Loguru functionality and most examples on that page work with Loguru. + +## Install + +Install `sentry-sdk` from PyPI with the Loguru extra. + +```bash +pip install --upgrade 'sentry-sdk[loguru]' +``` + +## Configure + +Add `LoguruIntegration()` to your integrations list: + +```python +import sentry_sdk +from sentry_sdk.integrations.loguru import LoguruIntegration + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + integrations=[ + LoguruIntegration(), + ], +) +``` + +## Behavior + +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 + +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") +``` + +- 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 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 + +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 +# Import form `logging` integration +from sentry_sdk.integrations.logging import ignore_logger + +ignore_logger("a.spammy.logger") +``` + +In `a.spammy.logger` module: + +```python +from loguru import logger +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. + +## Options + +You can pass the following keyword arguments to `LoguruIntegration()`: + +```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, + ], +) +``` + +- `level` + + 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` + +- `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 + +- 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/ ---