This guide explains how to monitor your DataBridge usage, track performance metrics, and set up observability for your applications.
OpenTelemetry Integration
DataBridge uses OpenTelemetry for comprehensive distributed tracing and metrics collection. This provides detailed insights into system performance and behavior.
Configuration
DataBridge automatically configures OpenTelemetry based on your environment:
from databridge import DataBridge# Development mode (writes to local files)db =DataBridge("your-uri", is_local=True)# Writes to:# - logs/telemetry/traces.log# - logs/telemetry/metrics.log# Production mode (uses OTLP exporters)db =DataBridge("your-uri")# Exports to configured OpenTelemetry collector
Resource Attributes
All telemetry data includes standard resource attributes:
service.name: "databridge-core"
Custom attributes for your application
Traces
Every operation in DataBridge is automatically traced, including:
Document ingestion
Semantic search queries
Completion requests
Authentication flows
Each trace includes:
Operation type
User ID
Duration
Status (success/error)
Custom metadata
Example of using traces:
from databridge import DataBridgedb =DataBridge("your-uri")# Traces are automatically collectedasyncwith db.track_operation("search", user_id="user123")as span:# Add custom attributes to the trace span.set_attribute("query_type", "semantic")# Perform operation results =await db.retrieve_chunks("query")# Record result metadata span.set_attribute("results_count", len(results))
# Token usage is automatically trackedresponse =await db.query("What are the insights?")print(f"Tokens used: {response.usage['total_tokens']}")# Get user-specific usage statisticsusage_stats = db.get_user_usage("user123")print(f"Total tokens: {usage_stats['total']}")
Local Development Mode
When running in local development mode (is_local=True), telemetry data is written to log files:
from databridge import DataBridge# Enable local development modedb =DataBridge("your-uri", is_local=True)# Telemetry data will be written to:# - logs/telemetry/traces.log: Detailed operation traces# - logs/telemetry/metrics.log: System metrics (exported every minute)
Local Trace Format
Traces are written as JSON objects with the following structure: