Skip to content

Commit 26722b3

Browse files
authored
Mark crashes that happen during collecting profiles as profiler_serializing:1 (#5096)
1 parent 6523d94 commit 26722b3

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"node": ">=18"
8282
},
8383
"dependencies": {
84-
"@datadog/libdatadog": "^0.3.0",
84+
"@datadog/libdatadog": "^0.4.0",
8585
"@datadog/native-appsec": "8.4.0",
8686
"@datadog/native-iast-rewriter": "2.6.1",
8787
"@datadog/native-iast-taint-tracking": "3.2.0",

packages/dd-trace/src/crashtracking/crashtracker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class Crashtracker {
4040
}
4141
}
4242

43+
withProfilerSerializing (f) {
44+
binding.beginProfilerSerializing()
45+
try {
46+
return f()
47+
} finally {
48+
binding.endProfilerSerializing()
49+
}
50+
}
51+
4352
// TODO: Send only configured values when defaults are fixed.
4453
_getConfig (config) {
4554
const { hostname = '127.0.0.1', port = 8126 } = config

packages/dd-trace/src/crashtracking/noop.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
class NoopCrashtracker {
44
configure () {}
55
start () {}
6+
withProfilerSerializing (f) {
7+
return f()
8+
}
69
}
710

811
module.exports = new NoopCrashtracker()

packages/dd-trace/src/profiling/profiler.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { snapshotKinds } = require('./constants')
66
const { threadNamePrefix } = require('./profilers/shared')
77
const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require('./webspan-utils')
88
const dc = require('dc-polyfill')
9+
const crashtracker = require('../crashtracking')
910

1011
const profileSubmittedChannel = dc.channel('datadog:profiling:profile-submitted')
1112
const 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

Comments
 (0)