Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/platforms/python/integrations/logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ sentry_sdk.init(
logging.info("I will be sent to Sentry logs")
```

### Working with Extra Fields

When sending log records as Sentry logs, any fields provided in the `extra` dictionary are automatically promoted to top-level attributes on the log entry. This makes them searchable and filterable in the Sentry UI.

```python
import logging
import sentry_sdk

sentry_sdk.init(
# ...
enable_logs=True,
)

logger = logging.getLogger(__name__)

# Extra fields become top-level searchable attributes
logger.error(
"Payment processing failed",
extra={
"user_id": 12345,
"transaction_id": "txn_abc123",
"payment_method": "credit_card",
"amount": 99.99
}
)
```

In this example, `user_id`, `transaction_id`, `payment_method`, and `amount` will appear as separate, searchable attributes in the Sentry logs interface, not nested within an `extra` object. You can filter and query logs using these attributes directly, such as `user_id:12345` or `payment_method:credit_card`.

## Options

To change the default behavior of the logging integration, instantiate the integration manually and pass it to Sentry's `init` function:
Expand Down
30 changes: 30 additions & 0 deletions platform-includes/logs/integrations/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ my_logger.info('But info events will be sent to Sentry logs. my_value=%s', my_va

By default, the logging integration sends `INFO`-level logs and higher to Sentry logs. You can set a different threshold via the `LoggingIntegration`'s `sentry_logs_level` parameter. However, regardless of the `sentry_logs_level` setting, the SDK only sends logs if they are at or above the logger's level.

#### Extra Fields as Searchable Attributes

When using the standard library logging with Sentry logs, any fields provided in the `extra` dictionary are automatically promoted to top-level attributes on the log entry, making them searchable and filterable in the Sentry UI.

```python
import sentry_sdk
import logging

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
enable_logs=True,
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Extra fields become searchable attributes
logger.info(
"User action completed",
extra={
"user_id": 12345,
"action": "purchase",
"item_count": 3,
"total_amount": 29.97
}
)
```

In this example, `user_id`, `action`, `item_count`, and `total_amount` will appear as separate, searchable attributes in the Sentry logs interface. You can filter logs using these attributes directly, such as `user_id:12345` or `action:purchase`.

```python
import sentry_sdk
import logging
Expand Down