camel-otel
OpenTelemetry integration for rust-camel.
Overview
Implements Lifecycle and MetricsCollector traits to export traces, metrics, and logs to any OTLP-compatible backend (e.g., Grafana LGTM, Jaeger, Tempo, Prometheus via OTLP).
OtelService initializes the global TracerProvider, MeterProvider, and LoggerProvider on start and shuts them down gracefully on stop. W3C traceparent / tracestate headers are propagated automatically in HTTP and Kafka components via optional feature flags.
Features:
- Traces: Distributed tracing via OTLP span exporter
- Metrics: Route-level metrics (duration, exchanges, errors) automatically recorded
- Logs: Log bridge exports
tracinglogs via OTLP - Auto-registration:
OtelService.as_metrics_collector()enables automatic metrics collection
Quick Start
use ;
use CamelContext;
// OTel providers start/stop automatically with context
let ctx = new
.with_lifecycle;
ctx.start.await?;
// Traces, metrics, and logs exported to OTLP backend
ctx.stop.await?;
// All providers flushed and shut down
Default Configuration
use OtelService;
// Connects to http://localhost:4317, service name "rust-camel"
let ctx = new
.with_lifecycle;
Custom Sampling and Resource Attributes
use ;
let config = new
.with_protocol
.with_sampler
.with_resource_attr
.with_resource_attr;
let ctx = new.with_lifecycle;
Configuration via Camel.toml
All OTel parameters can be configured in Camel.toml:
[]
= true
= "http://localhost:4317"
= "my-app"
= "info"
= "grpc" # "grpc" or "http"
= "ratio" # "always_on", "always_off", or "ratio"
= 0.1 # Only used when sampler = "ratio"
= 15000 # Metrics export interval (default: 60000)
= true # Export logs via OTLP (default: true)
[]
= "production"
= "us-east-1"
| Field | Default | Description |
|---|---|---|
enabled |
false |
Enable OTel export |
endpoint |
http://localhost:4317 |
OTLP endpoint |
service_name |
rust-camel |
Service name reported to backend |
log_level |
info |
Log level filter |
protocol |
grpc |
Export protocol (grpc or http) |
sampler |
always_on |
Sampling strategy |
sampler_ratio |
- | Ratio (0.0-1.0) when sampler = "ratio" |
metrics_interval_ms |
60000 |
Metrics export interval in ms |
logs_enabled |
true |
Export logs via OTLP |
resource_attrs |
{} |
Custom resource attributes |
OtelService
OtelService implements the Lifecycle trait, which follows Apache Camel's Service pattern:
- Initializes global
TracerProvider,MeterProvider, andLoggerProviderwhenCamelContext.start()is called - Installs
OpenTelemetryTracingBridgeto export logs via OTLP - Exposes
as_metrics_collector()for automatic metrics registration - Flushes and shuts down all providers when
CamelContext.stop()is called - Exposes
status()reflectingStopped/Started/Failedstates
Metrics Exported
Route-level metrics are recorded automatically by TracingProcessor:
| Metric | Type | Labels | Description |
|---|---|---|---|
camel.exchanges.total |
Counter | route.id |
Total exchanges processed |
camel.errors.total |
Counter | route.id, error.type |
Total errors |
camel.exchange.duration.seconds |
Histogram | route.id |
Exchange processing duration |
camel.queue.depth |
UpDownCounter | route.id |
Current queue depth |
camel.circuit.breaker.state |
UpDownCounter | route.id |
Circuit breaker state (0=closed, 1=open, 2=half_open) |
Log Bridge
The OpenTelemetryTracingBridge is installed automatically when OtelService starts. All tracing logs are exported via OTLP to your backend.
// These logs are automatically exported via OTLP
info!;
warn!;
W3C Propagation
W3C traceparent and tracestate headers are propagated automatically when the otel feature is enabled on the HTTP or Kafka components.
[]
= { = true, = ["otel"] }
= { = true, = ["otel"] }
- HTTP:
traceparentis injected into outgoing request headers and extracted from incoming requests - Kafka:
traceparentis injected into message headers and extracted on consume
Architecture
OtelService (Lifecycle trait)
↓
├── TracerProvider (OTLP span exporter, batch)
├── MeterProvider (OTLP metric exporter, 60s periodic reader)
├── LoggerProvider (OTLP log exporter, batch)
│ ↓
│ OpenTelemetryTracingBridge (log → OTLP)
├── OtelMetrics (implements MetricsCollector)
│ ↓
│ as_metrics_collector() → auto-registered with CamelContext
└── propagation.rs (W3C inject/extract used by camel-http and camel-kafka)
Note: Uses Lifecycle trait (not Service) to avoid confusion with tower::Service.
Hot-reload Compatibility
OTel configuration is NOT hot-reloadable. Changes to endpoint, service name, or sampler require process restart. This is standard practice in OpenTelemetry implementations.
Route hot-reload via ArcSwap continues to work independently.
Local Dev Backend
Then open http://localhost:3000 to view traces, metrics, and logs in Grafana.
Run the bundled demo:
Documentation
License
MIT — see LICENSE for details.
Contributing
Contributions welcome. Please open an issue or pull request on GitHub.