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

Use instrumentation loader to load plugins and instrumentations #1855

Merged
merged 8 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/request_for_instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ labels: instrumentation
---

<!--
**NB:** Before opening a plugin support request against this repo, consider whether the plugin should reside in the [contrib repository](https://github.com/open-telemetry/opentelemetry-js-contrib).
**NB:** Before opening an instrumentation support request against this repo, consider whether the instrumentation should reside in the [contrib repository](https://github.com/open-telemetry/opentelemetry-js-contrib).

You are welcome to try out the [plugin api](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/plugin-guide.md) to build your own plugin. If you do try out the plugin api, please let us know if you have any questions/feedback.
You are welcome to try out the [instrumentation api](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/instrumentation-guide.md) to build your own instrumentation. If you do try out the instrumentation api, please let us know if you have any questions/feedback.
-->

### Is it applicable for Node or Browser or both
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@ OpenTelemetry is vendor-agnostic and can upload data to any backend with various

See the [OpenTelemetry registry](https://opentelemetry.io/registry/?s=node.js) for a list of exporters available.

### Plugins
### Instrumentations & Plugins

OpenTelemetry can collect tracing data automatically using plugins. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for:
OpenTelemetry can collect tracing data automatically using instrumentations. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for:

#### Node Plugins
#### Node Instrumentations & Plugins

##### Core

- [@opentelemetry/plugin-grpc][otel-plugin-grpc]
- [@opentelemetry/instrumentation-grpc][otel-instrumentation-grpc] previous [@opentelemetry/plugin-grpc][otel-plugin-grpc]
- [@opentelemetry/plugin-grpc-js][otel-plugin-grpc-js]
- [@opentelemetry/plugin-http][otel-plugin-http]
- [@opentelemetry/plugin-https][otel-plugin-https]
- [@opentelemetry/instrumentation-http][otel-plugin-http] previous [@opentelemetry/plugin-http][otel-plugin-http] and [@opentelemetry/plugin-https][otel-plugin-https]

##### Contrib

Expand All @@ -216,7 +215,7 @@ These plugins are hosted at <https://github.com/open-telemetry/opentelemetry-js-
##### Core

- [@opentelemetry/instrumentation-xml-http-request][otel-instrumentation-xml-http-request]
- [@opentelemetry/plugin-fetch][otel-plugin-fetch]
- [@opentelemetry/instrumentation-fetch][otel-instrumentation-fetch]

##### Contrib

Expand All @@ -225,7 +224,7 @@ These plugins are hosted at <https://github.com/open-telemetry/opentelemetry-js-
- [@opentelemetry/plugin-document-load][otel-contrib-plugin-document-load]
- [@opentelemetry/plugin-user-interaction][otel-contrib-plugin-user-interaction]

To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, you can [write a plugin yourself](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/plugin-guide.md).
To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, you can [write an instrumentation yourself](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/instrumentation-guide.md).

### Shims

Expand Down Expand Up @@ -276,11 +275,15 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[otel-metrics]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics
[otel-node]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node

[otel-plugin-fetch]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-fetch
[otel-plugin-grpc]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-grpc
[otel-plugin-grpc-js]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-grpc-js
[otel-plugin-http]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-http
[otel-plugin-https]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-https

[otel-instrumentation-fetch]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation-fetch
[otel-instrumentation-grpc]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation-grpc
[otel-instrumentation-http]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation-http
[otel-instrumentation-https]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation-https
[otel-instrumentation-xml-http-request]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation-xml-http-request

[otel-shim-opentracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-shim-opentracing
Expand Down
7 changes: 3 additions & 4 deletions doc/plugin-guide.md → doc/instrumentation-guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plugin Developer Guide
# Instrumentation Developer Guide

The `NodeTracerProvider` or `Node-SDK` is driven by a set of plugins that describe how to patch a module to generate trace spans when that module is used. We provide out-of-the-box instrumentation for many popular frameworks and libraries by using a plugin system (see [builtin plugins][builtin-plugins]), and provide a means for developers to create their own.
We provide out-of-the-box instrumentations for many popular frameworks and libraries by using an instrumentation system (see [builtin instrumentations][builtin-instrumentations]), and provide a means for developers to create their own.

We strongly recommended to create a dedicated package for newly added plugin, example: `@opentelemetry/plugin-xxx`.

Expand Down Expand Up @@ -45,8 +45,7 @@ We recommend using [`shimmer`][shimmer] to modify function properties on objects
Please refer to the [HTTP instrumentation][http-plugin] or [gRPC instrumentation][grpc-plugin] for more comprehensive examples.

[shimmer]: https://github.com/othiym23/shimmer
[builtin-plugins]: https://github.com/open-telemetry/opentelemetry-js#plugins
[base-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-core/src/platform/node/BasePlugin.ts
[builtin-instrumentations]: https://github.com/open-telemetry/opentelemetry-js#instrumentations&plugins
[http-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-http/src/http.ts#L44
[grpc-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-grpc/src/grpc.ts#L52
[DEFAULT_INSTRUMENTATION_PLUGINS]: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-node/src/config.ts#L29
2 changes: 1 addition & 1 deletion examples/grpc-js/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const api = require('@opentelemetry/api');
const tracer = require('./tracer')('example-grpc-client');
const tracer = require('./tracer')('example-grpc-js-client');
// eslint-disable-next-line import/order
const grpc = require('@grpc/grpc-js');
const messages = require('./helloworld_pb');
Expand Down
1 change: 1 addition & 0 deletions examples/grpc-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@opentelemetry/api": "^0.15.0",
"@opentelemetry/exporter-jaeger": "^0.15.0",
"@opentelemetry/exporter-zipkin": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/node": "^0.15.0",
"@opentelemetry/plugin-grpc-js": "^0.15.0",
"@opentelemetry/tracing": "^0.15.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-js/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const api = require('@opentelemetry/api');
const tracer = require('./tracer')(('example-grpc-server'));
const tracer = require('./tracer')(('example-grpc-js-server'));
// eslint-disable-next-line import/order
const grpc = require('@grpc/grpc-js');

Expand Down
26 changes: 20 additions & 6 deletions examples/grpc-js/tracer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
Expand All @@ -9,13 +10,26 @@ const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider({
plugins: {
'@grpc/grpc-js': {
enabled: true,
path: '@opentelemetry/plugin-grpc-js',
const provider = new NodeTracerProvider();
registerInstrumentations({
instrumentations: [
vmarchaud marked this conversation as resolved.
Show resolved Hide resolved
{
plugins: {
'@grpc/grpc-js': {
enabled: true,
path: '@opentelemetry/plugin-grpc-js',
// // when boostraping with lerna for testing purposes
// path: `${__dirname}/../../packages/opentelemetry-plugin-grpc-js/build/src`
},
// // when boostraping with lerna for testing purposes
// 'http': {
// enabled: true,
// path: `${__dirname}/../../packages/opentelemetry-plugin-http/build/src`
// },
},
},
},
],
tracerProvider: provider,
});

let exporter;
Expand Down
1 change: 1 addition & 0 deletions examples/grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@opentelemetry/api": "^0.15.0",
"@opentelemetry/exporter-jaeger": "^0.15.0",
"@opentelemetry/exporter-zipkin": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/node": "^0.15.0",
"@opentelemetry/plugin-grpc": "^0.15.0",
"@opentelemetry/tracing": "^0.15.0",
Expand Down
15 changes: 15 additions & 0 deletions examples/grpc/tracer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
Expand All @@ -10,6 +11,20 @@ const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// // when boostraping with lerna for testing purposes
// instrumentations: [
// {
// plugins: {
// grpc: {
// enabled: true,
// path: `${__dirname}/../../packages/opentelemetry-plugin-grpc/build/src`
// }
// }
// }
// ],
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand Down
1 change: 1 addition & 0 deletions examples/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@opentelemetry/api": "^0.15.0",
"@opentelemetry/exporter-jaeger": "^0.15.0",
"@opentelemetry/exporter-zipkin": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/node": "^0.15.0",
"@opentelemetry/plugin-http": "^0.15.0",
"@opentelemetry/tracing": "^0.15.0"
Expand Down
15 changes: 15 additions & 0 deletions examples/http/tracer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
Expand All @@ -10,6 +11,20 @@ const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// // when boostraping with lerna for testing purposes
// instrumentations: [
// {
// plugins: {
// http: {
// enabled: true,
// path: `${__dirname}/../../packages/opentelemetry-plugin-http/build/src`
Flarna marked this conversation as resolved.
Show resolved Hide resolved
// }
// }
// }
// ],
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand Down
1 change: 1 addition & 0 deletions examples/https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@opentelemetry/api": "^0.15.0",
"@opentelemetry/exporter-jaeger": "^0.15.0",
"@opentelemetry/exporter-zipkin": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/node": "^0.15.0",
"@opentelemetry/plugin-https": "^0.15.0",
"@opentelemetry/tracing": "^0.15.0"
Expand Down
15 changes: 15 additions & 0 deletions examples/https/tracer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
Expand All @@ -12,6 +13,20 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
module.exports = (serviceName) => {
let exporter;
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// when boostraping with lerna for testing purposes
// instrumentations: [
// {
// plugins: {
// https: {
// enabled: true,
// path: `${__dirname}/../../packages/opentelemetry-plugin-https/build/src`
// }
// }
// }
// ],
});

if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter({
Expand Down
2 changes: 1 addition & 1 deletion examples/opentracing-shim/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const http = require('http');
const opentracing = require('opentracing');
const shim = require('./shim').shim('http_client_service');
const shim = require('./shim').shim('http_client_opentracing');

opentracing.initGlobalTracer(shim);
const tracer = opentracing.globalTracer();
Expand Down
1 change: 1 addition & 0 deletions examples/opentracing-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@opentelemetry/exporter-jaeger": "^0.15.0",
"@opentelemetry/exporter-zipkin": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/node": "^0.15.0",
"@opentelemetry/shim-opentracing": "^0.15.0",
"@opentelemetry/tracing": "^0.15.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/opentracing-shim/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const http = require('http');
const opentracing = require('opentracing');
const utils = require('./utils');
const shim = require('./shim').shim('http_server_service');
const shim = require('./shim').shim('http_server_opentracing');

opentracing.initGlobalTracer(shim);
const tracer = opentracing.globalTracer();
Expand Down
15 changes: 15 additions & 0 deletions examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
Expand All @@ -8,6 +9,20 @@ const { TracerShim } = require('@opentelemetry/shim-opentracing');

function shim(serviceName) {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// // when boostraping with lerna for testing purposes
// instrumentations: [
// {
// plugins: {
// 'opentracing': {
// enabled: true,
// path: `${__dirname}/../../packages/opentelemetry-shim-opentracing/build/src`
// }
// }
// }
// ],
});

provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
Expand Down
11 changes: 7 additions & 4 deletions examples/tracer-web/examples/document-load/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { WebTracerProvider } from '@opentelemetry/web';
import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider({
plugins: [
new DocumentLoad(),
],
const provider = new WebTracerProvider();

registerInstrumentations({
Flarna marked this conversation as resolved.
Show resolved Hide resolved
instrumentations: [new DocumentLoad()],
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));

Expand Down
8 changes: 6 additions & 2 deletions examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { WebTracerProvider } from '@opentelemetry/web';
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider({
plugins: [
const provider = new WebTracerProvider();

registerInstrumentations({
instrumentations: [
new FetchInstrumentation({
ignoreUrls: [/localhost:8090\/sockjs-node/],
propagateTraceHeaderCorsUrls: [
Expand All @@ -20,6 +23,7 @@ const provider = new WebTracerProvider({
clearTimingResources: true
}),
],
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
Expand Down
8 changes: 6 additions & 2 deletions examples/tracer-web/examples/user-interaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { B3Propagator } from '@opentelemetry/propagator-b3';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const providerWithZone = new WebTracerProvider({
plugins: [
const providerWithZone = new WebTracerProvider();

registerInstrumentations({
instrumentations: [
new UserInteractionPlugin(),
new XMLHttpRequestInstrumentation({
ignoreUrls: [/localhost/],
Expand All @@ -16,6 +19,7 @@ const providerWithZone = new WebTracerProvider({
],
}),
],
tracerProvider: providerWithZone,
});

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
Expand Down
Loading