open-telemetry / opentelemetry-js-contrib

OpenTelemetry instrumentation for JavaScript modules
https://opentelemetry.io
Apache License 2.0
683 stars 497 forks source link

instrumentation-pg records wrong db.connection_string when pg.Pool is configured by connectionString #1415

Open orangain opened 1 year ago

orangain commented 1 year ago

What version of OpenTelemetry are you using?

├── @opentelemetry/api@1.4.0
├── @opentelemetry/exporter-jaeger@1.9.1
├── @opentelemetry/exporter-zipkin@1.9.1
├── @opentelemetry/instrumentation-http@0.35.1
├── @opentelemetry/instrumentation-pg@0.34.1
├── @opentelemetry/instrumentation@0.35.1
├── @opentelemetry/sdk-trace-base@1.9.1
├── @opentelemetry/sdk-trace-node@1.9.1

What version of Node are you using?

v16.19.0

What did you do?

I set up auto instrumentation of an application using pg.Pool. In the application, pg.Pool was configured by connectionString like this:

const pool = new Pool({
  connectionString: "postgresql://postgres:postgres@localhost:54320/postgres"
})

Then I launched the application and found a trace having wrong value of db.connection_string.

Repro application is available at: https://github.com/orangain/opentelemetry-js-contrib/tree/spike-address-pg-pool-issue/examples/postgres

Complete recipe to reproduce

git clone -b spike-address-pg-pool-issue https://github.com/orangain/opentelemetry-js-contrib
cd opentelemetry-js-contrib/examples/postgres
npm install
# Launch PostgreSQL
npm run docker:start
# Launch Jaeger
docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.42
# Launch Server
npm run jaeger:server

After launching the server, open http://localhost:16686 in a browser, and you will see the Jaeger UI. Then select unknown_service:node from "Service" dropdown and click "Find Traces" button.

What did you expect to see?

The span pg-pool.connect contains a tag db.connection_string and its value is postgresql://localhost:54320/postgres.

What did you see instead?

The span pg-pool.connect contains a tag db.connection_string and its value is postgresql://localhost:5432/. The port number is wrong and the database name does not exist.

image

Additional context

Note that the child span pg.connect contains a tag db.connection_string and its value is postgresql://localhost:54320/postgres as expected.

image

https://github.com/open-telemetry/opentelemetry-js-contrib/issues/782 is a similar issue but it seems to be a different situation.

pichlermarc commented 1 year ago

@haddasbronfman do you maybe have some more context on this? :slightly_smiling_face:

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.