Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ const (
// RecordStats records database statistics for provided pgxpool.Pool at a default 1 second interval
// unless otherwise specified by the WithMinimumReadDBStatsInterval StatsOption.
func RecordStats(db PoolStats, opts ...StatsOption) error {
serverAddress := semconv.ServerAddress(db.Config().ConnConfig.Host)
serverPort := semconv.ServerPort(int(db.Config().ConnConfig.Port))
dbNamespace := semconv.DBNamespace(db.Config().ConnConfig.Database)
poolName := fmt.Sprintf("%s:%d/%s", serverAddress.Value.AsString(), serverPort.Value.AsInt64(), dbNamespace.Value.AsString())
dbClientConnectionPoolName := semconv.DBClientConnectionPoolName(poolName)

o := statsOptions{
meterProvider: otel.GetMeterProvider(),
minimumReadDBStatsInterval: defaultMinimumReadDBStatsInterval,
defaultAttributes: []attribute.KeyValue{
semconv.DBSystemPostgreSQL,
dbClientConnectionPoolName,
},
}

Expand Down Expand Up @@ -93,12 +100,6 @@ func recordStats(
lock sync.Mutex
)

serverAddress := semconv.ServerAddress(db.Config().ConnConfig.Host)
serverPort := semconv.ServerPort(int(db.Config().ConnConfig.Port))
dbNamespace := semconv.DBNamespace(db.Config().ConnConfig.Database)
poolName := fmt.Sprintf("%s:%d/%s", serverAddress.Value.AsString(), serverPort.Value.AsInt64(), dbNamespace.Value.AsString())
dbClientConnectionPoolName := semconv.DBClientConnectionPoolName(poolName)

lock.Lock()
defer lock.Unlock()

Expand Down Expand Up @@ -195,11 +196,6 @@ func recordStats(
return fmt.Errorf("failed to create asynchronous metric: %s with error: %w", pgxPoolEmptyAcquireWaitTime, err)
}

attrs = append(attrs, []attribute.KeyValue{
semconv.DBSystemPostgreSQL,
dbClientConnectionPoolName,
}...)

observeOptions = []metric.ObserveOption{
metric.WithAttributeSet(attribute.NewSet(attrs...)),
}
Expand Down