For a comprehensive reference of all available attributes and semantic conventions, see the Semantic Conventions guide.
Understanding Span Attributes
Span attributes provide contextual information for any span in your trace. They can be used to capture:- Trace-level context: Information that applies to the entire trace (set on the root span)
- Span-specific details: Information relevant to a particular operation or step
- Business logic metadata: Custom flags, parameters, or results specific to your application
Common Use Cases
- User and session information:
langwatch.user.id
,langwatch.thread.id
- Application context:
app.version
,environment
,region
- LLM operation details:
gen_ai.request.model
,gen_ai.request.temperature
,gen_ai.response.prompt_tokens
- Tool and API calls:
tool.name
,api.endpoint
,response.status
- RAG operations:
retrieved.document.ids
,chunk.count
- Custom business logic:
customer.tier
,feature.flags
,processing.stage
Setting Attributes
You can set attributes on any span using thesetAttributes()
method. This method accepts an object with key-value pairs.
Basic Attribute Setting
Setting Attributes on Child Spans
You can set attributes on any span in your trace hierarchy:Dynamic Attribute Updates
You can update attributes at any point during span execution:Using Semantic Conventions
LangWatch supports OpenTelemetry semantic conventions for consistent attribute naming. You can import semantic convention attributes for type-safe attribute setting:For a complete list of available semantic conventions and attributes, see the Semantic Conventions guide.
Advanced Attribute Patterns
Conditional Attributes
Set attributes based on your application logic:Structured Data Attributes
For complex data, you can serialize objects as JSON strings:LLM-Specific Attributes
For LLM operations, you can use GenAI semantic convention attributes:Best Practices
Attribute Naming
Follow consistent naming conventions for your attributes:Sensitive Data
Never include sensitive information in attributes:Performance Considerations
Limit the number and size of attributes for performance:When to Set Attributes
- At span creation: Set attributes that are known from the start
- During processing: Update attributes as you learn more about the operation
- At completion: Add final results, metrics, or status information
Viewing in LangWatch
All captured span attributes will be visible in the LangWatch UI:- Root span attributes are typically displayed in the trace details view, providing an overview of the entire operation
- Child span attributes are shown when you inspect individual spans within a trace
- Filter and search for traces and spans based on specific attribute values
- Analyze performance by correlating metrics with different attributes (e.g., comparing latencies for different
langwatch.user.id
s orgen_ai.request.model
s) - Debug issues by quickly understanding the context and parameters of a failed or slow operation