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


The following commit(s) were added to refs/heads/master by this push:
     new caaae15  Misc cleanups (#32)
caaae15 is described below

commit caaae15b8ded606c7c78ac974f960277e1e7ed7c
Author: Tomasz Pytel <[email protected]>
AuthorDate: Sat Feb 27 10:59:58 2021 -0300

    Misc cleanups (#32)
---
 src/config/AgentConfig.ts  |  2 +-
 src/plugins/AxiosPlugin.ts |  7 -------
 src/plugins/HttpPlugin.ts  |  5 +----
 src/plugins/MySQLPlugin.ts |  7 -------
 src/plugins/PgPlugin.ts    | 10 ++--------
 5 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/src/config/AgentConfig.ts b/src/config/AgentConfig.ts
index a28be12..94d5f26 100644
--- a/src/config/AgentConfig.ts
+++ b/src/config/AgentConfig.ts
@@ -60,6 +60,6 @@ export default {
     Number.parseInt(process.env.SW_AGENT_MAX_BUFFER_SIZE as string, 10) : 1000,
   ignoreSuffix: process.env.SW_IGNORE_SUFFIX ?? 
'.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg',
   traceIgnorePath: process.env.SW_TRACE_IGNORE_PATH || '',
-  sql_parameters_max_length: Math.trunc(Math.max(0, 
Number(process.env.SW_SQL_SQL_PARAMETERS_MAX_LENGTH))) || 512,
+  sql_parameters_max_length: Math.trunc(Math.max(0, 
Number(process.env.SW_SQL_PARAMETERS_MAX_LENGTH))) || 512,
   reIgnoreOperation: RegExp(''),  // temporary placeholder so Typescript 
doesn't throw a fit
 };
diff --git a/src/plugins/AxiosPlugin.ts b/src/plugins/AxiosPlugin.ts
index 9612abc..60af986 100644
--- a/src/plugins/AxiosPlugin.ts
+++ b/src/plugins/AxiosPlugin.ts
@@ -23,20 +23,13 @@ import ContextManager from 
'../trace/context/ContextManager';
 import { Component } from '../trace/Component';
 import Tag from '../Tag';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
-import { createLogger } from '../logging';
 import PluginInstaller from '../core/PluginInstaller';
 
-const logger = createLogger(__filename);
-
 class AxiosPlugin implements SwPlugin {
   readonly module = 'axios';
   readonly versions = '*';
 
   install(installer: PluginInstaller): void {
-    if (logger.isDebugEnabled()) {
-      logger.debug('installing axios plugin');
-    }
-
     this.interceptClientRequest(installer);
   }
 
diff --git a/src/plugins/HttpPlugin.ts b/src/plugins/HttpPlugin.ts
index e324b00..1d43b94 100644
--- a/src/plugins/HttpPlugin.ts
+++ b/src/plugins/HttpPlugin.ts
@@ -27,8 +27,6 @@ import ExitSpan from '../trace/span/ExitSpan';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
 import { ContextCarrier } from '../trace/context/ContextCarrier';
 
-const NativePromise = (async () => null)().constructor;  // may be different 
from globally overridden Promise
-
 class HttpPlugin implements SwPlugin {
   readonly module = 'http';
   readonly versions = '*';
@@ -163,9 +161,8 @@ class HttpPlugin implements SwPlugin {
           span.tag(Tag.httpMethod(req.method));
 
           let ret = handler.call(this, req, res, ...reqArgs);
-          const type = ret?.constructor;
 
-          if (type !== Promise && type !== NativePromise) {
+          if (!ret || typeof ret.then !== 'function') {  // generic Promise 
check
             copyStatusAndStop();
 
           } else {
diff --git a/src/plugins/MySQLPlugin.ts b/src/plugins/MySQLPlugin.ts
index 8e87ab6..8e191fc 100644
--- a/src/plugins/MySQLPlugin.ts
+++ b/src/plugins/MySQLPlugin.ts
@@ -22,21 +22,14 @@ import ContextManager from 
'../trace/context/ContextManager';
 import { Component } from '../trace/Component';
 import Tag from '../Tag';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
-import { createLogger } from '../logging';
 import PluginInstaller from '../core/PluginInstaller';
 import config from '../config/AgentConfig';
 
-const logger = createLogger(__filename);
-
 class MySQLPlugin implements SwPlugin {
   readonly module = 'mysql';
   readonly versions = '*';
 
   install(installer: PluginInstaller): void {
-    if (logger.isDebugEnabled()) {
-      logger.debug('installing mysql plugin');
-    }
-
     const Connection = installer.require('mysql/lib/Connection');
     const _query = Connection.prototype.query;
 
diff --git a/src/plugins/PgPlugin.ts b/src/plugins/PgPlugin.ts
index e17cf60..e8f4435 100644
--- a/src/plugins/PgPlugin.ts
+++ b/src/plugins/PgPlugin.ts
@@ -22,21 +22,14 @@ import ContextManager from 
'../trace/context/ContextManager';
 import { Component } from '../trace/Component';
 import Tag from '../Tag';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
-import { createLogger } from '../logging';
 import PluginInstaller from '../core/PluginInstaller';
 import agentConfig from '../config/AgentConfig';
 
-const logger = createLogger(__filename);
-
 class MySQLPlugin implements SwPlugin {
   readonly module = 'pg';
   readonly versions = '*';
 
   install(installer: PluginInstaller): void {
-    if (logger.isDebugEnabled()) {
-      logger.debug('installing pg plugin');
-    }
-
     const Client = installer.require('pg/lib/client');
     const _query = Client.prototype.query;
 
@@ -102,7 +95,7 @@ class MySQLPlugin implements SwPlugin {
 
         query = _query.call(this, config, values, callback);
 
-        if (query && typeof query.then === 'function' && typeof query.catch 
=== 'function')  // generic Promise check
+        if (query && typeof query.then === 'function') {  // generic Promise 
check
           query = query.then(
             (res: any) => {
               span.resync();
@@ -119,6 +112,7 @@ class MySQLPlugin implements SwPlugin {
               return Promise.reject(err);
             }
           );
+        }
 
       } catch (e) {
         span.error(e);

Reply via email to