Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions packages/opentelemetry-core/src/trace/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export interface PluginConfig {
*/
path?: string;

/**
* Function to load the plugin. Needed in environments like Yarn PnP
* where modules cannot use require() to load modules not listed in their
* own dependencies.
*
* Example: `loader: () => require('@opentelemetry/plugin-xxx').plugin`
*/
loader?: () => Plugin;

/**
* Request methods that match any string in ignoreMethods will not be traced.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export class PluginLoader {

// Expecting a plugin from module;
try {
const plugin: Plugin = require(modulePath).plugin;
const plugin: Plugin = config.loader
? config.loader()
: require(modulePath).plugin;
if (!utils.isSupportedVersion(version, plugin.supportedVersions)) {
this.logger.warn(
`PluginLoader#load: Plugin ${name} only supports module ${plugin.moduleName} with the versions: ${plugin.supportedVersions}`
Expand Down