Skip to content

Commit

Permalink
Misc cleanups (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-pytel authored Feb 27, 2021
1 parent 78d3a2a commit caaae15
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/config/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
7 changes: 0 additions & 7 deletions src/plugins/AxiosPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 1 addition & 4 deletions src/plugins/HttpPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '*';
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/MySQLPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 2 additions & 8 deletions src/plugins/PgPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -119,6 +112,7 @@ class MySQLPlugin implements SwPlugin {
return Promise.reject(err);
}
);
}

} catch (e) {
span.error(e);
Expand Down

0 comments on commit caaae15

Please sign in to comment.