Skip to main content

Crate otel_bootstrap

Crate otel_bootstrap 

Source
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:4317 for gRPC, http://localhost:4318 for HTTP)
  • OTEL_EXPORTER_OTLP_PROTOCOL (grpc or http/protobuf) — selects transport when both features are enabled
  • OTEL_EXPORTER_OTLP_TIMEOUT — export timeout in milliseconds (default: 10 000 ms)
  • OTEL_SERVICE_NAME (overridden by the service_name argument)
  • OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARG (fallback when no explicit sampler is set)

§Env var handling: otel-bootstrap vs SDK

Env varHandled by
OTEL_SERVICE_NAMEotel-bootstrap (falls back to SDK default)
OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARGotel-bootstrap
OTEL_EXPORTER_OTLP_PROTOCOLotel-bootstrap
OTEL_EXPORTER_OTLP_ENDPOINTotel-bootstrap
OTEL_EXPORTER_OTLP_TIMEOUTotel-bootstrap
OTEL_BSP_MAX_EXPORT_BATCH_SIZESDK (batch span processor)
OTEL_METRIC_EXPORT_INTERVALSDK (periodic reader)
Per-signal endpoints (OTEL_EXPORTER_OTLP_TRACES_ENDPOINT etc.)SDK

Structs§

Telemetry
Entry point for configuring telemetry via a builder pattern.
TelemetryBuilder
Builder for configuring telemetry options incrementally.
TelemetryHandles
Handles returned by init_telemetry or TelemetryBuilder::init.

Enums§

ExportProtocol
OTLP export protocol.
TraceSampler
Trace sampler configuration.

Functions§

build_resource
Build a Resource enriched with semantic-convention attributes.
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.