Comparing version 0.5.2 to 0.5.3
@@ -115,2 +115,3 @@ /** | ||
"profile_error_step_enabled": bool('profile_error_step_enabled', true), | ||
"profile_error_httpc_time_max": num("profile_error_httpc_time_max", 10000), | ||
"hook_direct_patch_classes": "", | ||
@@ -270,2 +271,3 @@ | ||
"oname_port_postfix_enabled": bool("oname_port_postfix_enabled", false), | ||
"ignore_http_lost_connection": bool("ignore_http_lost_connection", false) | ||
}; | ||
@@ -272,0 +274,0 @@ |
@@ -29,4 +29,3 @@ /** | ||
KubeUtil = require('../util/kube-util'), | ||
Logger = require('../logger'), | ||
Long = require('long'); | ||
Logger = require('../logger'); | ||
@@ -94,7 +93,13 @@ function CounterManager(agent) { | ||
//TraceContextManager.end(ctx._id); | ||
var obj = TraceContextManager.resume(ctx._id); | ||
TraceContextManager.addStep("Lost Connection","", ctx); | ||
//ctx.status = 5; | ||
//ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash); | ||
TraceContextManager.endTrace(ctx); | ||
if(conf.getProperty("ignore_http_lost_connection", false) === true){ | ||
Logger.print("WHATAP-072", "Lost Connection was ignored, " + ctx._id, false); | ||
TraceContextManager.end(ctx._id); | ||
ctx = null; | ||
}else{ | ||
// var obj = TraceContextManager.resume(ctx._id); | ||
TraceContextManager.addStep("Lost Connection","", ctx); | ||
//ctx.status = 5; | ||
//ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash); | ||
TraceContextManager.endTrace(ctx); | ||
} | ||
} | ||
@@ -101,0 +106,0 @@ } |
@@ -43,2 +43,4 @@ /** | ||
const {Buffer} = require("buffer"); | ||
const shimmer = require('../core/shimmer'); | ||
const TraceHttpc = require('../trace/trace-httpc'); | ||
@@ -211,6 +213,2 @@ var _exts=new Set([".css",".js",".png", ".htm", ".html", ".gif", ".jpg", ".css", ".txt", ".ico"]); | ||
var requestPath = ''; | ||
if(req.route && req.route.path) | ||
requestPath = req.route.path; | ||
var shouldEndTransaction = shouldEndCurrentTransaction(not_found_ignore, ctx, res, req.route ? req.route.path : ''); | ||
@@ -676,106 +674,96 @@ if (shouldEndTransaction) { | ||
aop.both(mod, 'request', | ||
function (obj, args, lctx) { | ||
var ctx = lctx.context; | ||
if (ctx == null || (args[0].host == null && args[0].hostname == null) ) { return; } // for axios | ||
var isHttpsRepeat = false; | ||
if(moduleName === 'https') { | ||
args[0].__isHttps = true; | ||
shimmer.wrap(mod, 'request', function (original) { | ||
return function wrappedRequest(options, callback) { | ||
var ctx = TraceContextManager.getCurrentContext(); | ||
if(!ctx || (!options.host && !options.hostname)){ | ||
return original.apply(this, arguments); | ||
} | ||
if(moduleName === 'http' && args[0].__isHttps) { | ||
isHttpsRepeat = true; | ||
var isHttpRepeat = false; | ||
if(moduleName === 'https'){ | ||
options.__isHttps = true; | ||
} | ||
if(moduleName === 'http' && options.__isHttps){ | ||
isHttpRepeat = true; | ||
} | ||
if(!isHttpsRepeat) { | ||
try { | ||
if(args[0].method === 'OPTION') { | ||
return; | ||
var step = new HttpStepX(); | ||
step.start_time = ctx.getElapsedTime(); | ||
if(!isHttpRepeat){ | ||
if(options.method === 'OPTION'){ | ||
return original.apply(this, arguments); | ||
} | ||
try{ | ||
interTxTraceAutoOn(ctx); | ||
if(conf.getProperty('mtrace_enabled', false)){ | ||
if(options.headers){ | ||
options.headers['x-wtap-po'] = transferPOID(ctx); | ||
}else{ | ||
options.headers = {'x-wtap-po': transferPOID(ctx)}; | ||
} | ||
if(conf.stat_mtrace_enabled){ | ||
options.headers[conf._trace_mtrace_spec_key1]=transferSPEC_URL(ctx); | ||
} | ||
if(conf.mtid_mtrace_enabled && ctx.mtid.isZero()===false){ | ||
options.headers[conf._trace_mtrace_caller_key]=transferMTID_CALLERTX(ctx); | ||
} | ||
} | ||
var dataConsumption = false; | ||
ctx.httpc_url = options.path || '/'; | ||
ctx.httpc_host = options.host || options.hostname || ''; | ||
ctx.httpc_port = options.port || -1; | ||
if(args.length > 0) { | ||
var info = args[0]; | ||
interTxTraceAutoOn(ctx); | ||
if(conf.mtrace_enabled){ | ||
if(info.headers){ | ||
info.headers['x-wtap-po']=transferPOID(ctx); | ||
}else{ | ||
info.headers={ | ||
'x-wtap-po': transferPOID(ctx) | ||
}; | ||
} | ||
if(conf.stat_mtrace_enabled){ | ||
info.headers[conf._trace_mtrace_spec_key1]=transferSPEC_URL(ctx); | ||
} | ||
if(conf.mtid_mtrace_enabled && ctx.mtid.isZero()===false){ | ||
info.headers[conf._trace_mtrace_caller_key]=transferMTID_CALLERTX(ctx); | ||
} | ||
} | ||
ctx.httpc_url = info.path || '/'; | ||
ctx.httpc_host = info.host || info.hostname || ''; | ||
ctx.httpc_port = info.port || -1; | ||
} | ||
ctx.footprint('Http Call Start'); | ||
if (ctx.httpc_port < 0) { ctx.httpc_port = 80 }; | ||
} catch(e) { | ||
return Logger.printError('WHATAP-852', 'Http Repeat ', e, true); | ||
}catch (e) { | ||
Logger.printError('WHATAP-852', 'Http Repeat ', e, true); | ||
return original.apply(this, arguments); | ||
} | ||
}else{ | ||
return original.apply(this, arguments); | ||
} | ||
aop.functionHook(args, -1, function(obj, args) { | ||
if(TraceContextManager.resume(ctx._id) == null) { return; } | ||
var wrappedCallback; | ||
if (typeof callback === 'function') { | ||
wrappedCallback = function(response) { | ||
if (TraceContextManager.resume(ctx._id) === null) { | ||
return callback.apply(this, arguments); | ||
} | ||
var res = args[0]; | ||
aop.before(res, ['on', 'addListener'], function(obj, args) { | ||
if(!dataConsumption && args[0] === 'data') { | ||
dataConsumption = true; | ||
response.on('end', function() { | ||
step.elapsed = ctx.getElapsedTime() - step.start_time; | ||
step.url = HashUtil.hashFromString(ctx.httpc_url); | ||
DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url); | ||
step.host = HashUtil.hashFromString(ctx.httpc_host); | ||
DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host); | ||
step.port = ctx.httpc_port; | ||
if (response.statusCode >= 400 && transaction_status_error_enable) { | ||
step.error = StatError.addError(response.statusCode, response.statusMessage, | ||
ctx.service_hash, TextTypes.HTTPC_URL, step.url); | ||
if (ctx.error.isZero()) { | ||
ctx.error = step.error; | ||
ctx.statusCode = response.statusCode; | ||
ctx.statusMessage = response.statusMessage; | ||
} | ||
} | ||
ctx.active_httpc_hash = step.url; | ||
ctx.profile.push(step); | ||
endHttpc(ctx, step); | ||
}); | ||
aop.before(res, 'pipe', function() { | ||
dataConsumption = true; | ||
}); | ||
aop.before(res, 'resume', function() { | ||
dataConsumption = true; | ||
}); | ||
if (dataConsumption) { return; } | ||
// endHttpc(ctx, step); | ||
}); | ||
return callback.apply(this, arguments); | ||
}; | ||
} | ||
}, | ||
function (obj, args, ret, lctx) { | ||
if(moduleName === 'http' && args[0].__isHttps) { | ||
return; | ||
} | ||
var ctx = lctx.context; | ||
if (ctx == null || ( args[0].host == null && args[0].hostname == null)) { return; } | ||
var is_ignore_error = false; | ||
var req = original.apply(this, [options, wrappedCallback]); | ||
ret.on('response', function(response){ | ||
var statusCode = response.statusCode; | ||
if(transaction_status_error_enable && statusCode >= 400){ | ||
if (step.error.isZero()) { | ||
step.error = StatError.addError(statusCode, response.statusMessage , ctx.service_hash, | ||
TextTypes.HTTPC_URL, step.url); | ||
if (ctx.error.isZero()) { | ||
ctx.error = step.error; | ||
ctx.statusCode = statusCode; | ||
ctx.statusMessage = response.statusMessage; | ||
} | ||
} | ||
} | ||
}) | ||
ret.on('error', function(err) { | ||
if (TraceContextManager.resume(ctx._id) == null) { return; } | ||
req.on('error', function (err) { | ||
if (TraceContextManager.resume(ctx._id) === null) { return; } | ||
ctx.is_httpc_error = true; | ||
if (transaction_status_error_enable && step.error.isZero() && !is_ignore_error) { | ||
if (transaction_status_error_enable && step.error.isZero()) { | ||
step.error = StatError.addError(err.code, err.message, ctx.service_hash, | ||
@@ -793,55 +781,36 @@ TextTypes.HTTPC_URL, step.url); | ||
var step = new HttpStepX(); | ||
step.start_time = ctx.getElapsedTime(); | ||
step.url = HashUtil.hashFromString(ctx.httpc_url); | ||
DataTextAgent.HTTPC_URL.add(step.url, ctx.httpc_url); | ||
step.host = HashUtil.hashFromString(ctx.httpc_host); | ||
DataTextAgent.HTTPC_HOST.add(step.host, ctx.httpc_host); | ||
step.port = ctx.httpc_port; | ||
shimmer.wrap(req, 'write', function (original) { | ||
return function wrappedWrite() { | ||
try { | ||
if (conf.getProperty('profile_httpc_parameter_enabled', true)) { | ||
if (arguments && arguments[0]) { | ||
var bodyData; | ||
aop.before(ret, 'write', function (obj, args) { | ||
if(conf.profile_httpc_parameter_enabled == true) { | ||
if(args.length == 1) { | ||
var step = new MessageStep(); | ||
step.hash = HashUtil.hashFromString("HTTPC-REQUEST-BODY"); | ||
step.start_time = ctx.getElapsedTime(); | ||
step.desc = args[0]; | ||
DataTextAgent.MESSAGE.add(step.hash, "HTTPC-REQUEST-BODY"); | ||
ctx.profile.push(step); | ||
if (typeof arguments[0] === 'object' && !(arguments[0] instanceof Buffer)) { | ||
bodyData = JSON.stringify(arguments[0]); | ||
} | ||
if (arguments[0] instanceof Buffer) { | ||
bodyData = arguments[0].toString('utf8'); | ||
} | ||
if(bodyData){ | ||
var step = new MessageStep(); | ||
step.hash = HashUtil.hashFromString("HTTPC-REQUEST-BODY"); | ||
step.start_time = ctx.getElapsedTime(); | ||
step.desc = bodyData; | ||
DataTextAgent.MESSAGE.add(step.hash, "HTTPC-REQUEST-BODY"); | ||
ctx.profile.push(step); | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
Logger.printError('WHATAP-615', 'HTTP Write hook failed', e, false); | ||
} | ||
return original.apply(this, arguments); | ||
} | ||
}); | ||
aop.before(ret, 'end', function (obj, args) { | ||
ctx.active_httpc_hash = step.url; | ||
ctx.profile.push(step); | ||
}); | ||
return req; | ||
} | ||
}); | ||
ret.on('socket', function(socket) { | ||
// socket reuse chk | ||
if(conf.setSocketChk(socket) == false) { | ||
aop.before(socket, 'end', function (obj, args) { | ||
if(ctx == null) { return; } | ||
TraceContextManager.resume(ctx._id); | ||
endHttpc(ctx, step); | ||
}); | ||
socket.on('timeout', function () { | ||
if (TraceContextManager.resume(ctx._id) == null) { return; } | ||
is_ignore_error = true; | ||
// if (step.error.isZero()) { | ||
// var msgObj = { 'class': 'Timeout', 'msg': 'Timeout' }; | ||
// step.error = StatError.addError('Timeout','Timeout', ctx.service_hash); | ||
// if (transaction_status_error_enable && ctx.error.isZero()) { | ||
// ctx.error = step.error; | ||
// ctx.statusCode = 'Timeout'; | ||
// ctx.statusMessage = 'Timeout'; | ||
// } | ||
// } | ||
// endHttpc(ctx, step); | ||
}); | ||
} | ||
}); | ||
}); | ||
function endHttpc(ctx, step) { | ||
@@ -851,2 +820,3 @@ if(ctx == null || step == null) { return; } | ||
step.elapsed = ctx.getElapsedTime() - step.start_time; | ||
TraceHttpc.isSlowHttpc(ctx, step); | ||
@@ -853,0 +823,0 @@ ctx.httpc_count++; |
@@ -26,3 +26,4 @@ /** | ||
Buffer = require('buffer').Buffer, | ||
shimmer = require('../core/shimmer'); | ||
shimmer = require('../core/shimmer'), | ||
TraceSQL = require('../trace/trace-sql'); | ||
@@ -50,2 +51,3 @@ var MariaObserver = function (agent) { | ||
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time; | ||
TraceSQL.isSlowSQL(ctx); | ||
@@ -58,2 +60,3 @@ MeterSql.add(sql_step.hash, sql_step.elapsed, false); | ||
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time; | ||
TraceSQL.isSlowSQL(ctx); | ||
@@ -198,5 +201,19 @@ MeterSql.add(sql_step.hash, sql_step.elapsed, false); | ||
const result = original.apply(this, args); | ||
// return result; | ||
return result.then(res => { | ||
_finishQuery(ctx, sql_step); | ||
if (Array.isArray(res) && psql && psql.type === "S") { | ||
var result_step = new ResultSetStep(); | ||
result_step.start_time = ctx.getElapsedTime(); | ||
result_step.elapsed = 0; | ||
result_step.fetch = res.length; | ||
result_step.sqlhash = psql.sql; | ||
result_step.dbc = dbc_hash; | ||
ctx.profile.push(result_step); | ||
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0); | ||
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0); | ||
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx); | ||
} | ||
var isSelectQuery = psql && psql.type === "S"? true : false; | ||
_finishQuery(ctx, sql_step, isSelectQuery, res); | ||
return res; | ||
@@ -203,0 +220,0 @@ }).catch(err => { |
@@ -22,3 +22,4 @@ /** | ||
conf = require('../conf/configure'), | ||
Logger = require('../logger'); | ||
Logger = require('../logger'), | ||
TraceSQL = require('../trace/trace-sql') | ||
const DateUtil = require('../util/dateutil'); | ||
@@ -121,2 +122,3 @@ const MessageStep = require("../step/message-step"); | ||
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time; | ||
TraceSQL.isSlowSQL(ctx); | ||
@@ -127,7 +129,2 @@ MeterSql.add(dbc_hash, sql_step.elapsed, args[0] != null); | ||
// if(conf.getProperty('profile_sql_resource_enabled', false)){ | ||
// sql_step.start_cpu = ResourceProfile.getCPUTime(); | ||
// sql_step.start_mem = ResourceProfile.getUsedHeapSize(); | ||
// } | ||
if(psql && psql.type == 'S') { | ||
@@ -138,3 +135,3 @@ var result_step = new ResultSetStep(); | ||
try { | ||
result_step.fetch = args[1].recordset.length; | ||
result_step.fetch = args[1][0].length; | ||
} catch(e) { | ||
@@ -145,2 +142,4 @@ } | ||
StatSql.addFetch(dbc_hash, result_step.sqlhash, result_step.fetch, 0); | ||
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx); | ||
} else if(psql && psql.type == 'U') { | ||
@@ -147,0 +146,0 @@ |
@@ -25,4 +25,4 @@ /** | ||
DateUtil = require('../util/dateutil'), | ||
Buffer = require('buffer').Buffer; | ||
// const ResourceProfile = require('../util/resourceprofile'); | ||
Buffer = require('buffer').Buffer, | ||
TraceSQL = require('../trace/trace-sql'); | ||
@@ -166,2 +166,4 @@ var MysqlObserver = function (agent) { | ||
TraceSQL.isSlowSQL(ctx); | ||
// if(conf.getProperty('profile_sql_resource_enabled', false)){ | ||
@@ -188,2 +190,4 @@ // sql_step.start_cpu = ResourceProfile.getCPUTime(); | ||
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0); | ||
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx); | ||
} | ||
@@ -190,0 +194,0 @@ |
@@ -23,4 +23,6 @@ /** | ||
Buffer = require('buffer').Buffer, | ||
DateUtil = require('../util/dateutil'); | ||
DateUtil = require('../util/dateutil'), | ||
TraceSQL = require('../trace/trace-sql'); | ||
const shimmer = require('../core/shimmer'); | ||
const ResultSetStep = require("../step/resultset-step"); | ||
@@ -174,3 +176,2 @@ var PgSqlObserver = function (agent) { | ||
try { | ||
// SQL 실행 | ||
const result = original.apply(this, arguments); | ||
@@ -180,2 +181,15 @@ | ||
return result.then(res => { | ||
if(res.command && res.command === 'SELECT'){ | ||
var result_step = new ResultSetStep(); | ||
result_step.start_time = ctx.getElapsedTime(); | ||
result_step.elapsed = 0; | ||
result_step.fetch = res.rowCount; | ||
result_step.sqlhash = psql.sql; | ||
result_step.dbc = dbc_hash; | ||
ctx.profile.push(result_step); | ||
MeterSql.addFetch(result_step.dbc, result_step.fetch, 0); | ||
StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0); | ||
TraceSQL.isTooManyRecords(sql_step, result_step.fetch, ctx); | ||
} | ||
self._finishQuery(ctx, sql_step); | ||
@@ -217,21 +231,7 @@ return res; | ||
}); | ||
// if (mod.Pool && mod.Pool.prototype.query) { | ||
// shimmer.wrap(mod.Pool.prototype, 'query', function (original) { | ||
// return function () { | ||
// const traceContext = TraceContextManager.getCurrentContext(); | ||
// if (!traceContext) { | ||
// return original.apply(this, arguments); | ||
// } | ||
// | ||
// // 동일한 방식으로 처리 | ||
// return self.agent.pgClient.query.apply(this, arguments); | ||
// }; | ||
// }); | ||
// } | ||
}; | ||
// 쿼리 완료 처리 | ||
PgSqlObserver.prototype._finishQuery = function (ctx, sql_step) { | ||
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time; | ||
TraceSQL.isSlowSQL(ctx); | ||
@@ -244,4 +244,4 @@ MeterSql.add(sql_step.hash, sql_step.elapsed, false); | ||
sql_step.elapsed = ctx.getElapsedTime() - sql_step.start_time; | ||
TraceSQL.isSlowSQL(ctx); | ||
// Logger.printError('WHATAP-192', 'PGSQL Query error.', err); | ||
MeterSql.add(sql_step.hash, sql_step.elapsed, false); | ||
@@ -248,0 +248,0 @@ StatSql.addSqlTime(ctx, ctx.service_hash, sql_step.dbc, sql_step.hash, sql_step.elapsed, true, 0); |
{ | ||
"name": "whatap", | ||
"homepage": "http://www.whatap.io", | ||
"version": "0.5.2", | ||
"releaseDate": "20241017", | ||
"version": "0.5.3", | ||
"releaseDate": "20241113", | ||
"description": "Monitoring and Profiling Service", | ||
@@ -7,0 +7,0 @@ "main": "index.js", |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
1051609
244
23053
1