Skip to content

Dbconv dont use pool name when no extra attributes are provided #7938

@victoraugustolls

Description

@victoraugustolls

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

  1. Create a dbconv metric, such as NewClientConnectionTimeouts
  2. Try to register a metric without extra attributes with Add(ctx, 1, poolName)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions