Skip to content

Commit e11e906

Browse files
author
Richard Cornelissen
committed
feat: feat: add ability to load resolved plugin
1 parent 37cdebd commit e11e906

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/opentelemetry-node/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ In the following example:
8282
- the default express plugin is disabled
8383
- the http plugin has a custom config for a `requestHook`
8484
- the customPlugin is loaded from the user supplied path
85+
- the customPlugin2 is resolved locally and injected
8586
- all default plugins are still loaded if installed.
8687

8788
```js
89+
import {plugin as httpsPlugin} from '@opentelemetry/plugin-https';
90+
8891
const provider = new NodeTracerProvider({
8992
plugins: {
9093
express: {
@@ -98,6 +101,9 @@ const provider = new NodeTracerProvider({
98101
customPlugin: {
99102
path: "/path/to/custom/module",
100103
},
104+
customPlugin2: {
105+
plugin: httpsPlugin,
106+
},
101107
},
102108
});
103109
```

packages/opentelemetry-node/src/instrumentation/PluginLoader.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class PluginLoader {
131131
if (this._hookState !== HookState.ENABLED) return exports;
132132
const config = pluginsToLoad[name];
133133
const modulePath = config.path!;
134+
const modulePlugin = config.plugin;
134135
let version = null;
135136

136137
if (!baseDir) {
@@ -170,7 +171,7 @@ export class PluginLoader {
170171

171172
// Expecting a plugin from module;
172173
try {
173-
const plugin: Plugin = require(modulePath).plugin;
174+
const plugin: Plugin = modulePlugin ?? require(modulePath).plugin;
174175
if (!utils.isSupportedVersion(version, plugin.supportedVersions)) {
175176
this.logger.warn(
176177
`PluginLoader#load: Plugin ${name} only supports module ${plugin.moduleName} with the versions: ${plugin.supportedVersions}`

0 commit comments

Comments
 (0)