Skip to content

Commit

Permalink
agent: deprecated support for Node <0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalieWolfe committed Mar 30, 2017
1 parent dce4a3b commit b815094
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 79 deletions.
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 1 addition & 18 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 14 additions & 32 deletions lib/instrumentation/core/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 7 additions & 19 deletions lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
}

/**
Expand All @@ -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
}

Expand Down Expand Up @@ -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))
}

/**
Expand All @@ -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]

Expand Down
4 changes: 1 addition & 3 deletions lib/transaction/tracer/instrumentation/outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b815094

Please sign in to comment.