greentic-telemetry
Tenant-aware telemetry utilities for Greentic services built on top of tracing, opentelemetry, and the shared greentic-types domain crate.
Highlights
TelemetryCtx: lightweight context carrying{tenant, session, flow, node, provider}.layer_from_task_local: grab the context from a Tokio task-local without wiring closures.CtxLayer(layer_with): legacy closure-based path kept for backwards compatibility.init_otlp: install an OTLP pipeline (with optionalfmtlayer) and flush on shutdown.- Utilities for integration testing (
testutil::span_recorder) and task-local helpers.
Quickstart
use ;
use ;
use ;
async
Spans automatically receive the Greentic attributes (as tracing fields and OTLP attributes), ensuring the collector exports {tenant, session, flow, node, provider} consistently via the task-local path.
Bridging greentic-types
TelemetryCtx implements From<&greentic_types::TenantCtx>, so existing tenant metadata can be attached without manual string conversions:
use TelemetryCtx;
use TenantCtx;
OTLP wiring
init_otlp installs a tracing subscriber composed of:
tracing_subscriber::fmtlayer (behind thefmtfeature flag)tracing_opentelemetry::layerconnected to an OTLP gRPC exporterservice.namepopulated fromOtlpConfig
The subscriber becomes the global default; call shutdown() during graceful shutdown to flush spans.
Testing utilities
testutil::span_recorder() returns a (CaptureLayer, Arc<Mutex<Vec<RecordedSpan>>>) pair for asserting that spans carry TelemetryCtx. See tests/context_propagation.rs for an end-to-end example exercising propagation across nested spans.
Dev Elastic bundle
A ready-to-run Elastic/Kibana/OpenTelemetry Collector stack lives in dev/elastic-compose/.
Then open Kibana at http://localhost:5601/. The default collector config writes spans/metrics to stdout for quick inspection—customise otel-config.yaml if you want to forward to Elastic APM.
The existing dev/docker-compose.elastic.yml + Filebeat setup remains available if you need the legacy log ingestion pipeline.
Verification
This crate must pass: