diff --git a/otelsql/go.mod b/otelsql/go.mod index ed5b3a5..ca946b6 100644 --- a/otelsql/go.mod +++ b/otelsql/go.mod @@ -3,12 +3,12 @@ module github.com/uptrace/opentelemetry-go-extra/otelsql go 1.18 require ( - go.opentelemetry.io/otel v1.13.0 - go.opentelemetry.io/otel/metric v0.36.0 - go.opentelemetry.io/otel/trace v1.13.0 + go.opentelemetry.io/otel v1.15.0 + go.opentelemetry.io/otel/metric v0.38.0 + go.opentelemetry.io/otel/trace v1.15.0 ) require ( - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect ) diff --git a/otelsql/go.sum b/otelsql/go.sum index cf606b7..760aa08 100644 --- a/otelsql/go.sum +++ b/otelsql/go.sum @@ -1,16 +1,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -go.opentelemetry.io/otel v1.13.0 h1:1ZAKnNQKwBBxFtww/GwxNUyTf0AxkZzrukO8MeXqe4Y= -go.opentelemetry.io/otel v1.13.0/go.mod h1:FH3RtdZCzRkJYFTCsAKDy9l/XYjMdNv6QrkFFB8DvVg= -go.opentelemetry.io/otel/metric v0.36.0 h1:t0lgGI+L68QWt3QtOIlqM9gXoxqxWLhZ3R/e5oOAY0Q= -go.opentelemetry.io/otel/metric v0.36.0/go.mod h1:wKVw57sd2HdSZAzyfOM9gTqqE8v7CbqWsYL6AyrH9qk= -go.opentelemetry.io/otel/trace v1.13.0 h1:CBgRZ6ntv+Amuj1jDsMhZtlAPT6gbyIRdaIzFhfBSdY= -go.opentelemetry.io/otel/trace v1.13.0/go.mod h1:muCvmmO9KKpvuXSf3KKAXXB2ygNYHQ+ZfI5X08d3tds= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +go.opentelemetry.io/otel v1.15.0 h1:NIl24d4eiLJPM0vKn4HjLYM+UZf6gSfi9Z+NmCxkWbk= +go.opentelemetry.io/otel v1.15.0/go.mod h1:qfwLEbWhLPk5gyWrne4XnF0lC8wtywbuJbgfAE3zbek= +go.opentelemetry.io/otel/metric v0.38.0 h1:vv/Nv/44S3GzMMmeUhaesBKsAenE6xLkTVWL+zuv30w= +go.opentelemetry.io/otel/metric v0.38.0/go.mod h1:uAtxN5hl8aXh5irD8afBtSwQU5Zjg64WWSz6KheZxBg= +go.opentelemetry.io/otel/trace v1.15.0 h1:5Fwje4O2ooOxkfyqI/kJwxWotggDLix4BSAvpE1wlpo= +go.opentelemetry.io/otel/trace v1.15.0/go.mod h1:CUsmE2Ht1CRkvE8OsMESvraoZrrcgD1J2W8GV1ev0Y4= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/otelsql/otel.go b/otelsql/otel.go index 0932e27..5a011ae 100644 --- a/otelsql/otel.go +++ b/otelsql/otel.go @@ -12,7 +12,6 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" semconv "go.opentelemetry.io/otel/semconv/v1.10.0" "go.opentelemetry.io/otel/trace" ) @@ -54,7 +53,7 @@ func (c *config) formatQuery(query string) string { type dbInstrum struct { *config - queryHistogram instrument.Int64Histogram + queryHistogram metric.Int64Histogram } func newDBInstrum(opts []Option) *dbInstrum { @@ -72,8 +71,8 @@ func newDBInstrum(opts []Option) *dbInstrum { var err error t.queryHistogram, err = t.meter.Int64Histogram( "go.sql.query_timing", - instrument.WithDescription("Timing of processed queries"), - instrument.WithUnit("milliseconds"), + metric.WithDescription("Timing of processed queries"), + metric.WithUnit("milliseconds"), ) if err != nil { panic(err) @@ -106,7 +105,7 @@ func (t *dbInstrum) withSpan( span.End() if query != "" { - t.queryHistogram.Record(ctx, time.Since(startTime).Milliseconds(), t.attrs...) + t.queryHistogram.Record(ctx, time.Since(startTime).Milliseconds(), metric.WithAttributes(t.attrs...)) } if !span.IsRecording() { @@ -185,57 +184,57 @@ func ReportDBStatsMetrics(db *sql.DB, opts ...Option) { maxOpenConns, _ := meter.Int64ObservableGauge( "go.sql.connections_max_open", - instrument.WithDescription("Maximum number of open connections to the database"), + metric.WithDescription("Maximum number of open connections to the database"), ) openConns, _ := meter.Int64ObservableGauge( "go.sql.connections_open", - instrument.WithDescription("The number of established connections both in use and idle"), + metric.WithDescription("The number of established connections both in use and idle"), ) inUseConns, _ := meter.Int64ObservableGauge( "go.sql.connections_in_use", - instrument.WithDescription("The number of connections currently in use"), + metric.WithDescription("The number of connections currently in use"), ) idleConns, _ := meter.Int64ObservableGauge( "go.sql.connections_idle", - instrument.WithDescription("The number of idle connections"), + metric.WithDescription("The number of idle connections"), ) connsWaitCount, _ := meter.Int64ObservableCounter( "go.sql.connections_wait_count", - instrument.WithDescription("The total number of connections waited for"), + metric.WithDescription("The total number of connections waited for"), ) connsWaitDuration, _ := meter.Int64ObservableCounter( "go.sql.connections_wait_duration", - instrument.WithDescription("The total time blocked waiting for a new connection"), - instrument.WithUnit("nanoseconds"), + metric.WithDescription("The total time blocked waiting for a new connection"), + metric.WithUnit("nanoseconds"), ) connsClosedMaxIdle, _ := meter.Int64ObservableCounter( "go.sql.connections_closed_max_idle", - instrument.WithDescription("The total number of connections closed due to SetMaxIdleConns"), + metric.WithDescription("The total number of connections closed due to SetMaxIdleConns"), ) connsClosedMaxIdleTime, _ := meter.Int64ObservableCounter( "go.sql.connections_closed_max_idle_time", - instrument.WithDescription("The total number of connections closed due to SetConnMaxIdleTime"), + metric.WithDescription("The total number of connections closed due to SetConnMaxIdleTime"), ) connsClosedMaxLifetime, _ := meter.Int64ObservableCounter( "go.sql.connections_closed_max_lifetime", - instrument.WithDescription("The total number of connections closed due to SetConnMaxLifetime"), + metric.WithDescription("The total number of connections closed due to SetConnMaxLifetime"), ) if _, err := meter.RegisterCallback( func(ctx context.Context, o metric.Observer) error { stats := db.Stats() - o.ObserveInt64(maxOpenConns, int64(stats.MaxOpenConnections), labels...) + o.ObserveInt64(maxOpenConns, int64(stats.MaxOpenConnections), metric.WithAttributes(labels...)) - o.ObserveInt64(openConns, int64(stats.OpenConnections), labels...) - o.ObserveInt64(inUseConns, int64(stats.InUse), labels...) - o.ObserveInt64(idleConns, int64(stats.Idle), labels...) + o.ObserveInt64(openConns, int64(stats.OpenConnections), metric.WithAttributes(labels...)) + o.ObserveInt64(inUseConns, int64(stats.InUse), metric.WithAttributes(labels...)) + o.ObserveInt64(idleConns, int64(stats.Idle), metric.WithAttributes(labels...)) - o.ObserveInt64(connsWaitCount, stats.WaitCount, labels...) - o.ObserveInt64(connsWaitDuration, int64(stats.WaitDuration), labels...) - o.ObserveInt64(connsClosedMaxIdle, stats.MaxIdleClosed, labels...) - o.ObserveInt64(connsClosedMaxIdleTime, stats.MaxIdleTimeClosed, labels...) - o.ObserveInt64(connsClosedMaxLifetime, stats.MaxLifetimeClosed, labels...) + o.ObserveInt64(connsWaitCount, stats.WaitCount, metric.WithAttributes(labels...)) + o.ObserveInt64(connsWaitDuration, int64(stats.WaitDuration), metric.WithAttributes(labels...)) + o.ObserveInt64(connsClosedMaxIdle, stats.MaxIdleClosed, metric.WithAttributes(labels...)) + o.ObserveInt64(connsClosedMaxIdleTime, stats.MaxIdleTimeClosed, metric.WithAttributes(labels...)) + o.ObserveInt64(connsClosedMaxLifetime, stats.MaxLifetimeClosed, metric.WithAttributes(labels...)) return nil },