Expand description
One-call OpenTelemetry bootstrap — traces + metrics + logs with OTLP export.
Call init_telemetry at main() before starting the server. Keep the returned
TelemetryHandles alive for the duration of the process — dropping them flushes
and shuts down both providers.
Configuration is via environment variables per the OpenTelemetry spec:
OTEL_EXPORTER_OTLP_ENDPOINT(default:http://localhost:4317for gRPC,http://localhost:4318for HTTP)OTEL_EXPORTER_OTLP_PROTOCOL(grpcorhttp/protobuf) — selects transport when both features are enabledOTEL_EXPORTER_OTLP_TIMEOUT— export timeout in milliseconds (default: 10 000 ms)OTEL_SERVICE_NAME(overridden by theservice_nameargument)OTEL_TRACES_SAMPLER/OTEL_TRACES_SAMPLER_ARG(fallback when no explicit sampler is set)
§Env var handling: otel-bootstrap vs SDK
| Env var | Handled by |
|---|---|
OTEL_SERVICE_NAME | otel-bootstrap (falls back to SDK default) |
OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARG | otel-bootstrap |
OTEL_EXPORTER_OTLP_PROTOCOL | otel-bootstrap |
OTEL_EXPORTER_OTLP_ENDPOINT | otel-bootstrap |
OTEL_EXPORTER_OTLP_TIMEOUT | otel-bootstrap |
OTEL_BSP_MAX_EXPORT_BATCH_SIZE | SDK (batch span processor) |
OTEL_METRIC_EXPORT_INTERVAL | SDK (periodic reader) |
Per-signal endpoints (OTEL_EXPORTER_OTLP_TRACES_ENDPOINT etc.) | SDK |
Re-exports§
pub use instrumented_port::Instrumented;pub use instrumented_port::InstrumentedArc;pub use log_bridge::PROPAGATED_SPAN_FIELDS;pub use log_bridge::SpanLogAttrs;pub use log_bridge::record_span_log_attr;pub use log_bridge::record_span_log_attr_on;pub use spanned::Spanned;pub use spanned::in_span;
Modules§
- axum_
middleware - Axum tower middleware for W3C trace context propagation.
- grpc_
middleware - Tonic gRPC trace-context propagation, client and server side.
- instrumented_
port - Generic client-span wrapper for outbound hexagonal port calls.
- log_
bridge - profiling
- span_
enrichment - Span enrichment via the
EnrichSpantrait. - spanned
- Await-safe replacement for the
let _guard = span.enter();pattern. - testing
- No-op / testing mode for
otel-bootstrap.
Structs§
- Mtls
Material - mTLS material for the gRPC transport. Requires the
grpc-mtlsfeature. - Telemetry
- Entry point for configuring telemetry via a builder pattern.
- Telemetry
Builder - Builder for configuring telemetry options incrementally.
- Telemetry
Handles - Handles returned by
init_telemetryorTelemetryBuilder::init.
Enums§
- Export
Protocol - OTLP export protocol.
- LogFormat
- Stdout log encoding installed by
TelemetryBuilder. - Trace
Sampler - Trace sampler configuration.
Functions§
- axum_
layer - Returns a ready-to-use
tower::Layerthat extracts W3C trace context from incoming HTTP requests, creates a span with standard HTTP semantic-convention attributes, and injects trace context into response headers. - build_
resource - Build a
Resourceenriched with semantic-convention attributes. - grpc_
client_ layer - Construct the tower
Layerthat injects the current trace context into outgoing gRPC request metadata. - grpc_
server_ layer - Construct the tower
Layerthat extracts trace context from incoming gRPC request metadata and opens a child span. - init_
telemetry - Initialise OpenTelemetry traces + metrics with OTLP gRPC export.
- init_
telemetry_ with_ sampler - Initialise OpenTelemetry traces + metrics with OTLP gRPC export and an explicit trace sampler.
- span_
enricher_ layer - Construct the tower
Layerthat callsspan_enrichment::EnrichSpan::enrich_spanon every request that carries aTextension.