tracing-gcloud-layer
A robust and configurable tracing layer for Rust, delivering logs from the tracing
ecosystem directly to Google Cloud Logging (Stackdriver).
๐ Features
- Seamless integration with Rustโs tracing ecosystem.
- Structured logs delivered to Google Cloud Logging (Stackdriver) using service account authentication.
- Asynchronous, batched log delivery for improved efficiency.
- Log formatting and enrichment customizable via the LogMapper trait.
- Basic support for trace ID and severity metadata propagation.
๐ฆ Installation
Add to your Cargo.toml
:
๐ ๏ธ Quickstart
-
Generate a Google Cloud service account with the "Logs Writer" role and download the JSON key.
-
Initialize the tracing layer:
use DefaultGCloudLayerConfigBuilder;
use Registry;
let = default
.log_name
.logger_credential
.build
.expect
.build_layer;
registry
.with
.init;
- Emit logs in your application:
!;
info
Logs will appear in Google Cloud Logging under the configured log name
โ๏ธ Configuration
log_name
: Log stream name in GCP (e.g., "stdout", "my-app").logger_credential
: Service account credentials (as bytes).config
: Batching, timeouts, and writer options.log_mapper
: Plug in your ownLogMapper
to customize log transformation.
Example: Custom Log Mapper
use ;
;
let = default
.log_name
.logger_credential
.log_mapper
.build
.expect
.build_layer;