Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Field conventions

Event fields map onto Cloud Logging’s structured LogEntry fields as follows. Anything else is written verbatim into the JSON payload.

Event fieldLog entry fieldFormat
severityseverityOne of DEFAULT DEBUG INFO NOTICE WARNING ERROR CRITICAL ALERT EMERGENCY, matched case-insensitively. Overrides the level mapping: TRACE and DEBUG are DEBUG, INFO is INFO, WARN is WARNING, ERROR is ERROR; the level maps when the field is absent or not a name
http_request.request_method, .request_url, .user_agent, .remote_ip, .server_ip, .referer, .protocolhttpRequest.*, camel-casedstrings
http_request.statushttpRequest.statusinteger
http_request.request_size, .response_size, .cache_fill_byteshttpRequest.*integers
http_request.latencyhttpRequest.latencya duration string such as "250ms" or "1.5s", or a number of seconds
http_request.cache_lookup, .cache_hit, .cache_validated_with_origin_serverhttpRequest.*booleans
labels.<name>logging.googleapis.com/labels.<name>value stringified
operation.id, .producerlogging.googleapis.com/operation.{id,producer}strings
operation.first, .lastlogging.googleapis.com/operation.{first,last}booleans
insert_idlogging.googleapis.com/insertIdstring
source locationlogging.googleapis.com/sourceLocationfile and line; on by default, disable with with_source_location(false)

The field names are not valid Rust identifiers, so they are written as string literals in the macros:

info!(
    "labels.tenant" = "acme",
    "http_request.request_method" = "GET",
    "http_request.request_url" = "https://example.test/orders",
    "http_request.status" = 200,
    "Serving a request."
);

Only the httpRequest.* keys are camel-cased, matching Google’s own field names; every other field name is written as given.

On the Cloud Logging API and OTLP sinks, a value that does not fit the typed field it is destined for, such as a malformed latency, stays in the payload instead of being dropped.

Errors

An event field passed as &dyn Error keeps its whole source() chain, one Caused by: line per source:

tracing::error!(error = &failure as &dyn std::error::Error, "checkout failed");

error = %err and error = ?err record only the text they format. See Error Reporting for how an error event is grouped.