{"name":"@opentelemetry/instrumentation-pg","version":"0.75.0","keywords":["instrumentation","nodejs","opentelemetry","pg","plugin","postgres","postgresql","profiling","tracing"],"author":{"name":"OpenTelemetry Authors"},"license":"Apache-2.0","_id":"@opentelemetry/instrumentation-pg@0.75.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"},{"name":"overbalance","email":"overbalancedev@proton.me"},{"name":"npmjs-account","email":"npmjs-account@opentelemetry.io"},{"name":"trentm","email":"trentm@gmail.com"},{"name":"martinkuba","email":"martin@martinkuba.com"}],"homepage":"https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-pg#readme","bugs":{"url":"https://github.com/open-telemetry/opentelemetry-js-contrib/issues"},"dist":{"shasum":"7e19a05827b52e3ee0123b81f0da96ce6e58ddf9","tarball":"http://registry-npm.ywwl.com/@opentelemetry/instrumentation-pg/download/@opentelemetry/instrumentation-pg-0.75.0.tgz","fileCount":30,"integrity":"sha512-YleNiIjYYEmIsH5ECDpq15ybFFXgcjdVhnh2vG3ij2xAApBMhgysuKtl6jM/KAelTl6rKZnREhrteGYmGBIPYg==","signatures":[{"sig":"MEUCIE3gJiDzPOuQeBr+eApF0hOhsXsg1MSnkI1wty+A1NmUAiEA3YiGRDuvjfqiDsXfX9Q4VFUuEEZO9QyMYUWhcghnseI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCID97hPDY4uX13T/cwfkS1tnysjgGIVpeYKWaiFcAMv4tAiEAz3r1ockStrM9rooMbJvl2eB402Vhsbfyjx+LaiZ9VO4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2finstrumentation-pg@0.75.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":150936,"size":37715,"noattachment":false,"key":"/@opentelemetry/instrumentation-pg/-/@opentelemetry/instrumentation-pg-0.75.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"cc263ac4e94320402ac3afe50d50eb00905e1bb8","scripts":{"tdd":"npm run test -- --watch-extensions ts --watch","test":"nyc --no-clean mocha 'test/**/*.test.ts'","clean":"rimraf build/*","watch":"tsc -w","compile":"tsc -p .","test:debug":"mocha --inspect-brk --no-timeouts 'test/**/*.test.ts'","lint:readme":"node ../../scripts/lint-readme.js","prepublishOnly":"npm run compile","version:update":"node ../../scripts/version-update.js","test-services:ls":"echo postgres","test-all-versions":"tav","test-services:stop":"cd ../.. && npm run test-services:stop postgres","test-services:start":"cd ../.. && npm run test-services:start postgres","test:with-services-env":"cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test","compile:with-dependencies":"nx run-many -t compile -p @opentelemetry/instrumentation-pg","test-all-versions:with-services-env":"cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"57ad0544-6d40-4157-86cb-737cd3197555"}},"repository":{"url":"git+https://github.com/open-telemetry/opentelemetry-js-contrib.git","type":"git","directory":"packages/instrumentation-pg"},"_npmVersion":"lerna/9.0.7/node@v24.21.0+x64 (linux)","description":"OpenTelemetry instrumentation for `pg` and `pg-pool` database client for PostgreSQL","directories":{},"_nodeVersion":"24.21.0","dependencies":{"@types/pg":"8.15.6","@types/pg-pool":"2.0.7","@opentelemetry/core":"^2.9.0","@opentelemetry/sql-common":"^0.42.0","@opentelemetry/instrumentation":"^0.223.0","@opentelemetry/semantic-conventions":"^1.34.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"pg":"8.7.1","pg-pool":"3.4.1","@opentelemetry/api":"^1.3.0","@opentelemetry/sdk-trace":"^2.9.0","@opentelemetry/contrib-test-utils":"^0.70.0","@opentelemetry/context-async-hooks":"^2.9.0"},"peerDependencies":{"@opentelemetry/api":"^1.3.0"},"_npmOperationalInternal":{"tmp":"tmp/instrumentation-pg_0.75.0_1791300268327_0.8269614498515139","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry Postgres Instrumentation for Node.js\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis module provides automatic instrumentation for the [`pg`](https://github.com/brianc/node-postgres)module.\n\nIf total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](https://www.npmjs.com/package/@opentelemetry/sdk-node) for the most seamless instrumentation experience.\n\nCompatible with OpenTelemetry JS API and SDK `1.0+`.\n\n## Installation\n\n```bash\nnpm install --save @opentelemetry/instrumentation-pg\n```\n\n### Supported Versions\n\n- [`pg`](https://www.npmjs.com/package/pg) versions `>=8.0.3 <9`\n- [`pg-pool`](https://www.npmjs.com/package/pg-pool) versions `>=2.0.0 <4`\n\n## Usage\n\n```js\nconst { NodeSDK } = require('@opentelemetry/sdk-node');\nconst { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');\n\nconst sdk = new NodeSDK({\n  instrumentations: [\n    new PgInstrumentation(),\n  ],\n});\nsdk.start();\nprocess.once('beforeExit', async () => { await sdk.shutdown(); });\n```\n\nPgInstrumentation contains both pg and [`pg.Pool`](https://node-postgres.com/api/pool) so it will be instrumented automatically.\n\n### Span Types Created\n\nThis instrumentation creates the following span types:\n\n| Span Name | Description | When Created |\n| --------- | ----------- | ------------ |\n| `pg.query:<OPERATION> <database>` | Database query execution | When `client.query()` is called |\n| `pg.connect` | Client connection to database | When `new Client().connect()` is called directly |\n| `pg-pool.connect` | Pool connection acquisition wait time | When acquiring a connection from `pg-pool` |\n\nThe `pg-pool.connect` spans measure the time spent waiting to acquire a connection from the pool. This can be valuable for identifying connection pool exhaustion or sizing issues. However, in high-throughput scenarios where connections are readily available, these spans may add noise with minimal diagnostic value. Consider using the `requireParentSpan` option or sampling strategies if pool connect spans become excessive.\n\n### PostgreSQL Instrumentation Options\n\nPostgreSQL instrumentation has few options available to choose from. You can set the following:\n\n| Options | Type | Description |\n| ------- | ---- | ----------- |\n| [`enhancedDatabaseReporting`](./src/types.ts#L30) | `boolean` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations |\n| `requestHook` | `PgInstrumentationExecutionRequestHook` (function) | Function for adding custom span attributes using information about the query being issued and the db to which it's directed |\n| `responseHook` | `PgInstrumentationExecutionResponseHook` (function) | Function for adding custom span attributes from db response |\n| `connectionHook` | `PgInstrumentationConnectionHook` (function) | Function for adding custom span attributes to `pg.connect` and `pg-pool.connect` spans using information about the db being connected to. Not called when `ignoreConnectSpans` is true |\n| `requireParentSpan` | `boolean` | If true, requires a parent span to create new spans (default false) |\n| `addSqlCommenterCommentToQueries` | `boolean` | If true, adds [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) specification compliant comment to queries with tracing context (default false). _NOTE: A comment will not be added to queries that already contain `--` or `/* ... */` in them, even if these are not actually part of comments_ |\n| `ignoreConnectSpans` | `boolean` | If true, `pg.connect` and `pg-pool.connect` spans will not be created. Query spans and pool metrics are still recorded (default false) |\n\n## Semantic Conventions\n\nThe `@opentelemetry/instrumentation-pg` versions 0.72.0 and later emit the stable v1.34.0+ semantic conventions.\n\n### Attributes collected\n\n| Attribute             | Short Description                                                                          |\n| --------------------- | ------------------------------------------------------------------------------------------ |\n| `db.system.name`      | The database management system (DBMS) product as identified by the client instrumentation. |\n| `db.namespace`        | The name of the database, fully qualified within the server address and port.              |\n| `db.query.text`       | The database query being executed.                                                         |\n| `db.operation.name`   | The name of the operation or command being executed.                                       |\n| `server.address`      | Remote hostname or similar.                                                                |\n| `server.port`         | Remote port number.                                                                        |\n| `error.type`          | Describes a class of error the operation ended with.                                       |\n\n> [!NOTE]\n> `db.collection.name` is not collected. The `pg` driver does not expose the table\n> name separately, and the OpenTelemetry specification advises against parsing\n> `db.query.text` when the database supports queries touching multiple\n> collections in non-batch operations, which is the case for PostgreSQL.\n\nMetrics Exported:\n\n- [`db.client.operation.duration`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md#metric-dbclientoperationduration)\n- [`db.client.connection.count`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md#metric-dbclientconnectioncount)\n- [`db.client.connection.max`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md#metric-dbclientconnectionmax)\n- [`db.client.connection.pending_requests`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md#metric-dbclientconnectionpending_requests)\n\n## Useful links\n\n- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>\n- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>\n- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]\n\n## License\n\nApache 2.0 - See [LICENSE][license-url] for more information.\n\n[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions\n[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-pg\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-pg.svg\n","publish_time":1791300268416,"_cnpm_publish_time":1791300268416,"dist-tags":{"latest":"0.78.0"}}