This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking-nodejs.git
commit e7a751054906778decdf4723a5cf88c9ff1edb19 Author: kezhenxu94 <kezhenx...@163.com> AuthorDate: Wed Jun 24 23:09:50 2020 +0800 Add `trace` annotation and polish plugin installer in dev environment --- .../PluginInstaller.ts => annotations/index.ts} | 37 ++++++++++------------ src/core/PluginInstaller.ts | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/core/PluginInstaller.ts b/src/annotations/index.ts similarity index 54% copy from src/core/PluginInstaller.ts copy to src/annotations/index.ts index 6ac4e08..e6fe0e1 100644 --- a/src/core/PluginInstaller.ts +++ b/src/annotations/index.ts @@ -17,29 +17,24 @@ * */ -import * as fs from 'fs'; -import * as path from 'path'; -import SwPlugin from '../core/SwPlugin'; -import { createLogger } from '../logging'; +import ContextManager from '../trace/context/ContextManager'; -const logger = createLogger(__filename); +export function trace(op?: string) { + return (target: any, key: string, descriptor?: PropertyDescriptor) => { + if (descriptor === undefined) { + return; + } -class PluginInstaller { - pluginDir: string; + const original = descriptor.value; - constructor() { - this.pluginDir = path.resolve(__dirname, '..', 'plugins'); - } + descriptor.value = function (...args: any[]) { + const span = ContextManager.current.newLocalSpan(op || key).start(); - install(): void { - fs.readdirSync(this.pluginDir) - .filter((file) => file.endsWith('.js')) - .forEach((file) => { - const plugin = require(path.join(this.pluginDir, file)).default as SwPlugin; - logger.info(`Installing plugin ${plugin.module} ${plugin.versions}`); - plugin.install(); - }); - } -} + const result = original.apply(this, args); + + span.stop(); -export default new PluginInstaller(); + return result; + }; + }; +} diff --git a/src/core/PluginInstaller.ts b/src/core/PluginInstaller.ts index 6ac4e08..dc3d1e1 100644 --- a/src/core/PluginInstaller.ts +++ b/src/core/PluginInstaller.ts @@ -33,7 +33,7 @@ class PluginInstaller { install(): void { fs.readdirSync(this.pluginDir) - .filter((file) => file.endsWith('.js')) + .filter((file) => (process.env.NODE_ENV === 'production' ? file.endsWith('.js') : true)) .forEach((file) => { const plugin = require(path.join(this.pluginDir, file)).default as SwPlugin; logger.info(`Installing plugin ${plugin.module} ${plugin.versions}`);