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 and MeterProvider 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.
Quick Start
use ;
use CamelContext;
// OTel providers start/stop automatically with context
let ctx = new
.with_lifecycle;
ctx.start.await?;
// Traces and metrics exported to OTLP backend
ctx.stop.await?;
// 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;
OtelService
OtelService implements the Lifecycle trait, which follows Apache Camel's Service pattern:
- Initializes global
TracerProviderandMeterProviderwhenCamelContext.start()is called - Flushes and shuts down providers when
CamelContext.stop()is called - Exposes
status()reflectingStopped/Started/Failedstates
Metrics Exported
| 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) |
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)
↓
├── Initializes global TracerProvider (OTLP span exporter, batch)
├── Initializes global MeterProvider (OTLP metric exporter, 60s periodic reader)
└── propagation.rs (W3C inject/extract used by camel-http and camel-kafka)
Note: Uses Lifecycle trait (not Service) to avoid confusion with tower::Service.
Local Dev Backend
Then open http://localhost:3000 to view traces and metrics 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.