The Atatus Python APM agent makes it easy to monitor and troubleshoot custom Python applications.
By manually instrumenting your code, you can:
  • Track performance metrics for your scripts and background tasks
  • Create and manage transactions for key workflows
  • Enable distributed tracing across services
  • Capture custom spans for fine-grained visibility

Creating New Transactions

atatus.capture_span works only when there’s an active transaction.
If your application is not running inside a supported framework (like Django or Flask), you’ll need to:
  1. Create a Client instance
  2. Begin and end transactions manually
You can still leverage automatic instrumentation for supported libraries by calling atatus.instrument(). A transaction can represent any logical operation like the entire script execution or a specific code block.

Example:

  • Call atatus.instrument() only once, as early as possible.
  • Treat the Client object as a singleton, so create one instance and reuse it.

Distributed Tracing

When instrumenting custom Python code across multiple services, ensure the TraceParent is propagated so Atatus can link transactions into a single distributed trace. It also provides utilities to work with TraceParent in string or header dictionary formats for manual propagation.

Example:

Creating Additional Spans in a Transaction

While Atatus automatically instruments many libraries, you may want to measure the execution time or frequency of specific functions. For this, use the @atatus.capture_span() decorator or @atatus.async_capture_span() for async code.
capture_span requires an active transaction. If you’re not using a supported framework, create a Client and manually manage transactions. See Creating New Transactions for details.

Synchronous Example

Asynchronous Example

Async span instrumentation requires Python 3.7+.