From 093a73826bf4fa2b526c331747e3b33ac86993a5 Mon Sep 17 00:00:00 2001 From: Mark Wolff Date: Thu, 26 Dec 2019 13:35:33 -0500 Subject: [PATCH] chore(docs:postgres): add usage instructions (#539) * chore(docs:postgres): add usage instructions * docs: add pg-pool install * docs: add pg-pool version Co-authored-by: Valentin Marchaud --- .../opentelemetry-plugin-pg/README.md | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) 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: