diff --git a/packages/dd-trace/src/profiling/profilers/events.js b/packages/dd-trace/src/profiling/profilers/events.js index e1d42484f1..f8f43b06a9 100644 --- a/packages/dd-trace/src/profiling/profilers/events.js +++ b/packages/dd-trace/src/profiling/profilers/events.js @@ -330,13 +330,13 @@ class EventsProfiler { if (!restart) { this.stop() } - const profile = this.eventSerializer.createProfile(startDate, endDate) + const thatEventSerializer = this.eventSerializer this.eventSerializer = new EventSerializer() - return profile + return () => thatEventSerializer.createProfile(startDate, endDate) } encode (profile) { - return pprof.encode(profile) + return pprof.encode(profile()) } }