Our docs got a refresh! Check out the new content and improved navigation. For detailed API reference see our Python SDK docs and TypeScript SDK.
Description
Traces

Concepts

Understanding tracing and logging in Patronus AI

What are traces and logs?

Traces and logs help you understand what's happening in your LLM application, whether you're debugging during development or monitoring production traffic. They capture the execution flow and events in your application, making it easier to identify issues and optimize performance.

The Patronus SDK provides observability tools built on OpenTelemetry standards to track interactions and record important events.

Tracing

Tracing captures the execution flow of your LLM applications as a series of connected steps called "spans." Each span represents a unit of work, like an LLM call, a retrieval step, or a processing function. Spans can be nested to show parent-child relationships, giving you a complete picture of how your application executes.

When to use tracing

Tracing is most valuable when you have multi-step workflows where understanding the sequence and relationships between steps matters:

  • Multi-step agent workflows
  • RAG pipelines with retrieval and generation steps
  • Complex chains of LLM calls
  • Any workflow where you need to see how steps connect and depend on each other

How tracing works

The Patronus SDK provides two ways to add tracing to your code:

Decorator approach: Use @traced() to automatically trace entire functions. This is the simplest way to add tracing.

Context manager approach: Use start_span() to trace specific code blocks when you need more granular control over what gets traced.

Spans automatically capture timing information, inputs, outputs, and any metadata you want to include. All traces are automatically sent to the Patronus platform where you can view and analyze them.

Logging

Logging records discrete events and information from your application. Unlike tracing, which focuses on workflow structure, logging captures specific moments and details that help you understand what happened during execution.

When to use logging

Use logging to record important events and context:

  • Application events and debug information
  • Prompts and responses
  • Configuration details and version information
  • Custom metadata within a trace

Patronus integrates with Python's standard logging module, so you can use familiar logging patterns while automatically sending logs to the Patronus platform.

Tracing vs logging

Both tools serve different purposes and work well together:

Use tracing when you need to understand workflow structure, timing, and relationships between steps. Tracing answers "how did my application execute?"

Use logging when you need to record specific events, values, or debug information. Logging answers "what happened at this point?"

In practice, you'll often use both together - tracing to structure your workflow and logging to capture important details within those traces.

Next steps

On this page