-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Whenever you are using dbconv helpers for metrics, such as ClientConnectionPendingRequests or ClientConnectionTimeouts, the required parameter clientConnectionPoolName is unused when no extra attributes are passed due to an early return.
This can be seen in the code here:
// Add adds incr to the existing count for attrs.
//
// The clientConnectionPoolName is the the name of the connection pool; unique
// within the instrumented application. In case the connection pool
// implementation doesn't provide a name, instrumentation SHOULD use a
// combination of parameters that would make the name unique, for example,
// combining attributes `server.address`, `server.port`, and `db.namespace`,
// formatted as `server.address:server.port/db.namespace`. Instrumentations that
// generate connection pool name following different patterns SHOULD document it.
func (m ClientConnectionTimeouts) Add(
ctx context.Context,
incr int64,
clientConnectionPoolName string,
attrs ...attribute.KeyValue,
) {
if len(attrs) == 0 {
m.Int64Counter.Add(ctx, incr)
return
}
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("db.client.connection.pool.name", clientConnectionPoolName),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}Environment
- Architecture: ARM
- OS: MacOS 15.7.2
- Go Version: 1.25.7
- opentelemetry-go version: v1.40.0
Steps To Reproduce
- Create a dbconv metric, such as
NewClientConnectionTimeouts - Try to register a metric without extra attributes with
Add(ctx, 1, poolName) - Metric is registered without the parameter.
Expected behavior
The pool name should always be used even when no extra attributes are passer OR this behavior should be documented.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working