Skip to content

Commit a5bd5f9

Browse files
committed
Use private fields in EventPlugin
1 parent 694bf23 commit a5bd5f9

File tree

1 file changed

+16
-11
lines changed
  • packages/dd-trace/src/profiling/profilers/event_plugins

1 file changed

+16
-11
lines changed

packages/dd-trace/src/profiling/profilers/event_plugins/event.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,55 @@ const { performance } = require('perf_hooks')
77
// start/error/finish methods to the appropriate diagnostic channels.
88
// TODO: Decouple this from TracingPlugin.
99
class EventPlugin extends TracingPlugin {
10+
#eventHandler
11+
#eventFilter
12+
#dataSymbol
13+
#entryType
14+
1015
constructor (eventHandler, eventFilter) {
1116
super()
12-
this.eventHandler = eventHandler
13-
this.eventFilter = eventFilter
14-
this.entryType = this.constructor.entryType
15-
this.dataSymbol = Symbol(`dd-trace.profiling.event.${this.entryType}.${this.constructor.operation}`)
17+
this.#eventHandler = eventHandler
18+
this.#eventFilter = eventFilter
19+
this.#entryType = this.constructor.entryType
20+
this.#dataSymbol = Symbol(`dd-trace.profiling.event.${this.#entryType}.${this.constructor.operation}`)
1621
}
1722

1823
start (ctx) {
19-
ctx[this.dataSymbol] = performance.now()
24+
ctx[this.#dataSymbol] = performance.now()
2025
}
2126

2227
error (ctx) {
2328
// We don't emit perf events for failed operations
24-
ctx[this.dataSymbol] = undefined
29+
ctx[this.#dataSymbol] = undefined
2530
}
2631

2732
finish (ctx) {
28-
const startTime = ctx[this.dataSymbol]
33+
const startTime = ctx[this.#dataSymbol]
2934
if (startTime === undefined) {
3035
return
3136
}
32-
ctx[this.dataSymbol] = undefined
37+
ctx[this.#dataSymbol] = undefined
3338

3439
if (this.ignoreEvent(ctx)) {
3540
return // don't emit perf events for ignored events
3641
}
3742

3843
const duration = performance.now() - startTime
3944
const event = {
40-
entryType: this.entryType,
45+
entryType: this.#entryType,
4146
startTime,
4247
duration
4348
}
4449

45-
if (!this.eventFilter(event)) {
50+
if (!this.#eventFilter(event)) {
4651
return
4752
}
4853

4954
const context = (ctx.currentStore?.span || this.activeSpan)?.context()
5055
event._ddSpanId = context?.toSpanId()
5156
event._ddRootSpanId = context?._trace.started[0]?.context().toSpanId() || event._ddSpanId
5257

53-
this.eventHandler(this.extendEvent(event, ctx))
58+
this.#eventHandler(this.extendEvent(event, ctx))
5459
}
5560

5661
ignoreEvent () {

0 commit comments

Comments
 (0)