How Metadata Works
Metadata is arbitrary structured JSON data attached to traces or observations. Unlike tags (simple string labels), metadata is key-value data that enables precise filtering and rich analysis.Understand Metadata Structure
- Top-level keys: Identify dimensions (tenant, feature, version, etc.)
- Nested objects: Group related data (model config, user details)
- Merged on update: Adding new keys preserves existing metadata
- Queryable: Filter traces using SQL-like queries on metadata fields
Add Metadata to Traces
Update Metadata Incrementally
Query Traces by Metadata
metadata.tenant_id = "acme-corp"→ All traces for tenant “acme-corp”metadata.feature = "summarization"→ All traces for the summarization featuremetadata.version = "v2.3" AND environment = "production"→ Traces for specific version in productionmetadata.user_tier = "enterprise"→ Traces for enterprise users onlymetadata.model_config.temperature > 0.5→ Traces with high temperature settings
- Navigate to the Traces view
- Click “Add Filter”
- Select “Metadata” and enter your query
- Results update instantly
- Export to CSV for analysis
- Create datasets for evaluations
- Generate reports for stakeholders
Aggregate Metrics by Metadata
- Cost by tenant: Group traces by
metadata.tenant_idto calculate per-tenant LLM costs - Latency by feature: Filter by
metadata.featureto identify slow features - Quality by experiment: Compare
metadata.experiment_versionto measure A/B test results - Error rate by region: Analyze
metadata.regionto detect regional issues
- Navigate to Metrics → Custom Dashboards
- Create charts grouped by metadata fields
- Track trends over time for specific dimensions
- Set alerts based on metadata filters (e.g., “alert when enterprise tier costs exceed threshold”)
Why Use Metadata?
Multi-Tenant Applications: Track Costs and Performance Per Customer
Multi-Tenant Applications: Track Costs and Performance Per Customer
tenant_id to isolate costs, performance, and errors by customer.metadata.tenant_id to calculate per-tenant costs or detect tenant-specific errors.Feature Flagging: Measure Impact of New Features
Feature Flagging: Measure Impact of New Features
Deployment Tracking: Correlate Issues with Code Versions
Deployment Tracking: Correlate Issues with Code Versions
Model and Prompt Versioning: Compare Configurations
Model and Prompt Versioning: Compare Configurations
metadata.model_provider to quantify tradeoffs and optimize selection.User Segmentation: Analyze by Subscription Tier or Region
User Segmentation: Analyze by Subscription Tier or Region
Error Tracking: Categorize and Debug Failures
Error Tracking: Categorize and Debug Failures
metadata.error_type to identify patterns and set alerts.Implementation Guide
Python: Using the @observe() Decorator
Python: Using the @observe() Decorator
@observe() decorator to automatically trace functions. Update metadata with abv.update_current_trace() and abv.update_current_span().Setup:Python: Manual Span Creation
Python: Manual Span Creation
JavaScript/TypeScript: Context Managers
JavaScript/TypeScript: Context Managers
@abvdev/tracing package to add metadata to traces and observations.Setup:JavaScript/TypeScript: observe Wrapper
JavaScript/TypeScript: observe Wrapper
JavaScript/TypeScript: Manual Span Creation
JavaScript/TypeScript: Manual Span Creation