Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the sentry_sdk.logger APIs.
The logger namespace exposes six methods that you can use to log messages at different log levels: trace, debug, info, warning, error, and fatal.
You can send structured messages by using the {attribute_name} placeholder syntax. The properties of this message will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.
import sentry_sdk
sentry_sdk.init(...)
sentry_sdk.logger.trace('Starting database connection {database}', database="users")
sentry_sdk.logger.debug('Cache miss for user {user_id}', user_id=123)
sentry_sdk.logger.info('Updated global cache')
sentry_sdk.logger.warning('Rate limit reached for endpoint {endpoint}', endpoint='/api/results/')
sentry_sdk.logger.error('Failed to process payment. Order: {order_id}. Amount: {amount}', order_id="or_2342", amount=99.99)
sentry_sdk.logger.fatal('Database {database} connection pool exhausted', database="users")You can also pass additional attributes directly to the logging functions via the attributes kwarg.
sentry_sdk.logger.error(
'Payment processing failed',
attributes={
'payment.provider': 'stripe',
'payment.method': 'credit_card',
'payment.currency': 'USD',
'user.subscription_tier': 'premium'
}
)Attribute values should be primitives — strings, numbers, or booleans. Sentry's log storage only retains these scalar types, so other values are handled inconsistently. A list or tuple of same-typed scalars (for example [1, 2, 3]) is sent as an array, which is not currently stored and shows up empty in the Logs UI. Mixed lists and dicts are stored as their string representation. To keep a complex value searchable, serialize it to a string before logging, for example json.dumps(workflow_ids).