Skip to content

Commit 093a738

Browse files
markwolffvmarchaud
authored andcommitted
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 <[email protected]>
1 parent 3ca2df4 commit 093a738

File tree

1 file changed

+45
-2
lines changed
  • packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg

1 file changed

+45
-2
lines changed

packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,62 @@ For automatic instrumentation see the
1313

1414
```bash
1515
npm install --save @opentelemetry/plugin-pg
16+
npm install --save @opentelemetry/plugin-pg-pool
1617
```
1718

1819
## Usage
1920

21+
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.
22+
23+
```js
24+
const { NodeTracer } = require('@opentelemetry/node');
25+
26+
const tracer = new NodeTracer(); // All default plugins will be used
27+
```
28+
29+
If instead you would just load a specific plugin (**pg** in this case), specify it in the `NodeTracer` configuration.
30+
2031
```js
21-
const opentelemetry = require('@opentelemetry/plugin-pg');
32+
const { NodeTracer } = require('@opentelemetry/node');
2233

23-
// TODO: DEMONSTRATE API
34+
const tracer = new NodeTracer({
35+
plugins: {
36+
pg: {
37+
enabled: true,
38+
// You may use a package name or absolute path to the module
39+
path: '@opentelemetry/plugin-pg',
40+
}
41+
}
42+
});
2443
```
2544

45+
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).
46+
47+
```js
48+
const { NodeTracer } = require('@opentelemetry/node');
49+
50+
const tracer = new NodeTracer({
51+
plugins: {
52+
pg: {
53+
enabled: true,
54+
// You may use a package name or absolute path to the module
55+
path: '@opentelemetry/plugin-pg',
56+
},
57+
'pg-pool': {
58+
enabled: true,
59+
// You may use a package name or absolute path to the module
60+
path: '@opentelemetry/plugin-pg-pool',
61+
},
62+
}
63+
});
64+
```
65+
66+
See [examples/postgres](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/postgres) for a short example.
67+
2668
## Supported Versions
2769

2870
- [pg](https://npmjs.com/package/pg): `7.x`
71+
- [pg-pool](https://npmjs.com/package/pg-pool): `2.x` (Installed by `pg`)
2972

3073
## Useful links
3174
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

0 commit comments

Comments
 (0)