cosmossdk.io/log/v2 package provides a zerolog logging implementation for the Cosmos SDK and Cosmos SDK modules.
To use a logger wrapping an instance of the standard library’s log/slog package, use cosmossdk.io/log/slog.
OpenTelemetry
The v2 release of log adds contextual methods to theLogger interface. This allows logs to be correlated with traces.
Example
Below is an example of how logs can be correlated with traces. In Grafana, clicking on theUpdateBalance trace will show the “Hello World” log,
as the span context was properly threaded to the logger’s InfoContext call.
otelslog
If your OpenTelemetry configuration contained a logger provider, the Cosmos SDK will automatically provision a MultiLogger, logging to both stdout via the existingzerolog wrapper, and to the configured logger provider via otelslog.
Log Correlation with Tempo and Loki
To get log correlation with Tempo and Loki, simply scrape the logs in JSON format from stdout/stderr and forward them to Loki. Then, configure Tempo with the following settings: In theTrace to logs section:
- Set data source to Loki if not already
- Set
Span start time shiftto a reasonable amount of time (+/-1m) - Set the custom query to:
{${__tags}} | trace_id = "${__trace.traceId}"