Skip to main content

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

Metadata is a JSON object with string keys and arbitrary values (strings, numbers, booleans, nested objects, arrays).Example metadata:
Key properties:
  • 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
Avoid overwriting the same top-level key multiple times within a single trace. Metadata updates merge based on top-level keys, and rewriting a key produces undefined behavior. Add keys incrementally instead.

Add Metadata to Traces

Attach metadata when creating traces or update it dynamically as your code executes.Python (decorator pattern):
Python (manual span creation):
JavaScript/TypeScript:

Update Metadata Incrementally

Metadata updates merge based on top-level keys. You can add new keys throughout the trace lifecycle without overwriting existing data.Example: Incremental updates
Do not write the same top-level key multiple times:
Instead, use different keys or nested objects:

Query Traces by Metadata

In the ABV Dashboard, filter traces using SQL-like queries on metadata fields.Query examples:
  • metadata.tenant_id = "acme-corp" → All traces for tenant “acme-corp”
  • metadata.feature = "summarization" → All traces for the summarization feature
  • metadata.version = "v2.3" AND environment = "production" → Traces for specific version in production
  • metadata.user_tier = "enterprise" → Traces for enterprise users only
  • metadata.model_config.temperature > 0.5 → Traces with high temperature settings
Dashboard workflow:
  1. Navigate to the Traces view
  2. Click “Add Filter”
  3. Select “Metadata” and enter your query
  4. Results update instantly
Export filtered traces:
  • Export to CSV for analysis
  • Create datasets for evaluations
  • Generate reports for stakeholders

Aggregate Metrics by Metadata

Use metadata dimensions to aggregate costs, latency, and quality metrics for business analysis.Example analyses:
  • Cost by tenant: Group traces by metadata.tenant_id to calculate per-tenant LLM costs
  • Latency by feature: Filter by metadata.feature to identify slow features
  • Quality by experiment: Compare metadata.experiment_version to measure A/B test results
  • Error rate by region: Analyze metadata.region to detect regional issues
Dashboard aggregations:
  • 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?

Attach tenant_id to isolate costs, performance, and errors by customer.
Filter by metadata.tenant_id to calculate per-tenant costs or detect tenant-specific errors.
Tag experiment variants to compare costs, latency, and quality.
Compare metrics by variant to make data-driven rollout decisions.
Attach deployment version to correlate issues with releases.
Filter by version to compare error rates and identify regressions.
Track model configurations to compare cost, quality, and latency.
Filter by metadata.model_provider to quantify tradeoffs and optimize selection.
Segment traces by user attributes to analyze costs by cohort.
Group by tier or region to optimize model selection and justify pricing.
Categorize errors for faster debugging.
Filter by metadata.error_type to identify patterns and set alerts.

Implementation Guide

Use the @observe() decorator to automatically trace functions. Update metadata with abv.update_current_trace() and abv.update_current_span().Setup:
Basic usage:
Incremental updates:
Create spans manually and attach metadata at the trace or span level.Trace-level metadata:
Span-level metadata:
Use the @abvdev/tracing package to add metadata to traces and observations.Setup:
Configuration (instrumentation.ts):
Add metadata:
Wrap existing functions with automatic tracing and metadata updates.Example:
Create spans manually with metadata attached.Example:

Related Features

Tags

Add simple string labels to traces for quick categorization and filtering

Sessions

Group related traces by user journey or job to see end-to-end workflows

Environments

Separate development, staging, and production traces for clean comparisons

User Tracking

Link traces to user accounts for faster debugging and GDPR-compliant handling