Google Cloud observability for Rust
Formerly opentelemetry-gcloud-trace, see the migration guide.
The library sends what a Rust service emits through tracing and OpenTelemetry to Google Cloud:
- Cloud Logging: a
tracing-subscriberlayer that writes structured log entries, each correlated with the trace and span that emitted it, so the console shows every log line under its trace; - Cloud Trace: OpenTelemetry span exporters for the Telemetry API, which takes OTLP (the OpenTelemetry wire protocol), and for the Cloud Trace API v2;
- Error Reporting: errors logged with the code location, the
source()chain and a backtrace, and panics, in the format Error Reporting groups; - Authentication of any OTLP exporter, metrics included, with Google Application Default Credentials (ADC), refreshed in the background;
- Three log sinks: JSON lines on stdout for GKE, Cloud Run and hosts with the logging agent, the Cloud Logging API, and OTLP.
Documentation
Please follow to the official website: https://gcloud-observability-rust.abdolence.dev/.
Features
| Feature | Goal |
|---|---|
logs (default) |
The logging layer with the JSON lines sink, and Error Reporting for every sink |
logs-api |
The logging layer writes through the Cloud Logging API, for hosts with no logging agent |
logs-otlp |
The logging layer sends entries over OTLP to the Telemetry API; includes logs and otlp |
otlp |
Span exporter and authentication for the Telemetry API (telemetry.googleapis.com) |
trace-api |
Span exporter for the Cloud Trace API v2 (cloudtrace.googleapis.com) |
tls-roots (default) |
Native TLS root certificates |
tls-webpki-roots |
TLS root certificates of the webpki-roots crate |
auth-default-crypto |
The rustls crypto provider that service account keys are signed with (default) |
No exporter is enabled by default.
Quick start
Cargo.toml:
[]
= { = "0.31", = ["logs-otlp"] }
= "0.33"
= "0.1"
= { = "0.3", = ["env-filter"] }
= "0.34"
= { = "1", = ["macros", "rt-multi-thread"] }
Minimum supported Rust version is 1.91.
Spans go to the Telemetry API through OTLP in both modes.
APP_MODE (default development) picks the log sink:
development: console lines, and the same entries over OTLP, so that a run from a laptop shows the correlated entries in the Google Cloud console;production: JSON lines on stdout, which the Cloud Logging agent of GKE, Cloud Run and GCE collects.
use LogId;
use GcpCloudLoggingLayerBuilder;
use GcpOtlpExporterBuilder;
use ;
use SubscriberExt;
use ;
async
The credentials ADC finds need the roles/telemetry.writer role on the project.
The development mode writes every event to the terminal and over OTLP. A service picks one sink.
See Authentication.
PROJECT_ID=<your-google-project-id> cargo
PROJECT_ID=<your-google-project-id> APP_MODE=production
Full example available here.
More examples, by goal, are in the examples directory:
| Goal | Examples |
|---|---|
| Logging | logging-dev-and-prod, logging-cloud-logging-api, logging-otlp |
| Errors and panics | errors-error-reporting, errors-panic-hook |
| Traces | traces-otlp, traces-cloud-trace-api |
| Traces with correlated logs | traces-and-logs-otlp, traces-and-logs-cloud-trace-api |
| Metrics | metrics-otlp |
Each runs as PROJECT_ID=<your-google-project-id> cargo run --example <name> --features <features>.
The features it needs are in its header and in required-features in Cargo.toml.
Compatibility matrix
| gcloud-observability version | opentelemetry version | opentelemetry-otlp | tracing-opentelemetry | gcloud-sdk |
|---|---|---|---|---|
| 0.31 | 0.33 | 0.33 | 0.34 | 0.33 |
| 0.30 | 0.33 | - | 0.34 | 0.33 |
| 0.29 | 0.33 | - | 0.34 | 0.33 |
| 0.28 | 0.33 | - | 0.34 | 0.32 |
| 0.27 | 0.32 | - | 0.33 | 0.32 |
| 0.26 | 0.32 | - | 0.33 | 0.32 |
| 0.25 | 0.32 | - | 0.33 | 0.31 |
| 0.24 | 0.32 | - | 0.33 | 0.30 |
| 0.23 | 0.31 | - | 0.32 | 0.29 |
Versions up to 0.30 are published as opentelemetry-gcloud-trace.
Migrating
0.31 renames the crate and moves the Cloud Trace API exporter behind the trace-api feature.
See the migration guide and
Migrating from 0.30.
From tracing-stackdriver: Migrating from tracing-stackdriver.
Licence
Apache Software License (ASL)
Author
Abdulla Abdurakhmanov