tracing-stackdriver
A tracing
Subscriber for communicating Stackdriver-formatted logs
tracing
is a scoped, structured logging and diagnostic system based on emitting Event
s in the context of potentially-nested Span
s 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
(inLogSeverity
format) derived fromtracing
Level
target
derived from the Eventtarget
Metadata
- Span
name
and custom fields included under aspan
key - automatic nesting of
http_request.
-prefixed event fields - automatic camelCase-ing of all field keys (e.g.
http_request
->httpRequest
) valuable
support, including anHttpRequest
helperstruct
- Cloud Trace support derived from OpenTelemetry Span and Trace IDs.
Examples
Basic setup:
use ;
Custom write location:
use ;
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;
With Cloud Trace support:
tracing_stackdriver
supports integration with Cloud Trace and OpenTelemetry via tracing_opentelemetry and outputs special Cloud Trace LogEntry
fields for trace sampling and log correlation.
To enable Cloud Trace support, you need to enable the opentelemetry
feature flag and provide a CloudTraceConfiguration
to the enable_cloud_trace
method of the layer.
use CloudTraceConfiguration;