id_effect_opentelemetry 0.4.0

OpenTelemetry tracing and metrics integration for id_effect (Phase B / @effect/opentelemetry parity)
Documentation

id_effect_opentelemetry

Phase B integration: OpenTelemetry traces, metrics, and logs alongside id_effect's built-in with_span and Metric helpers.

See the mdBook chapter "OpenTelemetry (id_effect_opentelemetry)" and docs/effect-ts-parity/phases/phase-b-opentelemetry.md.

Features

Feature Purpose
otlp (default) OTLP gRPC/HTTP exporters via install_from_config
config Load settings from id_effect_config keys (otel.*)
platform W3C inject/extract on id_effect_platform::http::HttpRequest

Disable defaults for test-only builds:

id_effect_opentelemetry = { path = "../id_effect_opentelemetry", default-features = false }

Production OTLP (one call)

use id_effect_opentelemetry::{OtelConfig, install_from_config, shutdown_otel_on_signal};

let guard = install_from_config(OtelConfig::from_env()?)?;
// ... run your server ...
shutdown_otel_on_signal(guard).await;

Environment variables follow the OpenTelemetry spec:

  • OTEL_EXPORTER_OTLP_ENDPOINT — collector URL (default http://localhost:4317)
  • OTEL_EXPORTER_OTLP_PROTOCOLgrpc or http
  • OTEL_SERVICE_NAMEservice.name resource attribute
  • OTEL_EXPORTER_OTLP_HEADERS — comma-separated key=value pairs
  • RUST_LOG — optional EnvFilter when installing the global subscriber

Highlights

  • with_span_otel: composes id_effect::with_span with a tracing span exported via OTEL.
  • W3C propagation: trace context + baggage on portable header maps (and HttpRequest with platform).
  • Metric bridges: dual-write from Metric counters/histograms to OTEL instruments.
  • Logs bridge: tracing events exported to OTEL logs via opentelemetry-appender-tracing.
  • Unified starter: install_otel_starter wires traces, metrics, logs, and propagators.
  • Test harness: with_otel_test_harness — in-memory exporters, no global clashes.

Examples

cargo run -p id_effect_opentelemetry --example otel_minimal
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 cargo run -p id_effect_opentelemetry --example otel_production

Tests

cargo test -p id_effect_opentelemetry --all-features