-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove-all-listeners
- Loading branch information
Showing
181 changed files
with
268 additions
and
12,472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.