@contrast/agentify
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -21,3 +21,2 @@ /* | ||
const Module = require('module'); | ||
const { env } = require('process'); | ||
@@ -36,4 +35,5 @@ const defaultOpts = { | ||
'depHooks', | ||
'enhancedLibraryUsage', | ||
'rewriteHooks', | ||
'functionHooks', | ||
'functionHooks' | ||
] | ||
@@ -143,17 +143,24 @@ }; | ||
if (env.CONTRAST__AGENT__DIAGNOSTICS__ENABLE !== 'false') { | ||
if (config._flat['agent.diagnostics.enable'] !== false) { | ||
const content = JSON.stringify(getEffectiveConfig(), null, 2).concat('\n\n'); | ||
if (env.CONTRAST__AGENT__DIAGNOSTICS__QUIET !== 'true') { | ||
if (config._flat['agent.diagnostics.quiet'] !== true) { | ||
fs.writeFileSync(1, content, 'utf8'); | ||
} | ||
let outputDir = env.CONTRAST__AGENT__DIAGNOSTICS__REPORT_PATH; | ||
let outputDir = config._flat['agent.diagnostics.report_path']; | ||
if (!outputDir && config.agent.logger.path) { | ||
outputDir = path.join(config.agent.logger.path, '../contrast_effective_config.json'); | ||
} else { | ||
outputDir = path.join(__dirname, 'contrast_effective_config.json'); | ||
} | ||
fs.writeFileSync(outputDir, content, 'utf-8'); | ||
try { | ||
fs.writeFileSync(outputDir, content, 'utf-8'); | ||
} catch (err) { | ||
outputDir = path.join(process.cwd(), 'contrast_effective_config.json'); | ||
try { | ||
fs.writeFileSync(outputDir, content, 'utf-8'); | ||
} catch (err) { | ||
fs.writeFileSync(1, `Couldn't create effective config file: ${err}`, 'utf-8'); | ||
} | ||
} | ||
} | ||
@@ -160,0 +167,0 @@ } |
@@ -17,59 +17,15 @@ /* | ||
'use strict'; | ||
const patchType = 'http-sources'; | ||
module.exports = function(core) { | ||
const { depHooks, patcher, logger, scopes: { sources: sourcesStorage } } = core; | ||
const sources = core.sources = {}; | ||
const { | ||
instrumentation: { instrument }, | ||
scopes: { sources: sourcesStorage } | ||
} = core; | ||
sources.install = function install() { | ||
depHooks.resolve({ name: 'http' }, http => patchServerEmit(http, 'httpServer')); | ||
depHooks.resolve({ name: 'https' }, https => patchServerEmit(https, 'httpsServer')); | ||
depHooks.resolve({ name: 'http2' }, http2 => { | ||
patchCreateServer(http2, 'http2Server'); | ||
patchCreateServer(http2, 'http2SecureServer', 'createSecureServer'); | ||
}); | ||
depHooks.resolve({ name: 'spdy' }, spdy => patchServerEmit(spdy, 'spdyServer')); | ||
}; | ||
function patchServerEmit(serverSource, sourceName) { | ||
serverSource.Server.prototype = patcher.patch(serverSource.Server.prototype, 'emit', { | ||
name: `${sourceName}.Server.prototype.emit`, | ||
patchType: 'http-sources', | ||
around: emitAroundHook(sourceName) | ||
}); | ||
} | ||
function patchCreateServer(serverSource, sourceName, constructorName = 'createServer') { | ||
patcher.patch(serverSource, constructorName, { | ||
name: sourceName, | ||
patchType: 'http-sources', | ||
post: createServerPostHook(sourceName) | ||
}); | ||
} | ||
function createServerPostHook(serverType) { | ||
return function(data) { | ||
const { result: server } = data; | ||
const serverPrototype = server ? Object.getPrototypeOf(server) : null; | ||
if (!serverPrototype) { | ||
logger.error('Unable to patch server prototype, continue without instrumentation'); | ||
return; | ||
} | ||
patcher.patch(serverPrototype, 'emit', { | ||
name: 'Server.prototype.emit', | ||
patchType: 'req-async-storage', | ||
around: emitAroundHook(serverType) | ||
}); | ||
}; | ||
} | ||
function emitAroundHook(serverType) { | ||
return function emitAroundHook(next, data) { | ||
function aroundHook(serverType) { | ||
return function around(next, data) { | ||
const { args: [event] } = data; | ||
if (event !== 'request') return next(); | ||
const store = { serverType }; | ||
return sourcesStorage.run(store, next); | ||
@@ -79,10 +35,47 @@ }; | ||
return { | ||
install: sources.install, | ||
functions: { | ||
patchCreateServer, | ||
createServerPostHook, | ||
emitAroundHook | ||
} | ||
function install() { | ||
[{ | ||
moduleName: 'http' | ||
}, | ||
{ | ||
moduleName: 'https' | ||
}, | ||
{ | ||
moduleName: 'spdy' | ||
}, | ||
{ | ||
moduleName: 'http2', | ||
patchObjectsProps: [ | ||
{ | ||
methods: ['createServer', 'createSecureServer'], | ||
patchType, | ||
patchObjects: [ | ||
{ | ||
name: 'Server.prototype', | ||
methods: ['emit'], | ||
patchType, | ||
around: aroundHook('http2') | ||
} | ||
] | ||
} | ||
] | ||
}].forEach(({ moduleName, patchObjectsProps }) => { | ||
const patchObjects = patchObjectsProps || [ | ||
{ | ||
name: 'Server.prototype', | ||
methods: ['emit'], | ||
patchType, | ||
around: aroundHook(moduleName) | ||
} | ||
]; | ||
instrument({ | ||
moduleName, | ||
patchObjects | ||
}); | ||
}); | ||
} | ||
return core.sources = { | ||
install, | ||
aroundHook | ||
}; | ||
}; |
{ | ||
"name": "@contrast/agentify", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Configures Contrast agent services and instrumentation within an application", | ||
@@ -19,2 +19,2 @@ "license": "SEE LICENSE IN LICENSE", | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
513
19052