diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/README.md b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/README.md index 985e82bc5f..ba0627c815 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/README.md +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/README.md @@ -13,19 +13,62 @@ For automatic instrumentation see the ```bash npm install --save @opentelemetry/plugin-pg +npm install --save @opentelemetry/plugin-pg-pool ``` ## Usage +To load all of the [default supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use the below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugsin for unused modules. + +```js +const { NodeTracer } = require('@opentelemetry/node'); + +const tracer = new NodeTracer(); // All default plugins will be used +``` + +If instead you would just load a specific plugin (**pg** in this case), specify it in the `NodeTracer` configuration. + ```js -const opentelemetry = require('@opentelemetry/plugin-pg'); +const { NodeTracer } = require('@opentelemetry/node'); -// TODO: DEMONSTRATE API +const tracer = new NodeTracer({ + plugins: { + pg: { + enabled: true, + // You may use a package name or absolute path to the module + path: '@opentelemetry/plugin-pg', + } + } +}); ``` +If you are using any of the [`pg.Pool`](https://node-postgres.com/api/pool) APIs, you will also need to include the [`pg-pool` plugin](../opentelemetry-plugin-pg-pool). + +```js +const { NodeTracer } = require('@opentelemetry/node'); + +const tracer = new NodeTracer({ + plugins: { + pg: { + enabled: true, + // You may use a package name or absolute path to the module + path: '@opentelemetry/plugin-pg', + }, + 'pg-pool': { + enabled: true, + // You may use a package name or absolute path to the module + path: '@opentelemetry/plugin-pg-pool', + }, + } +}); +``` + +See [examples/postgres](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/postgres) for a short example. + ## Supported Versions - [pg](https://npmjs.com/package/pg): `7.x` +- [pg-pool](https://npmjs.com/package/pg-pool): `2.x` (Installed by `pg`) ## Useful links - For more information on OpenTelemetry, visit: