Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark crashes that happen during collecting profiles as profiler_serializing:1 #5096

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"node": ">=18"
},
"dependencies": {
"@datadog/libdatadog": "^0.3.0",
"@datadog/libdatadog": "^0.4.0",
"@datadog/native-appsec": "8.4.0",
"@datadog/native-iast-rewriter": "2.6.1",
"@datadog/native-iast-taint-tracking": "3.2.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/dd-trace/src/crashtracking/crashtracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class Crashtracker {
}
}

withProfilerSerializing (f) {
binding.beginProfilerSerializing()
try {
return f()
} finally {
binding.endProfilerSerializing()
}
}

// TODO: Send only configured values when defaults are fixed.
_getConfig (config) {
const { hostname = '127.0.0.1', port = 8126 } = config
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/crashtracking/noop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
class NoopCrashtracker {
configure () {}
start () {}
withProfilerSerializing (f) {
return f()
}
}

module.exports = new NoopCrashtracker()
19 changes: 11 additions & 8 deletions packages/dd-trace/src/profiling/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { snapshotKinds } = require('./constants')
const { threadNamePrefix } = require('./profilers/shared')
const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require('./webspan-utils')
const dc = require('dc-polyfill')
const crashtracker = require('../crashtracking')

const profileSubmittedChannel = dc.channel('datadog:profiling:profile-submitted')
const spanFinishedChannel = dc.channel('dd-trace:span:finish')
Expand Down Expand Up @@ -197,15 +198,17 @@ class Profiler extends EventEmitter {
throw new Error('No profile types configured.')
}

// collect profiles synchronously so that profilers can be safely stopped asynchronously
for (const profiler of this._config.profilers) {
const profile = profiler.profile(restart, startDate, endDate)
if (!restart) {
this._logger.debug(`Stopped ${profiler.type} profiler in ${threadNamePrefix} thread`)
crashtracker.withProfilerSerializing(() => {
// collect profiles synchronously so that profilers can be safely stopped asynchronously
for (const profiler of this._config.profilers) {
const profile = profiler.profile(restart, startDate, endDate)
if (!restart) {
this._logger.debug(`Stopped ${profiler.type} profiler in ${threadNamePrefix} thread`)
}
if (!profile) continue
profiles.push({ profiler, profile })
}
if (!profile) continue
profiles.push({ profiler, profile })
}
})

if (restart) {
this._capture(this._timeoutInterval, endDate)
Expand Down
Loading