-
Notifications
You must be signed in to change notification settings - Fork 238
Add support for renamed hapi => @hapi/hapi module #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1173d00
6760e2b
567022e
ccae340
329f5bc
97324d6
08b13c9
71c0c6f
8c1a80f
a5224f8
82d71e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ var MODULES = [ | |
| 'generic-pool', | ||
| 'graphql', | ||
| 'handlebars', | ||
| 'hapi', | ||
| ['hapi', '@hapi/hapi'], | ||
| 'http', | ||
| 'https', | ||
| 'http2', | ||
|
|
@@ -70,30 +70,41 @@ function Instrumentation (agent) { | |
| this._patches = new NamedArray() | ||
|
|
||
| for (let mod of MODULES) { | ||
| if (!Array.isArray(mod)) mod = [mod] | ||
| const pathName = mod[0] | ||
|
|
||
| this.addPatch(mod, (exports, name, version, enabled) => { | ||
| // Lazy require so that we don't have to use `require.resolve` which | ||
| // would fail in combination with Webpack. For more info see: | ||
| // https://github.com/elastic/apm-agent-nodejs/pull/957 | ||
| const patch = require(`./modules/${mod}`) | ||
| const patch = require(`./modules/${pathName}`) | ||
| return patch(exports, name, version, enabled) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| Instrumentation.prototype.addPatch = function (name, handler) { | ||
| const type = typeof handler | ||
| if (type !== 'function' && type !== 'string') { | ||
| this._agent.logger.error('Invalid patch handler type:', type) | ||
| return | ||
| } | ||
| Instrumentation.prototype.addPatch = function (modules, handler) { | ||
| if (!Array.isArray(modules)) modules = [modules] | ||
|
|
||
| this._patches.add(name, handler) | ||
| this._startHook() | ||
| modules.forEach(mod => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be |
||
| const type = typeof handler | ||
| if (type !== 'function' && type !== 'string') { | ||
| this._agent.logger.error('Invalid patch handler type:', type) | ||
| return | ||
| } | ||
|
|
||
| this._patches.add(mod, handler) | ||
| this._startHook() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call to |
||
| }) | ||
| } | ||
|
|
||
| Instrumentation.prototype.removePatch = function (name, handler) { | ||
| this._patches.delete(name, handler) | ||
| this._startHook() | ||
| Instrumentation.prototype.removePatch = function (modules, handler) { | ||
| if (!Array.isArray(modules)) modules = [modules] | ||
|
|
||
| modules.forEach(mod => { | ||
| this._patches.delete(mod, handler) | ||
| this._startHook() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, the call to |
||
| }) | ||
| } | ||
|
|
||
| Instrumentation.prototype.clearPatches = function (name) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 'use strict' | ||
|
|
||
| require('./shared')('hapi') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
const pathName = Array.isArray(mod) ? mod[0] : mod, so you don't need to build an array you don't actually need.