tracing-stackdriver
A tracing Subscriber for communicating Stackdriver-formatted logs
tracing is a scoped, structured logging and diagnostic system based on emitting Events in the context of potentially-nested Spans across asynchronous await points. These properties make tracing ideal for use with Google Cloud Operations Suite structured logging (formerly Stackdriver).
This crate provides a Layer for use with a tracing Registry that formats tracing Spans and Events into properly-structured JSON for consumption by Google Operations Logging through the jsonPayload field. This includes the following behaviors and enhancements:
rfc3339-formatted timestamps for all Eventsseverity(inLogSeverityformat) derived fromtracingLeveltargetderived from the EventtargetMetadata- Span
nameand custom fields included under aspankey - automatic nesting of
http_request.-prefixed event fields - automatic camelCase-ing of all field keys (e.g.
http_request->httpRequest) valuablesupport, including anHttpRequesthelperstruct
Examples
Basic setup:
use ;
use Stackdriver;
Custom write location:
use ;
use Stackdriver;
With httpRequest fields:
See all available fields here.
// requires working global setup (see above examples)
use Request;
With more specific LogSeverity levels:
Google supports a slightly different set of severity levels than tracing. tracing levels are automatically mapped to LogSeverity levels, but you can customize the level beyond the intersection of tracing levels and LogSeverity levels by using the provided LogSeverity level with a severity key.
use LogSeverity;
With valuable support:
tracing_stackdriver supports deeply-nested structured logging through tracing's unstable valuable support. In addition, httpRequest fields can be generated with the HttpRequest helper struct exported from this library for better compile-time checking of fields.
To enable valuable support, use the valuable feature flag and compile your project with RUSTFLAGS="--cfg tracing_unstable".
// requires working global setup (see above examples)
use Request;
use HttpRequest;
use Valuable;
Roadmap:
- distributing tracing data in Cloud Trace format
- support the logging API in addition to the logging agent/std{out,err}