Spans
Building Blocks of Traces in Galileo
Spans in Galileo are the fundamental building blocks of traces, representing discrete operations or units of work within your AI application. A span captures a single step in your application’s workflow, such as an LLM call, a document retrieval operation, a tool execution, or any other distinct process.
Each span records detailed information about a specific operation, including its inputs, outputs, duration, and any relevant metadata. Spans are organized hierarchically within traces, allowing you to understand both individual operations and their relationships to each other.
The Role of Spans in Representing Units of Work
Spans serve several critical roles in the Galileo platform:
-
Granular Representation: Spans break down complex workflows into discrete, manageable units, making it easier to understand and analyze each step.
-
Contextual Information: Each span contains rich contextual information about the operation it represents, including inputs, outputs, and configuration details.
-
Hierarchical Organization: Spans can be nested within other spans, creating a hierarchical structure that reflects the organization of your application’s workflows.
-
Performance Tracking: Spans capture timing information, allowing you to identify bottlenecks and optimize performance.
-
Error Isolation: When issues occur, spans help isolate the specific operation where the error originated.
How Spans Contribute to System Evaluation and Debugging
Spans are essential for detailed system evaluation and debugging for several reasons:
-
Pinpoint Precision: Spans allow you to pinpoint exactly where in a workflow issues are occurring, rather than just knowing that something went wrong.
-
Input-Output Analysis: By examining the inputs and outputs of each span, you can identify where unexpected results are being generated.
-
Performance Profiling: Span durations help you identify which operations are taking the most time, guiding optimization efforts.
-
Error Context: When errors occur, spans provide the context needed to understand what led to the error and how to fix it.
-
Quality Assessment: Spans enable evaluation of individual components of your system, helping you identify which parts are performing well and which need improvement.
Key Components of a Span
A span in Galileo consists of several core components:
Essential Components
- Input: The data or query provided to the operation
- Output: The response or result generated by the operation
- Span Type: The type of operation (e.g., llm, workflow, retriever, tool)
- Duration: The time taken to complete the operation
- Timestamp: When the operation occurred
- Parent Span: The span that contains this span (if applicable)
- Child Spans: Spans contained within this span (if applicable)
Span Types and Their Behavior
Galileo supports several types of spans, each designed to capture different kinds of operations:
-
LLM Spans: Capture interactions with language models, including:
- Prompts sent to the model
- Responses received from the model
- Model configuration (e.g., model name, temperature)
- Token usage and other performance metrics
-
Workflow Spans: Represent logical groupings of operations that can contain child spans, useful for:
- Organizing complex processes
- Creating hierarchical structures
- Grouping related operations
-
Retriever Spans: Record document retrieval operations, including:
- Search queries
- Retrieved documents
- Relevance scores
- Retrieval configuration
-
Tool Spans: Document tool calls in agent-based systems, including:
- Tool inputs
- Tool outputs
- Error information (if applicable)
- Tool configuration
Each span type has specific fields and behaviors tailored to the operation it represents, allowing for more detailed and relevant information capture.
The Role of Metadata in Spans
Metadata enhances the traceability and utility of spans in several ways:
-
Contextual Information: Metadata provides additional context about the operation, such as user IDs, session information, or application-specific data.
-
Filtering and Searching: Metadata can be used to filter and search for specific spans, making it easier to find relevant information.
-
Correlation: Metadata helps correlate spans across different traces or systems, enabling end-to-end visibility.
-
Custom Attributes: You can add custom attributes to metadata to capture information specific to your application or use case.
-
Debugging Context: In debugging scenarios, metadata can provide crucial context about the state of your application when the operation occurred.
Creating and Managing Spans
Galileo provides several methods for creating and managing spans, each offering different levels of control and convenience.
Using the Galileo SDK
Using Integration Wrappers
Required Inputs and Configurations
When creating spans, you need to provide:
- Input: The data being processed by the operation
- Output (for concluded spans): The result of the operation
- Span Type: The type of operation (llm, workflow, retriever, or tool)
- Name (for workflow and tool spans): A descriptive name for the operation
Additional optional configurations include:
- Metadata: Additional contextual information
- Tags: Labels for categorization
- Parent Span: The span that contains this span (if applicable)
- Model Configuration (for LLM spans): Details about the model used
Customization Options
Spans can be customized in several ways:
- Custom Metadata: Add application-specific metadata to provide additional context
- Custom Tags: Add tags to categorize spans and make them easier to filter
- Nested Spans: Create hierarchical structures by nesting spans within other spans
- Error Handling: Capture and log errors for better debugging
- Custom Span Types: Define custom span types for application-specific operations
Using Spans in Practice
Common Use Cases
Spans in Galileo are valuable for a wide range of use cases:
-
LLM Interaction Tracking: Capture details of interactions with language models, including prompts, responses, and model configurations.
-
RAG Pipeline Analysis: Track each step in a retrieval-augmented generation pipeline, from document retrieval to LLM generation.
-
Agent Workflow Monitoring: Monitor the actions of AI agents, including tool calls and decision-making processes.
-
Performance Profiling: Identify bottlenecks and optimization opportunities by analyzing span durations.
-
Error Diagnosis: When issues occur, examine spans to understand what went wrong and why.
-
Quality Assessment: Evaluate the quality of individual components in your AI system.
Representing Different Parts of a Workflow
Spans can represent various parts of a workflow:
- LLM Spans: Represent interactions with language models
- Retriever Spans: Represent document retrieval operations
- Tool Spans: Represent tool calls or external API interactions
- Workflow Spans: Represent logical groupings of operations or multi-step processes
By combining these span types, you can create a complete representation of your application’s workflows, from simple LLM calls to complex multi-step processes.
Best Practices
When working with spans, follow these best practices:
-
Meaningful Names: Use descriptive names for spans to make them easier to understand and analyze.
-
Appropriate Granularity: Create spans at an appropriate level of granularity - too fine-grained and you’ll have too many spans to manage, too coarse-grained and you’ll miss important details.
-
Include Relevant Metadata: Add metadata that will be useful for filtering, analysis, and debugging.
-
Proper Hierarchy: Organize spans in a logical hierarchy that reflects the structure of your application’s workflows.
-
Error Handling: Log errors in spans to help with debugging and analysis.
-
Complete Spans: Always conclude spans to ensure they have both input and output information.
-
Consistent Naming: Use consistent naming conventions for similar spans across your application.
Integration with the Galileo Ecosystem
Integration with Other Components
Spans integrate seamlessly with other Galileo components:
-
Logs: Spans contain log data, providing structure and context for individual log entries.
-
Traces: Spans are organized into traces, which represent complete interactions or workflows.
-
Metrics: Span data feeds into metrics, allowing you to measure and monitor key aspects of your AI application.
-
Experiments: Spans can be used in experiments to compare different models, prompts, or configurations.
-
Datasets: Spans can be converted into datasets for fine-tuning or evaluation.
-
Alerts: Patterns in spans can trigger alerts to notify you of issues or anomalies.
Data Flow
The typical data flow for spans in Galileo is:
- Your application creates spans using the Galileo SDK
- Spans are organized into traces
- Traces are flushed to Galileo (automatically or manually)
- Galileo processes and stores the spans
- Spans are available for viewing, analysis, and use in other Galileo features
- Metrics and evaluations are computed based on span data
- Insights derived from spans inform improvements to your AI application
Dependencies and Connections
Spans have dependencies on several Galileo components:
- Traces: All spans belong to a trace
- Projects: All spans belong to a project (via their trace)
- Log Streams: Spans are organized into log streams (via their trace)
- API Keys: Authentication is required to send spans to Galileo
- SDK: The Galileo SDK is used to create and send spans
Examples and Practical Applications
Basic Span Creation
Spans with Detailed Metadata
Multi-Span RAG Example
Next Steps
After understanding spans, you can explore these related Galileo features:
Advanced Span Analysis
- Span Visualization: Use the Galileo UI to visualize spans and understand the flow of data through your application.
- Performance Analysis: Analyze span timing information to identify bottlenecks and opportunities for improvement.
- Error Analysis: Use spans to understand the root causes of errors and exceptions.
Related Galileo Workflows
- Trace Analysis: Examine how spans are organized into traces to understand complete workflows.
- Metrics: Set up metrics based on span data to monitor key aspects of your AI application.
- Experiments: Use spans to compare different models, prompts, or configurations.
- Datasets: Convert spans into datasets for fine-tuning or evaluation.
- Alerts: Configure alerts based on patterns in your spans.
Further Resources
- Traces - Understand how spans are organized into traces
- Log Streams - Explore how to organize spans and traces into streams
- Projects - Learn about the top-level organization of Galileo resources
- Metrics - Discover how to measure key aspects of your AI application
- Experiments - Learn how to compare different approaches