greentic-telemetry
Tenant-aware telemetry utilities for Greentic services built on top of tracing, opentelemetry, and the shared greentic-types domain crate.
Highlights
TelemetryCtx: structured context carrying{tenant, team, user, session, flow, node, provider}.CtxLayer: atracinglayer that injectsTelemetryCtxfields into spans and OTLP attributes.init_otlp: opinionated OTLP pipeline wiring with fmt logging + OpenTelemetry exporter.- Helpers for integration tests (
testutil::span_recorder) and Elastic/Kibana developer bundle. - Existing
init_telemetrybootstrap preserved for legacy callers.
Quickstart
use ;
use ;
use ;
Spans automatically receive the Greentic attributes (as tracing fields and OTLP attributes), ensuring the collector exports {tenant, session, flow, node, provider} consistently.
Bridging greentic-types
TelemetryCtx implements From<&greentic_types::TenantCtx>, From<&InvocationEnvelope>, and From<&telemetry::SpanContext>, so existing domain payloads can be mapped without manual string conversions:
use TelemetryCtx;
use ;
OTLP wiring
init_otlp produces a tracing Dispatch with:
tracing_subscriber::fmtlayer (target + thread info disabled by default)tracing_opentelemetry::layerconnected to an OTLP gRPC exporter- Resource set with
service.namefromOtlpConfig
It installs the Dispatch as the global default and returns a clone so callers can reinstall or inspect it. Use otlp::shutdown() (or the legacy shutdown() re-export) on graceful shutdown to flush spans.
Legacy bootstrap
init_telemetry / TelemetryConfig continue to provide the previous logging preset (stdout/file appenders + OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set). New services should prefer init_otlp for explicit configuration.
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:
The new context propagation integration test (tests/context_propagation.rs) asserts that CtxLayer injects the Greentic attributes across spans.