@@ -6,6 +6,7 @@ const { snapshotKinds } = require('./constants')
66const { threadNamePrefix } = require ( './profilers/shared' )
77const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require ( './webspan-utils' )
88const dc = require ( 'dc-polyfill' )
9+ const crashtracker = require ( '../crashtracking' )
910
1011const profileSubmittedChannel = dc . channel ( 'datadog:profiling:profile-submitted' )
1112const spanFinishedChannel = dc . channel ( 'dd-trace:span:finish' )
@@ -197,15 +198,17 @@ class Profiler extends EventEmitter {
197198 throw new Error ( 'No profile types configured.' )
198199 }
199200
200- // collect profiles synchronously so that profilers can be safely stopped asynchronously
201- for ( const profiler of this . _config . profilers ) {
202- const profile = profiler . profile ( restart , startDate , endDate )
203- if ( ! restart ) {
204- this . _logger . debug ( `Stopped ${ profiler . type } profiler in ${ threadNamePrefix } thread` )
201+ crashtracker . withProfilerSerializing ( ( ) => {
202+ // collect profiles synchronously so that profilers can be safely stopped asynchronously
203+ for ( const profiler of this . _config . profilers ) {
204+ const profile = profiler . profile ( restart , startDate , endDate )
205+ if ( ! restart ) {
206+ this . _logger . debug ( `Stopped ${ profiler . type } profiler in ${ threadNamePrefix } thread` )
207+ }
208+ if ( ! profile ) continue
209+ profiles . push ( { profiler, profile } )
205210 }
206- if ( ! profile ) continue
207- profiles . push ( { profiler, profile } )
208- }
211+ } )
209212
210213 if ( restart ) {
211214 this . _capture ( this . _timeoutInterval , endDate )
0 commit comments