Tracing and errors monitoring¶
go-pg supports tracing out-of-the-box using OpenTelemetry API. To enable queries instrumentation, use the following code:
import (
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/extra/pgotel"
)
db := pg.Connect(&pg.Options{...})
db.AddQueryHook(pgotel.TracingHook{})
TracingHook
sends SELECT, UPDATE, and DELETE queries as is. But it strips data values from INSERT queries since they can contain sensitive information.
This is how span looks at Uptrace.dev which is an OpenTelemetry backend that supports distributed traces, logs, and errors.