greentic-telemetry
Tenant-aware telemetry utilities for Greentic services built on top of tracing and opentelemetry.
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 whenGT_TELEMETRY_FMT=1).- Utilities for integration testing (
testutil::span_recorder) and task-local helpers.
Quickstart
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.
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; use opentelemetry::global::shutdown_tracer_provider() 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:
Local CI checks
Run ci/local_check.sh before pushing to mirror the GitHub Actions matrix locally. The script is offline by default; opt in to extra checks via:
LOCAL_CHECK_ONLINE=1— run networked steps (cargo publish dry-run, cloud telemetry loops, schema curls).LOCAL_CHECK_STRICT=1— treat skipped steps as failures and require every optional tool/env to be present.LOCAL_CHECK_VERBOSE=1— echo each command for easier debugging.
The generated .git/hooks/pre-push hook invokes the script automatically; remove or edit it if you prefer to run the checks manually.