Tracing
Capture and analyze MCP calls with tracing functionality
Tracing
The HUD SDK provides tracing functionality to capture and analyze MCP (Model-Client-Provider) calls during agent execution. This is particularly useful for debugging, performance analysis, and understanding the interaction between your agent and external services.
Overview
Tracing in HUD allows you to:
- Capture all MCP calls made by an agent within a specific code block or decorated function.
- Automatically upload these traces to the HUD platform (app.hud.so) for detailed analysis.
- View comprehensive information about each call, including request/response payloads, timing, status, and any errors.
- Associate traces with specific task runs, jobs, and custom attributes for better organization and filtering.
This capability is essential whether your agent is interacting with HUD environments (like hud-browser
) or using its own set of MCP-based tools independently.
Using Tracing
There are two main ways to use tracing in your code:
1. Context Manager: hud.trace()
Use the trace()
context manager to wrap a block of code where you want to capture MCP calls:
Parameters:
name
(str, optional): A name for this trace, useful for identificationattributes
(dict, optional): Additional metadata to associate with the trace
2. Decorator: @hud.register_trace
Use the @register_trace
decorator to automatically trace an entire function:
Parameters:
name
(str, optional): A name for this trace, defaults to the function nameattributes
(dict, optional): Additional metadata to associate with the trace
Viewing Traces
After a trace is captured, it’s automatically uploaded to the HUD platform. You’ll see a log message with a URL where you can view the trace:
The trace view shows:
- Timeline of all MCP calls
- Request and response payloads
- Timing information
- Error details (if any)
Best Practices
- Use descriptive names: Choose meaningful names for your traces to make them easier to identify
- Add relevant attributes: Include metadata that will help you filter and analyze traces later
- Limit trace scope: Trace specific sections of code rather than entire applications to keep traces focused
- Clean up resources: Traces are automatically uploaded when the context manager exits or the decorated function completes
Limitations
- Tracing only captures MCP calls, not other types of API calls or internal function calls
- Large traces with many calls may take longer to upload and display
- Trace data is temporarily stored in memory before being uploaded
Related Concepts
- Job: Jobs can contain multiple traces
- Environment: Environments can be associated with traces
- Task: Tasks can be traced to analyze performance