Performance and errors monitoring
OpenTelemetry
You can monitor DB performance and errors using distributed tracing and metrics. Tracing allows you to see how a request progresses through different services and systems, timings of every operation, any logs and errors as they occur.
go-clickhouse supports tracing and metrics using OpenTelemetry API. OpenTelemetry is a vendor-neutral API for distributed traces and metrics. It specifies how to collect and send telemetry data to backend platforms. It means that you can instrument your application once and then add or change vendors (backends) as required.
go-clickhouse comes with an OpenTelemetry instrumentation called chotel that is distributed as a separate module:
go get github.com/uptrace/go-clickhouse/chotel
To instrument go-clickhouse database, you need to add the hook provided by chotel:
import (
"github.com/uptrace/go-clickhouse/ch"
"github.com/uptrace/go-clickhouse/chotel"
)
db := ch.Connect(ch.WithDatabase("test"))
db.AddQueryHook(chotel.NewQueryHook())
As expected, go-clickhouse creates spans for processed queries and records any errors as they occur. Here is how the collected information is displayed at Uptrace:
You can find a runnable example at GitHub.