Skip to main content

Crate tracing_google_cloud

Crate tracing_google_cloud 

Source
Expand description

This is a tracing-subcriber Layer that implements Google Cloud’s Structured Logging format.

Features:

  • OpenTelemetry Trace integration (with opentelemetry feature flag)
  • Support for HTTP requests via log entry fields
  • Support for populating operation structures into log entries from the parent Span(s).
tracing_subscriber::registry()
    .with(tracing_opentelemetry::layer())
    .with(tracing_google_cloud::builder()
        .with_project_id(PROJECT_ID) // required with opentelemetry feature
        .with_writer(std::io::stdout())
        .build())
    .init();

§HTTP request fields

tracing::info!(
    http.request_method = "POST",
    http.request_url = "/",
    http.request_size = 420,
    http.status = 200,
    http.response_size = 1024,
    http.user_agent = "Fire fox",
    http.remote_ip = "127.0.0.1",
    http.server_ip = "127.0.0.2",
    http.referer = "127.0.0.2",
    http.latency_ns = 32000000,
    http.cache_lookup = false,
    http.cache_hit = false,
    http.cache_validated_with_origin_server = false,
    http.cache_fill_bytes = 200,
    http.protocol = "HTTP/4",
)

§Using operations

See SpanExt::operation and Operation.

use tracing_google_cloud::{OperationInfo, SpanExt};

let span = tracing::info_span!("long_operation");
let operation = span.start_operation(
    "unique-id",
    Some("github.com/der-fruhling/tracing-google-cloud")
);

span.in_scope(|| {
    // First log entry with an operation automatically has the "first" field set
    tracing::info!("First log");

    tracing::info!("Something in the middle");

    // Call Operation::end() to cause the next log entry to have "last" set.
    // You can also call this before the first entry if you wish.
    operation.end();
    tracing::info!("End of the operation");
})

Structs§

InvalidSeverity
A severity value was not one of the allowed enumerations.
Layer
LayerBuilder
Operation
Represents a potentially long-running operation that can be used by Google Cloud to group log entries.
OperationInfo

Enums§

Severity
Allows using any severity value supported by Cloud Logging.

Traits§

SpanExt
This trait extends tracing::Span with additional functionality provided by this crate.

Functions§

builder
The main entrypoint for this crate. This function allows creating a Layer from scratch.