Gather relevant insights about your application and modules with custom metrics and telemetry.
Overview
Thetelemetry package provides observability tooling for Cosmos SDK applications using OpenTelemetry. It offers a unified initialization point for traces, metrics, and logs via the OpenTelemetry declarative configuration API.
This package:
- Initializes OpenTelemetry SDK using YAML configuration files
- Provides backward compatibility with Cosmos SDK’s legacy
go-metricswrapper API - Includes built-in instrumentation for host, runtime, and disk I/O metrics
Quick Start
1. Start a Local Telemetry Backend
2. Create Configuration File
Create anotel.yaml file:
3. Initialize Telemetry
Option A: Environment Variable (Recommended) SetOTEL_EXPERIMENTAL_CONFIG_FILE to your config path. This initializes the SDK before any meters/tracers are created, avoiding atomic load overhead.
otel.yaml will now be generated in ~/.<node_home>/config/. Place the desired configuration in otel.yaml.
Option C: Programmatic Initialization
The SDK will first attempt to initialize via env var, then using the config in the node’s home directory.
You may optionally initialize telemetry yourself using the telemetry.InitializeOpenTelemetry function:
Configuration
OpenTelemetry Configuration
The package uses the OpenTelemetry declarative configuration spec. Key sections:| Section | Purpose |
|---|---|
resource | Service identity and attributes |
tracer_provider | Trace export configuration |
meter_provider | Metrics export configuration |
logger_provider | Log export configuration |
Extensions
Theextensions section of the otel.yaml configuration file provides additional features not yet supported by the standard otelconf:
Custom Instruments
Host Instrumentation (host)
Reports host-level metrics using go.opentelemetry.io/contrib/instrumentation/host:
- CPU usage
- Memory usage
- Network I/O
Runtime Instrumentation (runtime)
Reports Go runtime metrics using go.opentelemetry.io/contrib/instrumentation/runtime:
- Goroutine count
- GC statistics
- Memory allocations
Disk I/O Instrumentation (diskio)
Reports disk I/O metrics using gopsutil:
| Metric | Description |
|---|---|
system.disk.io | Bytes read/written |
system.disk.operations | Read/write operation counts |
system.disk.io_time | Time spent on I/O operations |
system.disk.operation_time | Time per read/write operation |
system.disk.merged | Merged read/write operations |
Propagators
Configure trace context propagation for distributed tracing:| Propagator | Description |
|---|---|
tracecontext | W3C Trace Context (default) |
baggage | W3C Baggage |
b3 | Zipkin B3 single header |
b3multi | Zipkin B3 multi-header |
jaeger | Jaeger propagation |
Developer Usage
Using Meters and Tracers
After initialization, use standard OpenTelemetry APIs:Shutdown
Always callShutdown() when the application exits:
Legacy API (Deprecated)
The package provides backward-compatible wrappers forgithub.com/hashicorp/go-metrics. These are deprecated and users should migrate to OpenTelemetry APIs directly.
OpenTelemetry Bridge
Cosmos SDK v0.54.0+ provides a bridge to send existing go-metrics to the meter provider defined in your OpenTelemetry config. To bridge your metrics, set themetrics-sink in app.toml to “otel”.
Legacy Configuration
Legacy Metrics Functions
All are deprecated; prefer OpenTelemetry:Metrics Sink Types
| Sink | Description |
|---|---|
mem | In-memory sink with SIGUSR1 dump support (default) |
statsd | StatsD protocol |
dogstatsd | Datadog DogStatsD |
otel | OpenTelemetry (bridges to configured MeterProvider) |
Best Practices
- Use environment variable initialization for production to avoid atomic load overhead
- Always call
Shutdown()to ensure metrics/traces are flushed - Thread
context.Contextproperly for correct span correlation
Viewing Telemetry Data
With Grafana LGTM running:- Open http://localhost:3000
- Use the Drilldown views to explore:
- Traces: Distributed trace visualization
- Metrics: Query and dashboard metrics
- Logs: Structured log search
Related Documentation
Cosmos SDK Metrics
The following metrics are emitted from the Cosmos SDK.| Metric | Description | Unit | Type |
|---|---|---|---|
tx_count | Total number of txs processed via DeliverTx | tx | counter |
tx_successful | Total number of successful txs processed via DeliverTx | tx | counter |
tx_failed | Total number of failed txs processed via DeliverTx | tx | counter |
tx_gas_used | The total amount of gas used by a tx | gas | gauge |
tx_gas_wanted | The total amount of gas requested by a tx | gas | gauge |
tx_msg_send | The total amount of tokens sent in a MsgSend (per denom) | token | gauge |
tx_msg_withdraw_reward | The total amount of tokens withdrawn in a MsgWithdrawDelegatorReward (per denom) | token | gauge |
tx_msg_withdraw_commission | The total amount of tokens withdrawn in a MsgWithdrawValidatorCommission (per denom) | token | gauge |
tx_msg_delegate | The total amount of tokens delegated in a MsgDelegate | token | gauge |
tx_msg_begin_unbonding | The total amount of tokens undelegated in a MsgUndelegate | token | gauge |
tx_msg_begin_begin_redelegate | The total amount of tokens redelegated in a MsgBeginRedelegate | token | gauge |
tx_msg_ibc_transfer | The total amount of tokens transferred via IBC in a MsgTransfer (source or sink chain) | token | gauge |
ibc_transfer_packet_receive | The total amount of tokens received in a FungibleTokenPacketData (source or sink chain) | token | gauge |
new_account | Total number of new accounts created | account | counter |
gov_proposal | Total number of governance proposals | proposal | counter |
gov_vote | Total number of governance votes for a proposal | vote | counter |
gov_deposit | Total number of governance deposits for a proposal | deposit | counter |
staking_delegate | Total number of delegations | delegation | counter |
staking_undelegate | Total number of undelegations | undelegation | counter |
staking_redelegate | Total number of redelegations | redelegation | counter |
ibc_transfer_send | Total number of IBC transfers sent from a chain (source or sink) | transfer | counter |
ibc_transfer_receive | Total number of IBC transfers received to a chain (source or sink) | transfer | counter |
ibc_client_create | Total number of clients created | create | counter |
ibc_client_update | Total number of client updates | update | counter |
ibc_client_upgrade | Total number of client upgrades | upgrade | counter |
ibc_client_misbehaviour | Total number of client misbehaviors | misbehaviour | counter |
ibc_connection_open-init | Total number of connection OpenInit handshakes | handshake | counter |
ibc_connection_open-try | Total number of connection OpenTry handshakes | handshake | counter |
ibc_connection_open-ack | Total number of connection OpenAck handshakes | handshake | counter |
ibc_connection_open-confirm | Total number of connection OpenConfirm handshakes | handshake | counter |
ibc_channel_open-init | Total number of channel OpenInit handshakes | handshake | counter |
ibc_channel_open-try | Total number of channel OpenTry handshakes | handshake | counter |
ibc_channel_open-ack | Total number of channel OpenAck handshakes | handshake | counter |
ibc_channel_open-confirm | Total number of channel OpenConfirm handshakes | handshake | counter |
ibc_channel_close-init | Total number of channel CloseInit handshakes | handshake | counter |
ibc_channel_close-confirm | Total number of channel CloseConfirm handshakes | handshake | counter |
tx_msg_ibc_recv_packet | Total number of IBC packets received | packet | counter |
tx_msg_ibc_acknowledge_packet | Total number of IBC packets acknowledged | acknowledgement | counter |
ibc_timeout_packet | Total number of IBC timeout packets | timeout | counter |
store_iavl_get | Duration of an IAVL Store#Get call | ms | summary |
store_iavl_set | Duration of an IAVL Store#Set call | ms | summary |
store_iavl_has | Duration of an IAVL Store#Has call | ms | summary |
store_iavl_delete | Duration of an IAVL Store#Delete call | ms | summary |
store_iavl_commit | Duration of an IAVL Store#Commit call | ms | summary |
store_iavl_query | Duration of an IAVL Store#Query call | ms | summary |