{"name":"@opentelemetry/instrumentation-pg","version":"0.60.0","keywords":["instrumentation","nodejs","opentelemetry","pg","plugin","postgres","postgresql","profiling","tracing"],"author":{"name":"OpenTelemetry Authors"},"license":"Apache-2.0","_id":"@opentelemetry/instrumentation-pg@0.60.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.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":"a3aa5533699ddf325df91315e2dc1bfc4c812346","tarball":"http://registry-npm.ywwl.com/@opentelemetry/instrumentation-pg/download/@opentelemetry/instrumentation-pg-0.60.0.tgz","fileCount":30,"integrity":"sha512-qZKeQojYJMoo7kWbHw/+SHopSdhfTxNISsBS+ZBbkr44sepmk/PmyU2AbOsSK7VOKvFt3oZde2n2nly7rk0SsA==","signatures":[{"sig":"MEYCIQCH6T7+LDmWtRIpxUHTuLcw3a43b+IBQETXBfbxXL+OXQIhAKLLjVtU/rICtkGM0aoeaBOVOtY/GiWpLDtw2tl6pZwm","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2finstrumentation-pg@0.60.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":156447,"size":36540,"noattachment":false,"key":"/@opentelemetry/instrumentation-pg/-/@opentelemetry/instrumentation-pg-0.60.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"2801ab2f0f9243b154a624298dacb7228c4f70cd","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-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":"oidc: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.0/node@v24.10.0+x64 (linux)","description":"OpenTelemetry instrumentation for `pg` and `pg-pool` database client for PostgreSQL","directories":{},"_nodeVersion":"24.10.0","dependencies":{"@types/pg":"8.15.5","@types/pg-pool":"2.0.6","@opentelemetry/core":"^2.0.0","@opentelemetry/sql-common":"^0.41.2","@opentelemetry/instrumentation":"^0.207.0","@opentelemetry/semantic-conventions":"^1.34.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"pg":"8.7.1","nyc":"17.1.0","sinon":"15.2.0","rimraf":"5.0.10","pg-pool":"3.4.1","cross-env":"7.0.3","typescript":"5.0.4","@types/node":"18.18.14","@types/mocha":"10.0.10","@types/sinon":"17.0.4","test-all-versions":"6.1.0","@opentelemetry/api":"^1.3.0","safe-stable-stringify":"^2.4.1","@opentelemetry/sdk-trace-base":"^2.0.0","@opentelemetry/sdk-trace-node":"^2.0.0","@opentelemetry/contrib-test-utils":"^0.54.0","@opentelemetry/context-async-hooks":"^2.0.0"},"peerDependencies":{"@opentelemetry/api":"^1.3.0"},"_npmOperationalInternal":{"tmp":"tmp/instrumentation-pg_0.60.0_1761062477898_0.7778103530607445","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| `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":1761062478123,"_cnpm_publish_time":1761062478123,"dist-tags":{"latest":"0.78.0"}}