Skip to main content
Sentry Logs lets you capture structured log messages from your application and view them in the context of the errors and traces they relate to. Instead of switching between your error tracker and a separate log aggregator, you can see the log output that led to an error directly in the Sentry UI.

Emitting logs via the SDK

The Sentry SDK provides a logging API that mirrors standard log levels. Enable log capture by setting enable_logs=True in your SDK configuration:
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration

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

# Use the Sentry logger directly
logger = sentry_sdk.get_logger()
logger.info("User logged in", user_id=user.id)
logger.warning("Slow query detected", duration_ms=850, query=sql)
logger.error("Payment failed", order_id=order.id, reason=str(e))

Log levels

Sentry recognizes the following log levels, from lowest to highest severity:
LevelDescription
traceVery detailed diagnostic information
debugDiagnostic information useful during development
infoConfirmation that things are working as expected
warningSomething unexpected happened but the operation succeeded
errorAn error occurred that prevented an operation from completing
fatalA critical failure that may cause the application to crash

Filtering logs

In the Logs section of Sentry you can:
  • Filter by log level (for example, show only error and above)
  • Search by message text or any structured attribute
  • Filter by project, environment, and time range
  • See the trace context associated with each log entry

Correlating logs with traces and errors

When a log message is emitted inside an active trace, Sentry automatically attaches the current trace_id, span_id, and transaction name to the log entry. This means:
  • From a trace or span, you can see all log messages emitted during that operation.
  • From a log entry, you can jump directly to the associated trace to see the full request context.
  • From an error issue, the breadcrumbs panel shows log messages that occurred in the same session or trace before the error.
Use structured attributes (key-value pairs) rather than interpolating variables into log message strings. Structured attributes are indexed and can be filtered in the Logs UI, while free-form text in the message body is only searchable via full-text search.
Sentry Logs is distinct from the breadcrumbs feature. Breadcrumbs are captured automatically by SDK integrations and shown on the issue detail page. Logs are explicit API calls that produce standalone log entries stored and queryable in the Logs section.

Build docs developers (and LLMs) love