diff --git a/index.js b/index.js index cba2f6c3bb..c3c1746b7b 100644 --- a/index.js +++ b/index.js @@ -42,14 +42,15 @@ function initialize() { logger.warn(BETA_MESSAGE) try { - logger.debug("Process was running %s seconds before agent was loaded.", - process.uptime()) - // Technically we run on 0.6, until we verify there are 0 users on 0.6, we - // should leave this code doing a check against 0.6, but then advise that - // people upgrade to one of our officially supported version (0.8 and higher) - if (semver.satisfies(process.version, '<0.6.0')) { + logger.debug( + 'Process was running %s seconds before agent was loaded.', + process.uptime() + ) + + // TODO: Update this check when Node v0.10 is deprecated. + if (semver.satisfies(process.version, '<0.10.0')) { message = "New Relic for Node.js requires a version of Node equal to or\n" + - "greater than 0.8.0. Not starting!" + "greater than 0.10.0. Not starting!" logger.error(message) throw new Error(message) diff --git a/lib/environment.js b/lib/environment.js index 5dbb1fddf9..8399f6ab6f 100644 --- a/lib/environment.js +++ b/lib/environment.js @@ -313,28 +313,11 @@ function findPackages() { addSetting('Dependencies', flattenVersions(dependencies)) } -function badOS() { - var badVersion = false - - if (!process.versions) { - badVersion = true - } else { - var version = process.versions.node.split('.') - if (version[1] <= 8 && version[2] <= 5) badVersion = true - } - - return badVersion && - os.arch() === 'x64' && - os.type() === 'SunOS' -} - /** * Settings actually get scraped below. */ function gatherEnv() { - // in 64-bit SmartOS zones, node <= 0.8.5 pukes on os.cpus() - if (!badOS()) addSetting('Processors', os.cpus().length) - + addSetting('Processors', os.cpus().length) addSetting('OS', os.type()) addSetting('OS version', os.release()) addSetting('Node.js version', process.version) diff --git a/lib/instrumentation/core/globals.js b/lib/instrumentation/core/globals.js index 903880f133..8806689a07 100644 --- a/lib/instrumentation/core/globals.js +++ b/lib/instrumentation/core/globals.js @@ -25,39 +25,21 @@ var NATIVE_PROMISE_SPEC = { } function initialize(agent) { - // Add handler for uncaught/fatal exceptions to record them. - // _fatalException is an undocumented feature of domains, introduced in - // Node.js v0.8. We use _fatalException when possible because wrapping it will - // not potentially change the behavior of the server. - if (process._fatalException) { - wrap(process, 'process', '_fatalException', function wrapper(original) { - return function wrappedFatalException(error) { - // Only record the error if we are not currently within an instrumented - // domain. - if (!process.domain) { - agent.errors.add(null, error) - agent.tracer.segment = null - } - return original.apply(this, arguments) + // `_fatalException` is an undocumented feature of domains, introduced in + // Node.js v0.8. We use `_fatalException` because wrapping it will not + // potentially change the behavior of the server unlike listening for + // `uncaughtException`. + wrap(process, 'process', '_fatalException', function wrapper(original) { + return function wrappedFatalException(error) { + // Only record the error if we are not currently within an instrumented + // domain. + if (!process.domain) { + agent.errors.add(null, error) + agent.tracer.segment = null } - }) - } else { - wrap( - process, - 'process', - 'emit', - function wrapEmit(original) { - return function wrappedEmit(ev, error) { - if (ev === 'uncaughtException' && error && !process.domain) { - agent.errors.add(null, error) - agent.tracer.segment = null - } - - return original.apply(this, arguments) - } - } - ) - } + return original.apply(this, arguments) + } + }) // Add a handler for unhandled promise rejections. process.on('unhandledRejection', function __NR_unhandledRejectionHandler(err, promise) { diff --git a/lib/timer.js b/lib/timer.js index fc2fccde8c..3a0c13c090 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -28,9 +28,9 @@ function hrToMillis(hr) { function Timer() { this.state = PENDING this.touched = false - this.duration = null this.hrDuration = null this.hrstart = null + this.start = null this.durationInMillis = null } @@ -43,8 +43,7 @@ Timer.prototype.begin = function begin() { if (this.state > PENDING) return this.start = Date.now() - // need to put a guard on this for compatibility with Node < 0.8 - if (process.hrtime) this.hrstart = process.hrtime() + this.hrstart = process.hrtime() this.state = RUNNING } @@ -54,9 +53,8 @@ Timer.prototype.begin = function begin() { Timer.prototype.end = function end() { if (this.state > RUNNING) return if (this.state === PENDING) this.begin() - if (process.hrtime) this.hrDuration = process.hrtime(this.hrstart) + this.hrDuration = process.hrtime(this.hrstart) this.touched = true - this.duration = Date.now() - this.start this.state = STOPPED } @@ -68,8 +66,7 @@ Timer.prototype.touch = function touch() { if (this.state > RUNNING) return if (this.state === PENDING) this.begin() - if (process.hrtime) this.hrDuration = process.hrtime(this.hrstart) - this.duration = Date.now() - this.start + this.hrDuration = process.hrtime(this.hrstart) } /** @@ -83,9 +80,8 @@ Timer.prototype.softEnd = function softEnd() { this.state = STOPPED if (this.touched) return false - if (process.hrtime) this.hrDuration = process.hrtime(this.hrstart) + this.hrDuration = process.hrtime(this.hrstart) this.touched = true - this.duration = Date.now() - this.start return true } @@ -162,15 +158,7 @@ Timer.prototype.getDurationInMillis = function getDurationInMillis() { return hrToMillis(this.hrDuration) } - if (this.duration) { - return this.duration - } - - if (process.hrtime) { - return hrToMillis(process.hrtime(this.hrstart)) - } - - return Date.now() - this.start + return hrToMillis(process.hrtime(this.hrstart)) } /** @@ -192,7 +180,7 @@ Timer.prototype.toRange = function toRange() { * @return {number} The offset in (floating-point) milliseconds. */ Timer.prototype.startedRelativeTo = function startedRelativeTo(other) { - if (this.hrstart && other.hrstart && process.hrtime) { + if (this.hrstart && other.hrstart) { var s = this.hrstart[0] - other.hrstart[0] var ns = this.hrstart[1] - other.hrstart[1] diff --git a/lib/transaction/tracer/instrumentation/outbound.js b/lib/transaction/tracer/instrumentation/outbound.js index c12a46bec6..3655e053b2 100644 --- a/lib/transaction/tracer/instrumentation/outbound.js +++ b/lib/transaction/tracer/instrumentation/outbound.js @@ -42,9 +42,7 @@ module.exports = function instrumentOutbound(agent, hostname, port, makeRequest) return function wrappedRequestEmit(evnt, arg) { if (evnt === 'error') { segment.end() - if (handleError(request, arg)) { - return // FIXME In v2 we should always call emit. - } + handleError(request, arg) } else if (evnt === 'response') { handleResponse(segment, request, arg) }