Skip to main content

Installation

Install the Heimdall Python SDK from PyPI:

Basic Usage

Initialize the Client

You can also configure the client using environment variables and initialize without arguments:

Trace MCP Tools

Use the @trace_mcp_tool() decorator to automatically trace your MCP tool functions:
The decorator automatically captures:
  • Function name as the span name
  • All parameters with their names ({"query": "machine learning", "limit": 5})
  • Return value
  • Execution duration
  • Any exceptions that occur

Custom Span Names

Override the default function name with a custom span name:

Flush Traces

Always flush traces before your application exits:

General Tracing with observe

For non-MCP functions or when you need more control, use the observe decorator:

Async Support

Both decorators work with async functions:

Error Handling

Errors are automatically captured and the span is marked as failed:

Complete Example

Here’s a complete example of an MCP server instrumented with Heimdall:

Next Steps

Environment Variables

Configure Heimdall using environment variables.

SDK Options

Explore all available configuration options.