Skip to content

@opentelemetry/instrumentation-pg: multiple pools cause db.client.connection.count to be recorded incorrectly #3354

@sfozz

Description

@sfozz

What version of OpenTelemetry are you using?

"@opentelemetry/api": "^1.9.0"
"@opentelemetry/auto-instrumentations-node": "^0.67.0"
"@opentelemetry/core": "^2.2.0"
"@opentelemetry/sdk-metrics": "^2.2.0"
"@opentelemetry/sdk-node": "^0.208.0"
"@opentelemetry/sdk-trace-node": "^2.2.0"

What version of Node are you using?

22.17.1

What did you do?

We are using instrumentation-pg via auto instrumentation to monitor the connections to a db. One of our services has 2 connection pools (different dbs soon to be different schema in the same db) but is looks like the counters are not working as expected. One of the pools connection counters just seems to increment where as the other just decrements.

db.client.connection.count{pool=poolA,state=used} 47
db.client.connection.count{pool=poolB,state=used} -47 

The pool only has a maximum size of 10, so it should never get beyond that.
Other services with only one pool are not impacted and are reporting fine

We are using FoalTS v5

OTEL Config

OTEL_SERVICE_NAME=our-api
OTEL_TRACES_SAMPLER=parentbased_always_off
OTEL_EXPORTER_OTLP_ENDPOINT=http://opentelemetry-kube-stack-collector:4318
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_SEMCONV_STABILITY_OPT_IN=http
OTEL_NODE_RESOURCE_DETECTORS=env,host,os
OTEL_LOGS_EXPORTER=none
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod,service.version=production

What did you expect to see?

for the default pool size I would expect the used count to go up to at most 10 and reduce as used connections are returned the the pool

What did you see instead?

That one pool always increments and the other pool always decrements

Image

Additional context

Will supply example code

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpkg:instrumentation-pgpriority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions