Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: removing plugin loader from node, updating usage and docs
  • Loading branch information
obecny committed Jan 20, 2021
commit 8be63eaf5def956df189c706b5a849a3d50aea68
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
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,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 @@ -215,7 +214,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 @@ -224,7 +223,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 All @@ -242,6 +241,7 @@ To request automatic tracing support for a module not on this list, please [file
- `Tracer.withSpan(span)`: use `api.context.with(api.setSpan(api.context.active(), span))`
- `Tracer.bind(target)`: use `api.context.bind(target)`


## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand All @@ -261,11 +261,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
11 changes: 11 additions & 0 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ Create a file named `tracing.js` and add the following code:

const { LogLevel } = require("@opentelemetry/core");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");

const provider = new NodeTracerProvider({
logLevel: LogLevel.ERROR
});

provider.register();

registerInstrumentations({
tracerProvider: provider,
});

```

Now, if you run your application with `node -r ./tracing.js app.js`, your application will create and propagate traces over HTTP. If an already instrumented service that supports [Trace Context](https://www.w3.org/TR/trace-context/) headers calls your application using HTTP, and you call another application using HTTP, the Trace Context headers will be correctly propagated.
Expand Down Expand Up @@ -116,11 +122,16 @@ const { LogLevel } = require("@opentelemetry/core");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");

const provider = new NodeTracerProvider({
logLevel: LogLevel.ERROR
});

registerInstrumentations({
tracerProvider: provider,
});

provider.register();

provider.addSpanProcessor(
Expand Down
1 change: 1 addition & 0 deletions getting-started/traced-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@opentelemetry/core": "^0.14.0",
"@opentelemetry/exporter-zipkin": "^0.14.0",
"@opentelemetry/instrumentation": "^0.14.0",
"@opentelemetry/node": "^0.14.0",
"@opentelemetry/plugin-express": "^0.12.0",
"@opentelemetry/plugin-http": "^0.14.0",
Expand Down
6 changes: 6 additions & 0 deletions getting-started/traced-example/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { LogLevel } = require("@opentelemetry/core");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider({ logLevel: LogLevel.ERROR });

Expand All @@ -19,4 +20,9 @@ provider.addSpanProcessor(
);

provider.register();

registerInstrumentations({
tracerProvider: provider,
});

console.log("tracing initialized");
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
import * as api from '@opentelemetry/api';
import * as core from '@opentelemetry/core';
import { isWrapped } from '@opentelemetry/instrumentation';
import {
isWrapped,
registerInstrumentations,
} from '@opentelemetry/instrumentation';

import {
B3Propagator,
Expand Down Expand Up @@ -170,7 +173,10 @@ describe('fetch', () => {
fetchInstrumentation = new FetchInstrumentation(config);
webTracerProviderWithZone = new WebTracerProvider({
logLevel: core.LogLevel.ERROR,
plugins: [fetchInstrumentation],
});
registerInstrumentations({
tracerProvider: webTracerProviderWithZone,
instrumentations: [fetchInstrumentation],
});
webTracerWithZone = webTracerProviderWithZone.getTracer('fetch-test');
dummySpanExporter = new DummySpanExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import { Span } from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
import { ReadableSpan, SpanProcessor } from '@opentelemetry/tracing';
import { WebTracerProvider } from '@opentelemetry/web';
Expand All @@ -40,8 +41,10 @@ describe('unmocked xhr', () => {
let testSpans: TestSpanProcessor;
let provider: WebTracerProvider;
beforeEach(() => {
provider = new WebTracerProvider({
plugins: [new XMLHttpRequestInstrumentation()],
provider = new WebTracerProvider();
registerInstrumentations({
instrumentations: [new XMLHttpRequestInstrumentation()],
tracerProvider: provider,
});
testSpans = new TestSpanProcessor();
provider.addSpanProcessor(testSpans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
otperformance as performance,
isWrapped,
} from '@opentelemetry/core';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import {
B3Propagator,
B3InjectEncoding,
Expand Down Expand Up @@ -203,7 +204,10 @@ describe('xhr', () => {
);
webTracerProviderWithZone = new WebTracerProvider({
logLevel: LogLevel.ERROR,
plugins: [xmlHttpRequestInstrumentation],
});
registerInstrumentations({
instrumentations: [xmlHttpRequestInstrumentation],
tracerProvider: webTracerProviderWithZone,
});
webTracerWithZone = webTracerProviderWithZone.getTracer('xhr-test');
dummySpanExporter = new DummySpanExporter();
Expand Down Expand Up @@ -730,8 +734,13 @@ describe('xhr', () => {

webTracerWithZoneProvider = new WebTracerProvider({
logLevel: LogLevel.ERROR,
plugins: [new XMLHttpRequestInstrumentation()],
});

registerInstrumentations({
instrumentations: [new XMLHttpRequestInstrumentation()],
tracerProvider: webTracerWithZoneProvider,
});

dummySpanExporter = new DummySpanExporter();
exportSpy = sinon.stub(dummySpanExporter, 'export');
webTracerWithZoneProvider.addSpanProcessor(
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-instrumentation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
export * from './autoLoader';
export * from './platform/index';
export * from './types';
export * from './types_internal';
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './old/autoLoader';
export * from './instrumentation';
export * from './instrumentationNodeModuleDefinition';
export * from './instrumentationNodeModuleFile';
export * from './old/autoLoader';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/

import * as assert from 'assert';
import { Instrumentation } from '../../src';
import { InstrumentationAbstract } from '../../src/instrumentation';
import { Instrumentation, InstrumentationBase } from '../../src';

class TestInstrumentation extends InstrumentationAbstract {
class TestInstrumentation extends InstrumentationBase {
constructor() {
super('test', '1.0.0');
}
Expand All @@ -34,7 +33,7 @@ describe('BaseInstrumentation', () => {
});

it('should create an instance', () => {
assert.ok(instrumentation instanceof InstrumentationAbstract);
assert.ok(instrumentation instanceof InstrumentationBase);
});

it('should have a name', () => {
Expand All @@ -44,4 +43,17 @@ describe('BaseInstrumentation', () => {
it('should have a version', () => {
assert.deepStrictEqual(instrumentation.instrumentationVersion, '1.0.0');
});

describe('constructor', () => {
it('should enable instrumentation by default', () => {
let called = false;
class TestInstrumentation2 extends TestInstrumentation {
enable() {
called = true;
}
}
instrumentation = new TestInstrumentation2();
assert.strictEqual(called, true);
});
});
});
Loading