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.6"
= { = "1", = ["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:
use OtlpLogger;
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 levels are configured via the RUST_LOG environment variable.
This behavior can be overridden by setting the trace_level, metrics_level or
log_level fields in the OtlpConfig struct. You can control what
goes to stdout by setting the stdout_level field.
use ;
async
License: Apache-2.0