@contrast/instrumentation
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -23,31 +23,35 @@ /* | ||
function createPostHook(namePrefix, patchType, methods, around) { | ||
return function post(data) { | ||
const { result: server } = data; | ||
const serverPrototype = server ? Object.getPrototypeOf(server) : null; | ||
if (!serverPrototype) { | ||
core.logger.error('Unable to patch server prototype, continue without instrumentation'); | ||
return; | ||
} | ||
methods.forEach((method) => { | ||
patcher.patch(serverPrototype, method, { | ||
name: `${namePrefix}.${method}`, | ||
patchType, | ||
around | ||
}); | ||
}); | ||
}; | ||
} | ||
return { | ||
'http2'(opts) { | ||
depHooks.resolve({ name: 'http2' }, (http2) => { | ||
opts.patchObjects.forEach((obj) => { | ||
const { methods, patchType, patchObjects } = obj; | ||
methods.forEach((method) => { | ||
patcher.patch(http2, method, { | ||
name: `http2.${method}`, | ||
patchType, | ||
post(data) { | ||
const { result: server } = data; | ||
const serverPrototype = server ? Object.getPrototypeOf(server) : null; | ||
opts.patchObjects.forEach(({ methods, patchType, around }) => { | ||
patcher.patch(http2, 'createServer', { | ||
name: 'http2.createServer', | ||
patchType, | ||
post: createPostHook('http2.Server.prototype', patchType, methods, around), | ||
}); | ||
if (!serverPrototype) { | ||
core.logger.error('Unable to patch server prototype, continue without instrumentation'); | ||
return; | ||
} | ||
patchObjects.forEach((obj) => { | ||
const { name, methods, patchType, around } = obj; | ||
methods.forEach((method) => { | ||
patcher.patch(serverPrototype, method, { | ||
name: `http2.${name}.${method}`, | ||
patchType, | ||
around | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
patcher.patch(http2, 'createSecureServer', { | ||
name: 'http2.createSecureServer', | ||
patchType, | ||
post: createPostHook('http2.SecureServer.prototype', patchType, methods, around) | ||
}); | ||
@@ -54,0 +58,0 @@ }); |
{ | ||
"name": "@contrast/instrumentation", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Shared hooks and patches between Protect and Assess components", | ||
@@ -19,2 +19,2 @@ "license": "SEE LICENSE IN LICENSE", | ||
} | ||
} | ||
} |
7933
205
22521