elastic-apm-node
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -0,1 +1,6 @@ | ||
# 2.4.0 - 2019/1/24 | ||
* feat: add ability to set custom log message for errors ([#824](https://github.com/elastic/apm-agent-nodejs/pull/824)) | ||
* feat: add ability to set custom timestamp for errors ([#823](https://github.com/elastic/apm-agent-nodejs/pull/823)) | ||
* feat: add support for custom start/end times ([#818](https://github.com/elastic/apm-agent-nodejs/pull/818)) | ||
# 2.3.0 - 2019/1/22 | ||
@@ -2,0 +7,0 @@ * fix(parsers): move port fix into parser ([#820](https://github.com/elastic/apm-agent-nodejs/pull/820)) |
@@ -77,3 +77,3 @@ 'use strict' | ||
Agent.prototype.startSpan = function (name, type) { | ||
Agent.prototype.startSpan = function () { | ||
return this._instrumentation.startSpan.apply(this._instrumentation, arguments) | ||
@@ -222,3 +222,3 @@ } | ||
var span = this.currentSpan | ||
var timestamp = Date.now() * 1000 | ||
var timestamp = normalizeTimestamp(opts && opts.timestamp) | ||
var context = (span || trans || {})._context || {} | ||
@@ -285,2 +285,7 @@ var req = opts && opts.request instanceof IncomingMessage | ||
error.exception.handled = !opts || opts.handled | ||
// Optional add an alternative error message as well as the exception message | ||
if (opts && opts.message && opts.message !== error.exception.message && !error.log) { | ||
error.log = { message: opts.message } | ||
} | ||
} | ||
@@ -440,1 +445,5 @@ | ||
} | ||
function normalizeTimestamp (timestamp) { | ||
return (timestamp > 0 && Math.floor(timestamp * 1000)) || Date.now() * 1000 | ||
} |
@@ -11,8 +11,6 @@ 'use strict' | ||
function GenericSpan (type, agent, traceContext, timer) { | ||
function GenericSpan (agent, type, opts) { | ||
this._timer = new Timer(opts.timer, opts.startTime) | ||
this._context = TraceContext.startOrResume(opts.childOf, agent._conf) | ||
this._agent = agent | ||
this._context = traceContext instanceof TraceContext | ||
? traceContext.child() | ||
: TraceContext.startOrResume(traceContext, agent._conf) | ||
this._timer = new Timer(timer) | ||
this._tags = null | ||
@@ -49,3 +47,3 @@ | ||
get () { | ||
return this._context.sampled | ||
return this._context.recorded | ||
} | ||
@@ -52,0 +50,0 @@ }) |
@@ -146,7 +146,10 @@ 'use strict' | ||
Instrumentation.prototype.startTransaction = function (name, type, traceparent) { | ||
return new Transaction(this._agent, name, type, traceparent) | ||
Instrumentation.prototype.startTransaction = function (name, type, opts) { | ||
// To be backwards compatible with the old API, we also accept a `traceparent` string | ||
if (typeof opts === 'string') opts = { childOf: opts } | ||
return new Transaction(this._agent, name, type, opts) | ||
} | ||
Instrumentation.prototype.endTransaction = function (result) { | ||
Instrumentation.prototype.endTransaction = function (result, endTime) { | ||
if (!this.currentTransaction) { | ||
@@ -156,3 +159,3 @@ this._agent.logger.debug('cannot end transaction - no active transaction found') | ||
} | ||
this.currentTransaction.end(result) | ||
this.currentTransaction.end(result, endTime) | ||
} | ||
@@ -178,3 +181,3 @@ | ||
Instrumentation.prototype.startSpan = function (name, type) { | ||
Instrumentation.prototype.startSpan = function () { | ||
if (!this.currentTransaction) { | ||
@@ -185,3 +188,3 @@ this._agent.logger.debug('no active transaction found - cannot build new span') | ||
return this.currentTransaction.startSpan(name, type) | ||
return this.currentTransaction.startSpan.apply(this.currentTransaction, arguments) | ||
} | ||
@@ -188,0 +191,0 @@ |
@@ -18,6 +18,16 @@ 'use strict' | ||
function Span (transaction, name, type) { | ||
var traceContext = (transaction._agent._instrumentation.activeSpan || transaction)._context | ||
function Span (transaction, name, type, opts) { | ||
if (!opts) { | ||
opts = { | ||
timer: transaction._timer, | ||
childOf: transaction._agent._instrumentation.activeSpan || transaction | ||
} | ||
} else { | ||
opts.timer = transaction._timer | ||
if (!opts.childOf) { | ||
opts.childOf = transaction._agent._instrumentation.activeSpan || transaction | ||
} | ||
} | ||
GenericSpan.call(this, type, transaction._agent, traceContext, transaction._timer) | ||
GenericSpan.call(this, transaction._agent, type, opts) | ||
@@ -44,3 +54,3 @@ this._db = null | ||
Span.prototype.end = function () { | ||
Span.prototype.end = function (endTime) { | ||
if (this.ended) { | ||
@@ -51,3 +61,3 @@ this._agent.logger.debug('tried to call span.end() on already ended span %o', { span: this.id, parent: this.parentId, trace: this.traceId, name: this.name, type: this.type }) | ||
this._timer.end() | ||
this._timer.end(endTime) | ||
this._agent._instrumentation._recoverTransaction(this.transaction) | ||
@@ -54,0 +64,0 @@ |
@@ -7,16 +7,19 @@ 'use strict' | ||
function Timer (timer) { | ||
// `startTime`: millisecond float | ||
function Timer (timer, startTime) { | ||
this._timer = timer ? timer._timer : microtime() | ||
this.start = this._timer() | ||
this.duration = null | ||
this.start = startTime >= 0 ? startTime * 1000 : this._timer() // microsecond integer | ||
this.duration = null // millisecond float | ||
} | ||
Timer.prototype.end = function () { | ||
// `endTime`: millisecond float | ||
Timer.prototype.end = function (endTime) { | ||
if (this.duration !== null) return | ||
this.duration = this.elapsed() | ||
this.duration = this.elapsed(endTime) | ||
} | ||
Timer.prototype.elapsed = function () { | ||
// durations are in milliseconds ¯\_(ツ)_/¯ | ||
return (this._timer() - this.start) / 1000 | ||
// `endTime`: millisecond float | ||
// returns: millisecond float | ||
Timer.prototype.elapsed = function (endTime) { | ||
return ((endTime >= 0 ? endTime * 1000 : this._timer()) - this.start) / 1000 | ||
} |
@@ -97,3 +97,2 @@ 'use strict' | ||
// Apply reported and requested flags | ||
if (sampled) { | ||
@@ -111,2 +110,7 @@ buffer[OFFSETS.flags] |= FLAGS.recorded | ||
this[bufferSymbol] = buffer | ||
Object.defineProperty(this, 'recorded', { | ||
value: !!(buffer[OFFSETS.flags] & FLAGS.recorded), | ||
enumerable: true | ||
}) | ||
defineLazyProp(this, 'version', hexSliceFn(buffer, OFFSETS.version, OFFSETS.traceId)) | ||
@@ -117,19 +121,10 @@ defineLazyProp(this, 'traceId', hexSliceFn(buffer, OFFSETS.traceId, OFFSETS.id)) | ||
defineLazyProp(this, 'parentId', maybeHexSliceFn(buffer, OFFSETS.parentId)) | ||
const recorded = !!(this[bufferSymbol][OFFSETS.flags] & FLAGS.recorded) | ||
Object.defineProperties(this, { | ||
recorded: { | ||
enumerable: true, | ||
value: recorded | ||
}, | ||
sampled: { | ||
enumerable: true, | ||
value: recorded | ||
} | ||
}) | ||
} | ||
static startOrResume (traceparent, conf) { | ||
return isValidHeader(traceparent) | ||
? resume(traceparent) | ||
static startOrResume (childOf, conf) { | ||
if (childOf instanceof TraceContext) return childOf.child() | ||
if (childOf && childOf._context instanceof TraceContext) return childOf._context.child() | ||
return isValidHeader(childOf) | ||
? resume(childOf) | ||
: start(Math.random() <= conf.transactionSampleRate) | ||
@@ -136,0 +131,0 @@ } |
@@ -15,4 +15,4 @@ 'use strict' | ||
function Transaction (agent, name, type, traceContext) { | ||
GenericSpan.call(this, type, agent, traceContext) | ||
function Transaction (agent, name, type, opts = {}) { | ||
GenericSpan.call(this, agent, type, opts) | ||
@@ -82,3 +82,3 @@ const verb = this.parentId ? 'continue' : 'start' | ||
Transaction.prototype.startSpan = function (name, type) { | ||
Transaction.prototype.startSpan = function (name, type, opts) { | ||
if (!this.sampled) { | ||
@@ -98,3 +98,6 @@ return null | ||
return new Span(this, name, type) | ||
// To be backwards compatible with the old API, we also accept a `traceparent` string | ||
if (typeof opts === 'string') opts = { childOf: opts } | ||
return new Span(this, name, type, opts) | ||
} | ||
@@ -187,3 +190,3 @@ | ||
Transaction.prototype.end = function (result) { | ||
Transaction.prototype.end = function (result, endTime) { | ||
if (this.ended) { | ||
@@ -200,3 +203,3 @@ this._agent.logger.debug('tried to call transaction.end() on already ended transaction %o', { trans: this.id, parent: this.parentId, trace: this.traceId }) | ||
this._timer.end() | ||
this._timer.end(endTime) | ||
this.ended = true | ||
@@ -203,0 +206,0 @@ |
{ | ||
"name": "elastic-apm-node", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "The official Elastic APM agent for Node.js", | ||
@@ -164,5 +164,5 @@ "main": "index.js", | ||
"coordinates": [ | ||
55.6809778, | ||
12.5643414 | ||
55.777969, | ||
12.5907446 | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191376
6
54
4401