Skip to content

Commit 694bf23

Browse files
committed
Use symbol instead of weak map for associating data with contexts
1 parent 092a702 commit 694bf23

File tree

1 file changed

+12
-17
lines changed
  • packages/dd-trace/src/profiling/profilers/event_plugins

1 file changed

+12
-17
lines changed

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,28 @@ class EventPlugin extends TracingPlugin {
1111
super()
1212
this.eventHandler = eventHandler
1313
this.eventFilter = eventFilter
14-
this.contextData = new WeakMap()
1514
this.entryType = this.constructor.entryType
15+
this.dataSymbol = Symbol(`dd-trace.profiling.event.${this.entryType}.${this.constructor.operation}`)
1616
}
1717

1818
start (ctx) {
19-
this.contextData.set(ctx, {
20-
startEvent: ctx,
21-
startTime: performance.now()
22-
})
19+
ctx[this.dataSymbol] = performance.now()
2320
}
2421

2522
error (ctx) {
26-
const data = this.contextData.get(ctx)
27-
if (data) {
28-
data.error = true
29-
}
23+
// We don't emit perf events for failed operations
24+
ctx[this.dataSymbol] = undefined
3025
}
3126

3227
finish (ctx) {
33-
const data = this.contextData.get(ctx)
34-
35-
if (!data) return
36-
this.contextData.delete(ctx)
28+
const startTime = ctx[this.dataSymbol]
29+
if (startTime === undefined) {
30+
return
31+
}
32+
ctx[this.dataSymbol] = undefined
3733

38-
const { startEvent, startTime, error } = data
39-
if (error || this.ignoreEvent(startEvent)) {
40-
return // don't emit perf events for failed operations or ignored events
34+
if (this.ignoreEvent(ctx)) {
35+
return // don't emit perf events for ignored events
4136
}
4237

4338
const duration = performance.now() - startTime
@@ -55,7 +50,7 @@ class EventPlugin extends TracingPlugin {
5550
event._ddSpanId = context?.toSpanId()
5651
event._ddRootSpanId = context?._trace.started[0]?.context().toSpanId() || event._ddSpanId
5752

58-
this.eventHandler(this.extendEvent(event, startEvent))
53+
this.eventHandler(this.extendEvent(event, ctx))
5954
}
6055

6156
ignoreEvent () {

0 commit comments

Comments
 (0)