otlp-logger
OpenTelemetry Logging with Tokio Tracing
This crate provides a convienent way to initialize the OpenTelemetry logger
with otlp endpoint. It uses the opentelemetry and tracing
crates to provide structured, context-aware logging for Rust applications.
Simply add the following to your Cargo.toml:
[]
= "0.1"
= "0.3"
= { = "1.37", = ["rt", "macros"] }
Because this crate uses the batching function of the OpenTelemetry SDK, it is
required to use the tokio runtime. Due to this requirement, the tokio crate
must be added as a dependency in your Cargo.toml file.
In your code initialize the logger with:
async
If the OTEL_EXPORTER_OTLP_ENDPOINT environment variable is set, the
OpenTelemetry logger will be used. Otherwise, the logger will default to
only stdout.
The OpenTelemetry logger can be configured with the following environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT: The endpoint to send OTLP data to.OTEL_SERVICE_NAME: The name of the service.OTEL_SERVICE_NAMESPACE: The namespace of the service.OTEL_SERVICE_VERSION: The version of the service.OTEL_SERVICE_INSTANCE_ID: The instance ID of the service.OTEL_DEPLOYMENT_ENVIRONMENT: The deployment environment of the service.
The OpenTelemetry logger can also be configured with the OtlpConfig struct, which
can be passed to the init_with_config function. The OtlpConfig struct can be built
with the OtlpConfigBuilder struct.
Once the logger is initialized, you can use the tracing macros to log
messages. For example:
use ;
async
Traces, metrics, and logs are sent to the configured OTLP endpoint. The traces,
metrics, and log level are configured via the RUST_LOG environment variable.
This behavior can be overridden by setting the trace_level, metrics_level, or
stdout_level fields in the OtlpConfig struct.
use ;
async
The OtlpConfig struct also allows you to configure metrics aggregation. Under the hood
the default aggregation is provided by the OpenTelemetry SDK's DefaultAggregationSelector.
The default can be overridden by setting the metrics_aggregation field in the OtlpConfig
struct. The metrics_aggregation field is of type MetricsAggregationConfig which can be
built with MetricsAggregationConfigBuilder struct.
use ;
async
Current version: 0.3.0
License: Apache-2.0