Skip to content

Commit 2370e2e

Browse files
watsonQard
authored andcommitted
perf: cache 'ids' value of transactions and spans (#1434) (#1438)
1 parent 650ae83 commit 2370e2e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

lib/instrumentation/generic-span.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function GenericSpan (agent, type, opts) {
1313
this._context = TraceParent.startOrResume(opts.childOf, agent._conf) // _context is used by the OT bridge, and should unfortunately therefore be considered public
1414
this._agent = agent
1515
this._labels = null
16+
this._ids = null // Populated by sub-types of GenericSpan
1617

1718
this.timestamp = this._timer.start
1819
this.type = type || 'custom'

lib/instrumentation/span.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function Span (transaction, name, type, opts) {
4949

5050
Object.defineProperty(Span.prototype, 'ids', {
5151
get () {
52-
return new SpanIds(this)
52+
return this._ids === null
53+
? (this._ids = new SpanIds(this))
54+
: this._ids
5355
}
5456
})
5557

lib/instrumentation/transaction.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ Object.defineProperty(Transaction.prototype, 'result', {
7575

7676
Object.defineProperty(Transaction.prototype, 'ids', {
7777
get () {
78-
return new TransactionIds(this)
78+
return this._ids === null
79+
? (this._ids = new TransactionIds(this))
80+
: this._ids
7981
}
8082
})
8183

0 commit comments

Comments
 (0)