Skip to content

Commit

Permalink
Add manual instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBerisso committed Jun 13, 2019
1 parent cd8b080 commit 850525e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ class Instrumenter {
this._instrumented = new Map()
}

rePatch (name, moduleExports) {
if (!this._enabled) return

if (!this._names.has(name)) {
log.debug(`Could not find a plugin named "${name}". Can't reload`)
return
}

const id = Object.keys(require.cache).find(id => id.includes(`node_modules${path.sep}${name}`))
const baseDir = getBasedir(id)
this.hookModule(moduleExports, name, baseDir)
}

use (name, config) {
if (typeof config === 'boolean') {
config = { enabled: config }
Expand Down
4 changes: 4 additions & 0 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class Tracer extends BaseTracer {
bindEmitter () {
this._deprecate('bindEmitter')
}

instrument (pluginName, moduleExports) {
this._instrumenter.rePatch(pluginName, moduleExports)
}
}

module.exports = Tracer

0 comments on commit 850525e

Please sign in to comment.