Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Revert "feat: console patcher created (#575)" #579

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ Advanced options can be configured as a parameter to the init() method or as env
|useSSL |EPSAGON_SSL |Boolean|`true` |Whether to send the traces over HTTPS SSL or not |
|traceCollectorURL |EPSAGON_COLLECTOR_URL |String |- |The address of the trace collector to send trace to |
|isEpsagonDisabled |DISABLE_EPSAGON |Boolean|`false` |A flag to completely disable Epsagon (can be used for tests or locally) |
|keysToAllow |EPSAGON_ALLOWED_KEYS |Boolean|- |Array of keys to automatically label in the trace |
|ignoredKeys |EPSAGON_IGNORED_KEYS |Array |- |Array of keys names (can be string or regex) to be removed from the trace |
|ignoredDBTables |EPSAGON_IGNORED_DB_TABLES |Array |- |Array of DB Table names (can be string or regex) to ignore response from trace. |
|removeIgnoredKeys |EPSAGON_REMOVE_IGNORED_KEYS|Boolean|`false` |Whether to remove ignored keys instead of masking them |
Expand All @@ -792,7 +791,6 @@ Advanced options can be configured as a parameter to the init() method or as env
|httpErrorStatusCode|EPSAGON_HTTP_ERR_CODE |Integer|`400` |The minimum number of an HTTP response status code to treat as an error |
|- |EPSAGON_PROPAGATE_LAMBDA_ID|Boolean|`false` |Insert Lambda request ID into the response payload |
|- |DISABLE_EPSAGON_PATCH |Boolean|`false` |Disable the library patching (instrumentation) |
|isConsolePatched |EPSAGON_PATCH_CONSOLE |Boolean|`false` |Enable console module patching (instrumentation) for labelling |
|- |EPSAGON_DEBUG |Boolean|`false` |Enable debug prints for troubleshooting |
|- |EPSAGON_PROPAGATE_NATS_ID |Boolean|`false` |Whether to propagate a correlation ID in NATS.io calls for distributed tracing |
|- |EPSAGON_ADD_NODE_PATH |String |- |List of folders to looks for node_modules when patching libraries. Separated by `:`|
Expand Down
53 changes: 13 additions & 40 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ module.exports.HTTP_ERR_CODE = parseInt(process.env.EPSAGON_HTTP_ERR_CODE, 10) |
* @param {string} key the key to process
* @returns {string} key after process
*/
module.exports.prepareMatchingKey = function prepareMatchingKey(key) {
module.exports.processIgnoredKey = function processIgnoredKey(key) {
return key
.toLowerCase()
.replace('-', '')
.replace('_', '')
.replace(/\s/g, '');
};

/**
* process list of ignored keys
* @param {Array<string | RegExp>} keys the list of keys to process
* @returns {Array<string | RegExp>} the list of keys after process
*/
const processIgnoredKeys = keys => keys.map(k => (typeof k === 'string' ? module.exports.processIgnoredKey(k) : k));

/**
* process list of ignored keys, supporting String & RegExp. Warns if else
* @param {Array<string | RegExp>}keys the list of keys to match
* @return {Array<string | RegExp>} the list of keys to override in config
*/
module.exports.prepareMatchingKeys = function prepareMatchingKeys(keys) {
const matchKeysToIgnore = (keys) => {
const filteredKeys = keys
.filter(key => key && (typeof key === 'string' || key instanceof RegExp));
if (filteredKeys.length !== keys.length) {
Expand All @@ -34,29 +41,7 @@ module.exports.prepareMatchingKeys = function prepareMatchingKeys(keys) {
keys
);
}
return keys.map(key => (typeof key === 'string' ? module.exports.prepareMatchingKey(key) : key));
};

/**
* Tests if a value is found in keys
* @param {Array<String | RegExp>} keys a list of keys to match
* @param {string} testVal a value to search keys for
* @returns {boolean} true for non-ignored keys
*/
module.exports.isKeyMatched = function isKeyMatched(keys, testVal) {
return keys
.some((key) => {
// on a string key, convert to a looser fmt first
// includes() can handle more edge cases than ===
if (typeof key === 'string' && module.exports.prepareMatchingKey(testVal).includes(key)) {
return true;
}
// on a regex key, test directly for a match
if (key instanceof RegExp && key.test(testVal)) {
return true;
}
return false;
});
return processIgnoredKeys(filteredKeys);
};

/**
Expand All @@ -74,13 +59,10 @@ const config = {
useSSL: (process.env.EPSAGON_SSL || 'TRUE').toUpperCase() === 'TRUE',
traceCollectorURL: process.env.EPSAGON_COLLECTOR_URL || consts.TRACE_COLLECTOR_URL,
isEpsagonDisabled: (process.env.DISABLE_EPSAGON || '').toUpperCase() === 'TRUE',
isConsolePatched: (process.env.EPSAGON_PATCH_CONSOLE || '').toUpperCase() === 'TRUE',
urlPatternsToIgnore: [],
ignoredDBTables: [],
internalSampleRate: consts.DEFAULT_SAMPLE_RATE,
labels: {},
keysToAllow: [],
labelConsole: (process.env.EPSAGON_LABEL_CONSOLE || '').toUpperCase() === 'TRUE',
sendOnlyErrors: (process.env.EPSAGON_SEND_TRACE_ON_ERROR || '').toUpperCase() === 'TRUE',
removeIgnoredKeys: (process.env.EPSAGON_REMOVE_IGNORED_KEYS || '').toUpperCase() === 'TRUE',
sendTimeout: (Number(process.env.EPSAGON_SEND_TIMEOUT_SEC) || DEFAULT_TIMEOUT_SEC) * 1000.0,
Expand Down Expand Up @@ -135,11 +117,7 @@ if (process.env.EPSAGON_IGNORED_DB_TABLES) {
}

if (process.env.EPSAGON_IGNORED_KEYS) {
config.ignoredKeys = module.exports.prepareMatchingKeys(process.env.EPSAGON_IGNORED_KEYS.split(','));
}

if (process.env.EPSAGON_ALLOWED_KEYS) {
config.keysToAllow = module.exports.prepareMatchingKeys(process.env.EPSAGON_ALLOWED_KEYS.split(','));
config.ignoredKeys = processIgnoredKeys(process.env.EPSAGON_IGNORED_KEYS.split(','));
}

if ((process.env.EPSAGON_SSL || 'TRUE').toUpperCase() === 'FALSE') {
Expand Down Expand Up @@ -241,18 +219,13 @@ module.exports.setConfig = function setConfig(configData) {
config.disableHttpResponseBodyCapture = configData.disableHttpResponseBodyCapture;
}

// Keys to automatically capture and label
if (configData.keysToAllow) {
config.keysToAllow = module.exports.prepareMatchingKeys(configData.keysToAllow);
}

// User-defined DB Table response blacklist
if (configData.ignoredDBTables && Array.isArray(configData.ignoredDBTables)) {
config.ignoredDBTables = module.exports.prepareMatchingKeys(configData.ignoredDBTables);
config.ignoredDBTables = matchKeysToIgnore(configData.ignoredDBTables);
}

if (configData.ignoredKeys && Array.isArray(configData.ignoredKeys)) {
config.ignoredKeys = module.exports.prepareMatchingKeys(configData.ignoredKeys);
config.ignoredKeys = matchKeysToIgnore(configData.ignoredKeys);
}

if (configData.removeIgnoredKeys) {
Expand Down
50 changes: 0 additions & 50 deletions src/events/console.js

This file was deleted.

7 changes: 1 addition & 6 deletions src/patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const config = require('./config.js');
const utils = require('./utils.js');
const awsSDKPatcher = require('./events/aws_sdk.js');
const awsSDKv3Patcher = require('./events/aws_sdk_v3.js');
const consolePatcher = require('./events/console.js');
const daxPatcher = require('./events/amazon_dax_client.js');
const httpPatcher = require('./events/http.js');
const http2Patcher = require('./events/http2.js');
Expand Down Expand Up @@ -46,7 +45,6 @@ const LIBNAME_TO_PATCHER = {
'azure-sdk': azureSdkPatcher,
'winston-cw': winstonCloudwatchPatcher,
'cos-nodejs-sdk-v5': tencentCOSPatcher,
console: consolePatcher,
http: httpPatcher,
http2: http2Patcher,
pg: pgPatcher,
Expand Down Expand Up @@ -93,7 +91,6 @@ if (!config.getConfig().isEpsagonPatchDisabled) {
[
awsSDKPatcher,
awsSDKv3Patcher,
(config.getConfig().isConsolePatched ? consolePatcher : undefined),
httpPatcher,
http2Patcher,
pgPatcher,
Expand Down Expand Up @@ -122,9 +119,7 @@ if (!config.getConfig().isEpsagonPatchDisabled) {
tencentCOSPatcher,
neo4jPatcher,
fs,
]
.filter(p => p !== undefined)
.forEach(patch);
].forEach(patch);
} else {
config.getConfig().patchWhitelist.forEach(
(lib) => {
Expand Down
22 changes: 21 additions & 1 deletion src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,26 @@ function sendCurrentTrace(traceSender, tracerObject) {
return sendResult;
}

/**
* Tests if a string value (which is suspected to be a stringyfied JSON)
* contains an ignored key
* @param {Array<String | RegExp>} keysToIgnore a list of keys to ignore
* @param {string} value a value to search ignored keys in
* @returns {boolean} true for non-ignored keys
*/
module.exports.doesContainIgnoredKey = function doesContainIgnoredKey(keysToIgnore, value) {
return keysToIgnore
.some((predicate) => {
if (typeof predicate === 'string' && config.processIgnoredKey(value).includes(predicate)) {
return true;
}
if (predicate instanceof RegExp && predicate.test(value)) {
return true;
}
return false;
});
};

/**
* Filter a trace to exclude all unwanted keys
* @param {Object} traceObject the trace to filter
Expand All @@ -461,7 +481,7 @@ module.exports.filterTrace = function filterTrace(traceObject, ignoredKeys, remo
for (let i = 0; i < ignoredKeys.length; i += 1) {
const predicate = ignoredKeys[i];
if (typeof predicate === 'string' &&
predicate === config.prepareMatchingKey(key)) {
predicate === config.processIgnoredKey(key)) {
return false;
}
if (predicate instanceof RegExp && predicate.test(key)) {
Expand Down