From 7d6ca676a626fa561d39c794cba6af13ec428951 Mon Sep 17 00:00:00 2001 From: Olivier Albertini Date: Wed, 28 Aug 2019 14:48:16 -0400 Subject: [PATCH] feat(logger): pass logger to plugin packages (#228) Closes #193 Signed-off-by: Olivier Albertini --- .../src/trace/instrumentation/BasePlugin.ts | 5 ++++- .../src/instrumentation/PluginLoader.ts | 2 +- .../opentelemetry-types/src/trace/instrumentation/Plugin.ts | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts index 538977435ad..90631c7830b 100644 --- a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts +++ b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts @@ -14,20 +14,23 @@ * limitations under the License. */ -import { Tracer, Plugin } from '@opentelemetry/types'; +import { Tracer, Plugin, Logger } from '@opentelemetry/types'; /** This class represent the base to patch plugin. */ export abstract class BasePlugin implements Plugin { protected _moduleExports!: T; protected _tracer!: Tracer; + protected _logger!: Logger; enable( moduleExports: T, tracer: Tracer, + logger: Logger, config?: { [key: string]: unknown } ): T { this._moduleExports = moduleExports; this._tracer = tracer; + this._logger = logger; return this.patch(); } diff --git a/packages/opentelemetry-node-tracer/src/instrumentation/PluginLoader.ts b/packages/opentelemetry-node-tracer/src/instrumentation/PluginLoader.ts index 69978b302f6..7137983bfae 100644 --- a/packages/opentelemetry-node-tracer/src/instrumentation/PluginLoader.ts +++ b/packages/opentelemetry-node-tracer/src/instrumentation/PluginLoader.ts @@ -103,7 +103,7 @@ export class PluginLoader { const plugin: Plugin = require(moduleName).plugin; this._plugins.push(plugin); // Enable each supported plugin. - return plugin.enable(exports, this.tracer); + return plugin.enable(exports, this.tracer, this.logger); } catch (e) { this.logger.error( `PluginLoader#load: could not load plugin ${moduleName} of module ${name}. Error: ${e.message}` diff --git a/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts b/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts index 1233996a566..643a4d45291 100644 --- a/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts +++ b/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts @@ -15,6 +15,7 @@ */ import { Tracer } from '../tracer'; +import { Logger } from '../../common/Logger'; /** Interface Plugin to apply patch. */ // tslint:disable-next-line:no-any @@ -24,11 +25,13 @@ export interface Plugin { * @param moduleExports The value of the `module.exports` property that would * normally be exposed by the required module. ex: `http`, `https` etc. * @param tracer a tracer instance. + * @param logger a logger instance. * @param [config] an object to configure the plugin. */ enable( moduleExports: T, tracer: Tracer, + logger: Logger, config?: { [key: string]: unknown } ): T;