strong-trace
Version:
StrongTrace Node.js Tracer
110 lines (85 loc) • 2.18 kB
JavaScript
;
exports = module.exports = instrument
exports.checkBlacklist = checkBlacklist
var xtend = require("xtend")
var toRe = require("glob-to-regexp")
var requireTx = require("./require_transform")
var Tracer = require("./core_tracer")
var core = require("./wrappers/core/")
var DEFAULT_CONFIG = {
"instrument": true,
"trace": true,
"transactions": true,
// Core modules
"wrap_core": true,
"wrap_timers": true,
"wrap_process": true,
"wrap_dns": true,
"wrap_fs": true,
"wrap_http": true, // also wraps https
"wrap_zlib": true,
// TBD
//"wrap_crypto": true,
//"wrap_net": true,
//"wrap_dgram": true,
//"wrap_events": true,
// Third party special-cased modules.
// "wrap_redis": true,
// Third party native modules
// "wrap_native": true,
"rewrite_returns": true,
"min_calls": 0, //1,
"min_nodes": 1, //4,
"min_length": 0,
"max_scope_depth": 1000,
"max_stack_length": 20000,
"max_links_per_stack": 100,
"follow_links": true,
"enable_cca": false,
"blacklist": []
}
function checkBlacklist(filename) {
if (process.platform === "win32")
filename = filename.replace(/\\/g, "/")
function test(glob) {
return toRe(glob).test(filename)
}
return !(this.blacklist.some(test))
}
function instrument(config) {
config = xtend(DEFAULT_CONFIG, config)
// Instantiates the tracer in the global namespace.
var tracer = new Tracer(config)
// Has to come after the tracer is instantiated.
var FunctionTrace = require("./function_trace")
wrapCore(config, tracer)
if (config.instrument) {
requireTx(FunctionTrace(config), checkBlacklist.bind(config))
}
return tracer
}
function wrapCore(config, tracer) {
if (!config.wrap_core) {
return
}
if (config.wrap_timers) {
core.wrapTimers(tracer)
}
if (config.wrap_process) {
core.wrapProcess(tracer)
}
if (config.wrap_http) {
core.wrapHttp(tracer, "http")
core.wrapHttp(tracer, "https")
core.wrapHttpOutgoingMessage(tracer)
}
if (config.wrap_fs) {
core.wrapFs(tracer)
}
if (config.wrap_dns) {
core.wrapDns(tracer)
}
if (config.wrap_zlib) {
core.wrapZlib(tracer)
}
}