Skip to content

Commit

Permalink
feat(logger): pass logger to plugin packages (open-telemetry#228)
Browse files Browse the repository at this point in the history
Closes open-telemetry#193

Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca>
  • Loading branch information
OlivierAlbertini authored and mayurkale22 committed Aug 28, 2019
1 parent 9785974 commit 7d6ca67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> implements Plugin<T> {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Tracer } from '../tracer';
import { Logger } from '../../common/Logger';

/** Interface Plugin to apply patch. */
// tslint:disable-next-line:no-any
Expand All @@ -24,11 +25,13 @@ export interface Plugin<T = any> {
* @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;

Expand Down

0 comments on commit 7d6ca67

Please sign in to comment.