Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prefer use of global TracerProvider/MeterProvider #2127

Merged
merged 8 commits into from
Apr 23, 2021
1 change: 0 additions & 1 deletion examples/grpc-js/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = (serviceName) => {
instrumentations: [
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

let exporter;
Expand Down
1 change: 0 additions & 1 deletion examples/grpc/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new GrpcInstrumentation(),
],
Expand Down
1 change: 0 additions & 1 deletion examples/http/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// // when boostraping with lerna for testing purposes
instrumentations: [
new HttpInstrumentation(),
Expand Down
1 change: 0 additions & 1 deletion examples/https/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = (serviceName) => {
let exporter;
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new HttpInstrumentation(),
],
Expand Down
1 change: 0 additions & 1 deletion examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { TracerShim } = require('@opentelemetry/shim-opentracing');
function shim(serviceName) {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
Expand Down
3 changes: 1 addition & 2 deletions examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ registerInstrumentations({
'https://cors-test.appspot.com/test',
'https://httpbin.org/get',
],
clearTimingResources: true
clearTimingResources: true,
}),
],
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
Expand Down
1 change: 0 additions & 1 deletion examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ registerInstrumentations({
],
}),
],
tracerProvider: providerWithZone,
});

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
Expand Down
6 changes: 2 additions & 4 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This guide walks you through the setup and configuration process for a tracing b

- [Getting started with OpenTelemetry JS](#getting-started-with-opentelemetry-js)
- [Trace your application with OpenTelemetry](#trace-your-application-with-opentelemetry)
- [Set up a Tracing Backend](#set-up-a-tracing-backend)
- [Trace Your NodeJS Application](#trace-your-nodejs-application)
- [Set up a tracing backend](#set-up-a-tracing-backend)
- [Trace your NodeJS application](#trace-your-nodejs-application)
- [Install the required OpenTelemetry libraries](#install-the-required-opentelemetry-libraries)
- [Initialize a global tracer](#initialize-a-global-tracer)
- [Initialize and register a trace exporter](#initialize-and-register-a-trace-exporter)
Expand Down Expand Up @@ -92,7 +92,6 @@ registerInstrumentations({
new HttpInstrumentation(),
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

```
Expand Down Expand Up @@ -153,7 +152,6 @@ registerInstrumentations({
new HttpInstrumentation(),
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

console.log("tracing initialized");
Expand Down
1 change: 0 additions & 1 deletion getting-started/traced-example/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ provider.register();

// load old default plugins
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
2 changes: 0 additions & 2 deletions getting-started/ts-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const provider: NodeTracerProvider = new NodeTracerProvider({
provider.register();

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down Expand Up @@ -153,7 +152,6 @@ provider.addSpanProcessor(
);

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
1 change: 0 additions & 1 deletion getting-started/ts-example/traced-example/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ provider.addSpanProcessor(
);

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-instrumentation-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ provider.register({

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

// or plugin can be also initialised separately and then set the tracer provider or meter provider
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-instrumentation-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ provider.register();

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

```
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-instrumentation-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ provider.register();

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

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ registerInstrumentations({
propagateTraceHeaderCorsUrls: ['http://localhost:8090']
}),
],
tracerProvider: provider,
});


Expand Down
20 changes: 15 additions & 5 deletions packages/opentelemetry-instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class MyPlugin extends InstrumentationBase {
// Later

const myPLugin = new MyPlugin();
myPLugin.setTracerProvider(provider); // this is optional
myPLugin.setTracerProvider(provider); // this is optional, only if global TracerProvider shouldn't be used
myPLugin.setMeterProvider(meterProvider); // this is optional
myPLugin.enable();
// or use Auto Loader
Expand Down Expand Up @@ -151,8 +151,8 @@ export class MyPlugin extends InstrumentationBase {
// Later

const myPLugin = new MyPlugin();
myPLugin.setTracerProvider(provider);
myPLugin.setMeterProvider(meterProvider);
myPLugin.setTracerProvider(provider); // this is optional, only if global TracerProvider shouldn't be used
myPLugin.setMeterProvider(meterProvider); // this is optional, only if global MeterProvider shouldn't be used
myPLugin.enable();
// or use Auto Loader
```
Expand Down Expand Up @@ -221,7 +221,8 @@ registerInstrumentations({
instrumentations: [
new HttpInstrumentation(),
],
tracerProvider: tracerProvider,
//tracerProvider: tracerProvider, // optional, only if global TracerProvider shouldn't be used
//meterProvider: meterProvider, // optional, only if global MeterProvider shouldn't be used
});

```
Expand Down Expand Up @@ -249,10 +250,19 @@ registerInstrumentations({
],
}),
],
tracerProvider: tracerProvider,
//tracerProvider: tracerProvider, // optional, only if global TracerProvider shouldn't be used
//meterProvider: meterProvider, // optional, only if global MeterProvider shouldn't be used
});
```

## Selection of the used TracerProvider/MeterProvider

The `registerInstrumentations()` API allows to specify which `TracerProvider` and/or `MeterProvider` to use by the given options object.
If nothing is specified the global registered provider is used. Usually this is what most users want therefore it's recommended to keep this default.

There might be usecase where someone has the need for more providers within an application. Please note that special care must be takes in such setups
to avoid leaking information from one provider to the other because there are a lot places where e.g. the global `ContextManager` or `Propagator` is used.

## License

Apache 2.0 - See [LICENSE][license-url] for more information.
Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ provider.register();
// register and load instrumentation and old plugins - old plugins will be loaded automatically as previously
// but instrumentations needs to be added
registerInstrumentations({
tracerProvider: provider,
});

// Your application code - http will automatically be instrumented if
Expand All @@ -88,7 +87,6 @@ const provider = new NodeTracerProvider();
// register and load instrumentation and old plugins - old plugins will be loaded automatically as previously
// but instrumentations needs to be added
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation({
Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ export class NodeSDK {

registerInstrumentations({
vmarchaud marked this conversation as resolved.
Show resolved Hide resolved
instrumentations: this._instrumentations,
tracerProvider: this._tracerProvider,
meterProvider: this._meterProvider,
});
}

Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ registerInstrumentations({
instrumentations: [
new DocumentLoad(),
],
tracerProvider: provider,
});

```
Expand Down