summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-06-05 10:15:05 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-05 10:15:05 +0200
commitb401bd1ccbce7fa547c75e9f0ae89e211112c1bb (patch)
tree08bf9ed438713e8c390ea60732e7dfc14b0d3191 /vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go
parent[chore]: Bump github.com/minio/minio-go/v7 from 7.0.55 to 7.0.56 (#1869) (diff)
downloadgotosocial-b401bd1ccbce7fa547c75e9f0ae89e211112c1bb.tar.xz
[chore] update latest deps, ensure readme up to date (#1873)
* [chore] update latest deps, ensure readme up to date * remove double entry
Diffstat (limited to 'vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go')
-rw-r--r--vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go50
1 files changed, 24 insertions, 26 deletions
diff --git a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go
index 0932e2759..9bd45afbd 100644
--- a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go
+++ b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/otel.go
@@ -11,8 +11,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"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"
)
@@ -36,7 +34,7 @@ type config struct {
func newConfig(opts []Option) *config {
c := &config{
tracerProvider: otel.GetTracerProvider(),
- meterProvider: global.MeterProvider(),
+ meterProvider: otel.GetMeterProvider(),
}
for _, opt := range opts {
opt(c)
@@ -54,7 +52,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 +70,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 +104,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 +183,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
},