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
Prev Previous commit
Next Next commit
chore: removing remaining plugins configurations, updating readme, re…
…moving base abstract class
  • Loading branch information
obecny committed Apr 7, 2021
commit fe12bbc7908b14be760973c093c7a38a290e3fb5
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ To request automatic tracing support for a module not on this list, please [file
| [@opentelemetry/shim-opentracing][otel-shim-opentracing] | OpenTracing shim allows existing OpenTracing instrumentation to report to OpenTelemetry |

## Upgrade guidelines
\

### 0.19.0 to 1.0.0-rc.0

- All plugins have been removed use instrumentations.
- All plugins have been removed in favor of instrumentations.
```javascript

```
Expand Down
55 changes: 7 additions & 48 deletions doc/instrumentation-guide.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
# Instrumentation Developer Guide

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.
A detailed explained guide how to instrument a package is available at [instrumentation package][base-instrumentation]

We strongly recommended to create a dedicated package for newly added plugin, example: `@opentelemetry/plugin-xxx`.
For more comprehensive examples please refer to the [HTTP instrumentation][http-instrumentation] or [gRPC instrumentation][grpc-instrumentation] for node
and [XMLHttpRequest instrumentation][xhr-instrumentation] for web.

Each plugin must extend the abstract class [BasePlugin][base-plugin] implementing the below methods:

- `patch`: A function describing how the module exports for a given file should be modified.

- `unpatch`: A function describing how the module exports for a given file should be unpatched. This should generally mirror the logic in `patch`; for example, if `patch` wraps a method, `unpatch` should unwrap it.

The core `PluginLoader` class is responsible for loading the instrumented plugins that use a patch mechanism to enable automatic tracing for specific target modules. In order to load new plugin, it should export `plugin` identifier.

```typescript
export const plugin = new HttpPlugin(...);
```

> Example of simple module plugin created and used in the tests.
<https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-node/test/instrumentation/node_modules/%40opentelemetry/plugin-simple-module/simple-module.js>
After the plugin is created, it must be added in the [list of default supported plugins][DEFAULT_INSTRUMENTATION_PLUGINS].

```typescript
export const DEFAULT_INSTRUMENTATION_PLUGINS: Plugins = {
http: {
enabled: true,
path: '@opentelemetry/plugin-http',
},
grpc: {
enabled: true,
path: '@opentelemetry/plugin-grpc',
},
// [ADD NEW PLUGIN HERE]
xxx: {
enabled: true,
// You may use a package name or absolute path to the file.
path: '@opentelemetry/plugin-xxx',
}
};
```

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-instrumentations]: https://github.com/open-telemetry/opentelemetry-js#instrumentations&plugins
[base-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/platform/node/BasePlugin.ts
[http-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-plugin-http/src/http.ts#L44
[grpc-plugin]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-plugin-grpc/src/grpc.ts#L52
[DEFAULT_INSTRUMENTATION_PLUGINS]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-node/src/config.ts#L29
[base-instrumentation]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation
[http-instrumentation]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-http/src/http.ts#L59
[grpc-instrumentation]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts#L28
[xhr-instrumentation]: https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts#L71
45 changes: 28 additions & 17 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ This guide uses the example application provided in the [example directory](exam

([link to TypeScript version](ts-example/README.md#install-the-required-opentelemetry-libraries))

To create traces on NodeJS, you need `@opentelemetry/node`, `@opentelemetry/core`, and any plugins required by your application such as gRPC or HTTP. If you're using the example application, you need to install `@opentelemetry/plugin-http`, `@opentelemetry/plugin-https`, and `@opentelemetry/plugin-express`.
To create traces on NodeJS, you need `@opentelemetry/node`, `@opentelemetry/core`, and any instrumentation required by your application such as gRPC or HTTP. If you're using the example application, you need to install `@opentelemetry/instrumentation-http` and `@opentelemetry/instrumentation-express`.

```sh
$ npm install \
@opentelemetry/core \
@opentelemetry/node \
@opentelemetry/plugin-http \
@opentelemetry/plugin-https \
@opentelemetry/plugin-express
@opentelemetry/instrumentation-http \
@opentelemetry/instrumentation-express
```

#### Initialize a global tracer
Expand All @@ -76,17 +75,23 @@ Create a file named `tracing.js` and add the following code:
```javascript
'use strict';

const { LogLevel } = require("@opentelemetry/core");
const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http");
const { GrpcInstrumentation } = require("@opentelemetry/instrumentation-grpc");

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

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);

provider.register();

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

Expand Down Expand Up @@ -118,21 +123,17 @@ After you install these dependencies, initialize and register them. Modify `trac
```javascript
'use strict';

const { LogLevel } = require("@opentelemetry/core");
const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http");
const { GrpcInstrumentation } = require("@opentelemetry/instrumentation-grpc");

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

registerInstrumentations({
tracerProvider: provider,
});
const provider = new NodeTracerProvider();

provider.register();
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);

provider.addSpanProcessor(
new SimpleSpanProcessor(
Expand All @@ -145,6 +146,16 @@ provider.addSpanProcessor(
)
);

provider.register();

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

console.log("tracing initialized");
```

Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export * from './context/propagation/HttpTraceContext';
export * from './context/propagation/types';
export * from './baggage/propagation/HttpBaggage';
export * from './platform';
export * from './trace/Plugin';
export * from './trace/sampler/AlwaysOffSampler';
export * from './trace/sampler/AlwaysOnSampler';
export * from './trace/sampler/ParentBasedSampler';
Expand Down
50 changes: 0 additions & 50 deletions packages/opentelemetry-core/src/platform/BaseAbstractPlugin.ts

This file was deleted.

100 changes: 0 additions & 100 deletions packages/opentelemetry-core/src/trace/Plugin.ts

This file was deleted.

17 changes: 5 additions & 12 deletions packages/opentelemetry-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ For manual instrumentation see the
## How auto instrumentation works

This package exposes a `NodeTracerProvider`.
For loading plugins / instrumentations please use `registerInstrumentations` function from [opentelemetry-instrumentation](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation)
For loading instrumentations please use `registerInstrumentations` function from [opentelemetry-instrumentation](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-instrumentation)

OpenTelemetry comes with a growing number of instrumentation plugins for well know modules (see [supported modules](https://github.com/open-telemetry/opentelemetry-js#plugins)) and an API to create custom instrumentation (see [the instrumentation developer guide](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/instrumentation-guide.md)).
OpenTelemetry comes with a growing number of instrumentation plugins for well know modules (see [supported modules](https://github.com/open-telemetry/opentelemetry-js#instrumentations)) and an API to create custom instrumentation (see [the instrumentation developer guide](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/instrumentation-guide.md)).

> **Please note:** This module does *not* bundle any plugins. They need to be installed separately.

Expand Down Expand Up @@ -72,21 +72,14 @@ registerInstrumentations({
const http = require('http');
```

## Instrumentation / Plugin configuration

User supplied plugin configuration is merged with the default plugin
configuration. Furthermore, custom plugins that are configured are implicitly
enabled just as default plugins are.
## Instrumentation configuration

In the following example:

- the default express plugin is disabled
- the express plugin is enabled
- the http plugin has a custom config for a `requestHook`
- the customPlugin is loaded from the user supplied path
- all default plugins are still loaded if installed.

```javascript
const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graphql');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');

Expand All @@ -97,7 +90,7 @@ const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new GraphQLInstrumentation(),
new ExpressInstrumentation(),
new HttpInstrumentation({
requestHook: (span, request) => {
span.setAttribute("custom request hook attribute", "request");
Expand Down
7 changes: 0 additions & 7 deletions packages/opentelemetry-node/src/NodeTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';
import {
AsyncHooksContextManager,
AsyncLocalStorageContextManager,
Expand All @@ -36,12 +35,6 @@ import { NodeTracerConfig } from './config';
export class NodeTracerProvider extends BasicTracerProvider {
constructor(config: NodeTracerConfig = {}) {
super(config);
if (config.plugins) {
diag.warn(
'plugins options was removed, please use' +
' "registerInstrumentations" to load plugins'
);
}
}

register(config: SDKRegistrationConfig = {}) {
Expand Down
5 changes: 1 addition & 4 deletions packages/opentelemetry-node/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ import { TracerConfig } from '@opentelemetry/tracing';
/**
* NodeTracerConfig provides an interface for configuring a Node Tracer.
*/
export interface NodeTracerConfig extends TracerConfig {
/** Plugins options deprecated */
plugins?: unknown[];
}
export type NodeTracerConfig = TracerConfig;
Loading