Skip to content

Commit

Permalink
chore: prefer use of global TracerProvider/MeterProvider (#450)
Browse files Browse the repository at this point in the history
Remove setting of TracerProvider in samples where it is actually not needed as the global TracerProvider should be preferred on default.

I found it also inconsistent to set a TracerProvider but no MeterProvider.

Co-authored-by: Daniel Dyla <[email protected]>
Co-authored-by: Valentin Marchaud <[email protected]>
Co-authored-by: Naseem <[email protected]>
  • Loading branch information
4 people authored Apr 26, 2021
1 parent 862ab4e commit 041508f
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 67 deletions.
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-node/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OpenTelemetry Meta Packages for Node

[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
Expand Down
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-web/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OpenTelemetry Meta Packages for Web

[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm install --save @opentelemetry/instrumentation-aws-lambda
## Usage

Create a file to initialize the instrumentation, such as `lambda-wrapper.js`.

```js
const { NodeTracerProvider } = require('@opentelemetry/node');
const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');
Expand All @@ -30,7 +31,6 @@ registerInstrumentations({
instrumentations: [
new AwsLambdaInstrumentation()
],
tracerProvider: provider,
});
```

Expand Down
8 changes: 4 additions & 4 deletions plugins/node/opentelemetry-instrumentation-bunyan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ registerInstrumentations({
}),
// other instrumentations
],
tracerProvider: provider,
});

bunyan.createLogger({ name: 'example' }).info('foo');
Expand All @@ -44,6 +43,7 @@ bunyan.createLogger({ name: 'example' }).info('foo');
### Fields added to bunyan records

For the current active span, the following will be added to the bunyan record:

* `trace_id`
* `span_id`
* `trace_flags`
Expand All @@ -52,9 +52,9 @@ When no span context is active or the span context is invalid, injection is skip

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
* For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
* For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
* For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

## License

Expand Down
1 change: 0 additions & 1 deletion plugins/node/opentelemetry-instrumentation-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ registerInstrumentations({
// see under for available configuration
}),
],
tracerProvider: provider,
});
```

Expand Down
5 changes: 3 additions & 2 deletions plugins/node/opentelemetry-instrumentation-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ npm install --save @opentelemetry/instrumentation-http @opentelemetry/instrument
```

### Supported Versions
- `^4.0.0`

- `^4.0.0`

## Usage

Expand All @@ -42,7 +43,6 @@ registerInstrumentations({
new HttpInstrumentation(),
new ExpressInstrumentation(),
],
tracerProvider: provider,
});
```

Expand Down Expand Up @@ -74,6 +74,7 @@ Express instrumentation has few options available to choose from. You can set th
- `request_handler` is the name for anything that's not a router or a middleware.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ registerInstrumentations({
// mergeItems: true,
}),
],
tracerProvider: provider,
});

```
Expand Down
29 changes: 9 additions & 20 deletions plugins/node/opentelemetry-instrumentation-hapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ For automatic instrumentation see the
```bash
npm install --save @opentelemetry/instrumentation-hapi
```

### Supported Versions
- @hapi/hapi `^17.0.0`

- @hapi/hapi `^17.0.0`

## Usage

Expand All @@ -27,12 +29,15 @@ To load a specific instrumentation (Hapi in this case), specify it in the regist
```js
const { NodeTracerProvider } = require('@opentelemetry/node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new HapiInstrumentation(),
],
});
```

Expand All @@ -48,34 +53,18 @@ const hapiInstrumentation = new HapiInstrumentation();
hapiInstrumentation.setTracerProvider(provider);
```

You can combine loading default plugins and HapiInstrumentation at the same time:

```js
const { NodeTracerProvider } = require('@opentelemetry/node');
const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
instrumentations: [
new HapiInstrumentation(),
],
tracerProvider: provider,
});
```

See [examples/hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/hapi) for a short example using Hapi

<!--
The dev dependency of `@hapi/[email protected]` is required to force the compatible type declarations. See: https://github.com/hapijs/hapi/issues/4240
-->

## Hapi Instrumentation Support

This package provides automatic tracing for hapi server routes and [request lifecycle](https://github.com/hapijs/hapi/blob/main/API.md#request-lifecycle) extensions defined either directly or via a Hapi plugin.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
4 changes: 2 additions & 2 deletions plugins/node/opentelemetry-instrumentation-ioredis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ registerInstrumentations({
// see under for available configuration
})
],
tracerProvider: provider,
})
```

Expand All @@ -52,7 +51,8 @@ IORedis instrumentation has few options available to choose from. You can set th
| `responseHook` | `RedisResponseCustomAttributeFunction` | Function for adding custom attributes on db response |
| `requireParentSpan` | `boolean` | Require parent to create ioredis span, default when unset is true |

#### Custom db.statement Serializer
#### Custom db.statement Serializer

The instrumentation serializes the whole command into a Span attribute called `db.statement`. The standard serialization format is `{cmdName} {cmdArgs.join(',')}`.
It is also possible to define a custom serialization function. The function will receive the command name and arguments and must return a string.

Expand Down
6 changes: 4 additions & 2 deletions plugins/node/opentelemetry-instrumentation-koa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ For automatic instrumentation see the
```bash
npm install --save @opentelemetry/instrumentation-koa
```

### Supported Versions
- Koa `^2.0.0`

- Koa `^2.0.0`

## Usage

Expand All @@ -34,7 +36,6 @@ registerInstrumentations({
instrumentations: [
new KoaInstrumentation(),
],
tracerProvider: provider,
});
```

Expand All @@ -45,6 +46,7 @@ See [examples/koa](https://github.com/open-telemetry/opentelemetry-js-contrib/tr
This package provides automatic tracing for middleware added using either the core [`Koa`](https://github.com/koajs/koa) package or the [`@koa/router`](https://github.com/koajs/router) package.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
4 changes: 2 additions & 2 deletions plugins/node/opentelemetry-instrumentation-mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For automatic instrumentation see the
```bash
npm install --save @opentelemetry/instrumentation-mongodb
```

### Supported Versions
- `'>=3.3 <4`

Expand All @@ -38,7 +39,6 @@ registerInstrumentations({
// see under for available configuration
}),
],
tracerProvider: provider,
});

```
Expand All @@ -51,8 +51,8 @@ Mongodb instrumentation has few options available to choose from. You can set th
| ------- | ---- | ----------- |
| [`enhancedDatabaseReporting`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-api/src/trace/instrumentation/instrumentation.ts#L91) | `string` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations |


## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
4 changes: 3 additions & 1 deletion plugins/node/opentelemetry-instrumentation-mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ npm install --save @opentelemetry/instrumentation-mysql
```

## Supported Versions

- `2.x`

## Usage

OpenTelemetry MySQL Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with [mysql](https://www.npmjs.com/package/mysql).

To load a specific plugin (**MySQL** in this case), specify it in the registerInstrumentations's configuration

```js
const { NodeTracerProvider } = require('@opentelemetry/node');
const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql');
Expand All @@ -36,13 +38,13 @@ registerInstrumentations({
instrumentations: [
new MySQLInstrumentation(),
],
tracerProvider: provider,
})
```

See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/mysql) for a short example.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
8 changes: 4 additions & 4 deletions plugins/node/opentelemetry-instrumentation-net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ registerInstrumentations({
new NetInstrumentation(),
// other instrumentations
],
tracerProvider: provider,
});
```

Expand All @@ -39,16 +38,17 @@ registerInstrumentations({
* `net.peer.name`: host name or the IPC file path

For TCP:

* `net.peer.ip`
* `net.peer.port`
* `net.host.ip`
* `net.host.port`

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
* For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
* For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
* For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

## License

Expand Down
5 changes: 4 additions & 1 deletion plugins/node/opentelemetry-instrumentation-net/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import { IPC_TRANSPORT } from '../src/utils';

export const PORT = 42123;
export const HOST = 'localhost';
export const IPC_PATH = path.join(os.tmpdir(), 'otel-js-net-test-ipc');
export const IPC_PATH =
os.platform() !== 'win32'
? path.join(os.tmpdir(), 'otel-js-net-test-ipc')
: '\\\\.\\pipe\\otel-js-net-test-ipc';

export function assertTcpSpan(span: ReadableSpan, socket: Socket) {
assertSpanKind(span);
Expand Down
3 changes: 2 additions & 1 deletion plugins/node/opentelemetry-instrumentation-pg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
instrumentations: [
new PgInstrumentation(),
],
tracerProvider: provider,
});
```

Expand All @@ -53,6 +53,7 @@ PostgreSQL instrumentation has few options available to choose from. You can set
- [pg-pool](https://npmjs.com/package/pg-pool): `2.x`, `3.*` (Installed by `pg`)

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
8 changes: 4 additions & 4 deletions plugins/node/opentelemetry-instrumentation-pino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ registerInstrumentations({
}),
// other instrumentations
],
tracerProvider: provider,
});

const pino = require('pino');
Expand All @@ -45,6 +44,7 @@ logger.info('foobar');
### Fields added to pino log objects

For the current active span, the following fields are injected:

* `trace_id`
* `span_id`
* `trace_flags`
Expand All @@ -57,9 +57,9 @@ When no span context is active or the span context is invalid, injection is skip

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
* For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
* For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
* For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

## License

Expand Down
8 changes: 5 additions & 3 deletions plugins/node/opentelemetry-instrumentation-redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ For automatic instrumentation see the

## Installation

```
```bash
npm install --save @opentelemetry/instrumentation-redis
```

### Supported Versions
- `>=2.6.0`

- `>=2.6.0`

## Usage

OpenTelemetry Redis Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with [redis](https://www.npmjs.com/package/redis).

To load a specific instrumentation (**redis** in this case), specify it in the registerInstrumentations' configuration

```javascript
const { NodeTracerProvider } = require('@opentelemetry/node');
const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis');
Expand All @@ -36,13 +38,13 @@ registerInstrumentations({
instrumentations: [
new RedisInstrumentation(),
],
tracerProvider: provider,
})
```

See [examples/redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/redis) for a short example.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
Expand Down
Loading

0 comments on commit 041508f

Please sign in to comment.