Overview
The Vals SDK includes a tracing feature for monitoring and debugging operations in your applications, such as LLM calls, tool executions, and logic flows. It integrates with OpenTelemetry to export traces to the Vals platform, providing visibility into your code’s execution.Introduction and Setup
Tracing allows you to track the flow of operations, capture inputs/outputs, and monitor performance. To get started, initialize a trace client with a name for your application or module:"default-project" project. To send traces to a different project, pass the project_slug parameter:
Basic Tracing with Decorators
The simplest way to add tracing is using the@trace.span decorator, which automatically captures function arguments as input and return values as output.
You can optionally provide a custom name for the span:
Asynchronous Functions
Manual Span Control
For more control, use context managers to create spans manually. This is useful for wrapping specific code blocks or operations.Span Types and Hierarchy
Spans have types to categorize operations:- LOGIC (default): For general logic, data processing, or workflows.
- LLM: For language model interactions, with special attributes like model, usage, and reasoning.
- TOOL: For external tools or API calls.
Usage Tracking
When usingSpanType.LLM, you can track token usage with the usage parameter, which accepts a Usage TypedDict with the following fields:
in_tokens: Number of input tokensout_tokens: Number of output tokensreasoning_tokens: Number of reasoning tokens (for models that support it)