Skip to main content

How Trace IDs Work in ABV

ABV uses the W3C Trace Context standard for trace IDs:
  • Trace IDs: 32-character lowercase hexadecimal strings (e.g., abcdef1234567890abcdef1234567890)
  • Span IDs (observation IDs): 16-character lowercase hexadecimal strings (e.g., fedcba0987654321)

Understand Default Behavior

By default, ABV generates random trace IDs and span IDs for every trace. This works fine for basic observability, but limits advanced use cases:
  • Distributed tracing: Can’t correlate events across multiple services
  • External system integration: Can’t map ABV traces to your support tickets, orders, or sessions
  • Programmatic access: Can’t fetch specific traces via API using your own IDs
Default ID format:
  • Trace ID: Random 32-character hex string (W3C Trace Context compliant)
  • Span ID: Random 16-character hex string
For advanced workflows, bring your own trace IDs.

Generate Deterministic Trace IDs from External IDs

ABV provides utilities to generate W3C-compliant trace IDs from any seed string. This creates deterministic, reproducible IDs from your external identifiers.Why deterministic IDs?
  • Same input always produces the same trace ID
  • Correlate ABV traces with support tickets, order IDs, session tokens
  • Re-generate the same trace ID later for scoring or retrieval
Python:
JavaScript/TypeScript:
Now you can regenerate this trace ID anytime using the same external ID.

Use Custom Trace IDs in Your Code

Once you have a trace ID, pass it to ABV when creating traces or spans. This ensures all events use your custom ID instead of a random one.Python (decorator pattern):
Python (manual span creation):
JavaScript/TypeScript:
Note: When setting a custom trace ID in JS/TS, you must provide a parentSpanContext with an arbitrary spanId. This detaches the span from the active context.

Propagate Trace IDs Across Services

For distributed tracing, propagate the trace ID from the entry point through all downstream services via HTTP headers, message queues, or RPC metadata.HTTP headers (W3C Trace Context standard):
Python example (service A → service B):
Service B: Extract and use trace ID:
Now both services log events under the same trace ID. In the ABV Dashboard, you see a unified timeline across services.

Access Trace IDs Programmatically

Retrieve the current trace ID at runtime for logging, debugging, or passing to external systems.Python:
JavaScript/TypeScript:
Store these IDs in your logs or databases to link back to ABV traces later.

Why Use Custom Trace IDs?

Modern applications span multiple services: API gateways, authentication services, LLM backends, RAG retrievers, databases, caching layers. When a user request fails, you need to see the full journey—not just isolated logs from each service.The problem: Without shared trace IDs, each service logs events independently. You have:
  • API gateway logs: “Request received at 10:45:12”
  • Auth service logs: “User validated at 10:45:13”
  • LLM backend logs: “LLM call failed at 10:45:15”
  • No connection between these events
The solution with custom trace IDs:
  1. API gateway generates a trace ID when the request arrives
  2. Passes trace ID to auth service via HTTP header (traceparent)
  3. Auth service extracts trace ID and uses it for its logs
  4. Auth service forwards trace ID to LLM backend
  5. LLM backend logs events with the same trace ID
  6. ABV groups all events into one trace
In the dashboard: Search for the trace ID and see the complete timeline:
How trace IDs propagate across services:Implementation:
Benefits:
  • Root cause analysis: See exactly where requests fail in multi-service workflows
  • Performance optimization: Identify slow services in the critical path
  • Debugging: Trace request flow end-to-end with one query
Your support dashboard, admin panel, or internal tools display user sessions, orders, or tickets. When investigating issues, you want to jump directly to the corresponding ABV trace without searching manually.The problem: ABV assigns random trace IDs (e.g., f3a2b1c9-4567-8901-2345-6789abcdef01). Your support ticket has ID ticket-12345. No connection between them.The solution with deterministic trace IDs: Generate ABV trace IDs from your external IDs:
In your support dashboard:
Benefits:
  • Instant navigation from your tools to ABV traces
  • No manual searching or copy-pasting trace IDs
  • Better support workflows: “View this user’s LLM traces” → one click
You’re running A/B tests, experiments, or benchmarks. Each experiment has an ID (e.g., experiment-2025-01-v2). You need to fetch all traces from that experiment and score them programmatically.The problem: ABV’s random trace IDs don’t map to your experiment IDs. You can add metadata (metadata.experiment_id = "experiment-2025-01-v2"), but fetching and scoring requires API queries.The solution with deterministic trace IDs: Generate trace IDs that include your experiment ID:
Later, score all traces from experiment:
Benefits:
  • Programmatic access to specific traces using your IDs
  • Batch scoring for experiments without complex queries
  • Reproducible evaluations (same seed = same trace ID every time)
You want to fetch ABV traces programmatically via API, but you only know your external IDs (session tokens, order IDs, user IDs). ABV’s random trace IDs force you to query by metadata, which is slower and more complex.The solution with deterministic trace IDs: Generate ABV trace IDs from your external IDs, then fetch directly by trace ID (fast, precise).Example: Fetch trace for a specific order
Benefits:
  • Direct trace retrieval by ID (no complex metadata queries)
  • Faster API responses (indexed by trace ID)
  • Simpler code—no need to parse query results
ABV’s trace IDs follow the W3C Trace Context standard, making them compatible with OpenTelemetry and other observability tools. If you’re already using OpenTelemetry, ABV integrates seamlessly.W3C Trace Context format:
  • 00: Version (fixed)
  • <trace-id>: 32-character hex string
  • <parent-span-id>: 16-character hex string
  • <trace-flags>: 01 (sampled) or 00 (not sampled)
OpenTelemetry integration (Python):
Benefits:
  • Use the same trace IDs across ABV and other observability tools (Datadog, Honeycomb, Jaeger)
  • Vendor-neutral: Switch tools without changing instrumentation
  • Standards-based: Follow W3C best practices for distributed tracing

Implementation Guide

Use the @observe() decorator to automatically trace functions. Pass custom trace IDs via the special abv_trace_id keyword argument.Setup:
Basic usage:
Key points:
  • abv_trace_id is a special keyword argument recognized by @observe()
  • Trace ID must be a 32-character lowercase hexadecimal string
  • Use abv.create_trace_id(seed="...") to generate W3C-compliant IDs from any string
For more control, create spans manually with custom trace contexts.Create span with custom trace ID:
Access current trace ID:
Use the @abvdev/tracing package to create spans with custom trace IDs.Setup:
Configuration (instrumentation.ts):
Create span with custom trace ID:
Important:
  • parentSpanContext.spanId must be a valid 16-character hex string
  • The parent span doesn’t actually exist—it’s only used for trace ID inheritance
  • Setting parentSpanContext detaches the span from the active context
Retrieve the active trace ID at runtime.Example:
Use cases:
  • Log trace ID to external systems (Datadog, Splunk)
  • Include trace ID in API responses for debugging
  • Pass trace ID to downstream services via HTTP headers
For microservices architectures, propagate trace IDs using HTTP headers following the W3C Trace Context standard.Service A (Python): Send request with trace ID
Service B (Python): Extract and use trace ID
Service A (TypeScript): Send request with trace ID
Service B (TypeScript): Extract and use trace ID
Result: In the ABV Dashboard, search for the trace ID and see events from both services grouped together in one timeline.
If you’re using OpenTelemetry directly (without ABV SDKs), trace IDs are managed by the OpenTelemetry SDK. ABV automatically ingests OpenTelemetry spans with their trace IDs.Access trace ID in OpenTelemetry (Python):
Access trace ID in OpenTelemetry (JavaScript/TypeScript):
ABV integration:
  • ABV’s span processors automatically extract trace IDs from OpenTelemetry spans
  • No code changes needed—just configure ABVSpanProcessor
  • Trace IDs in ABV Dashboard match OpenTelemetry trace IDs exactly

Next Steps

Trace URLs

Share deep links to traces for reproducible bug reports, customer support, and code reviews

Sessions

Group related traces by user journey or job to see end-to-end behavior across multiple LLM calls

Metadata

Attach structured context to traces for precise filtering, analysis, and correlation with business data

OpenTelemetry Integration

Learn more about OpenTelemetry-based SDKs and advanced instrumentation patterns