Skip to content

Commit

Permalink
Logic for heuristic-triggered profiler start.
Browse files Browse the repository at this point in the history
Also make sure mock profiler event emitter runs until heuristics trigger.
  • Loading branch information
szegedi committed May 17, 2024
1 parent 3bb306f commit dd67713
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/dd-trace/src/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ process.once('beforeExit', () => { profiler.stop() })
module.exports = {
start: config => {
const { service, version, env, url, hostname, port, tags, repositoryUrl, commitSHA } = config
const { enabled, sourceMap, exporters } = config.profiling
const { enabled, sourceMap, exporters, heuristicsEnabled } = config.profiling
const logger = {
debug: (message) => log.debug(message),
info: (message) => log.info(message),
Expand All @@ -19,6 +19,7 @@ module.exports = {

return profiler.start({
enabled,
heuristicsEnabled,
service,
version,
env,
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/profiling/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Config {
DD_PROFILING_PPROF_PREFIX, '')

this.enabled = enabled
this.heuristicsEnabled = options.heuristicsEnabled
this.service = service
this.env = env
this.host = host
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/profiling/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Profiler extends EventEmitter {
if (this._enabled) return true

const config = this._config = new Config(options)
if (!config.enabled) return false
if (!config.enabled && !config.heuristicsEnabled) return false

this._logger = config.logger
this._enabled = true
Expand Down
10 changes: 8 additions & 2 deletions packages/dd-trace/src/profiling/ssi-telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ class SSITelemetry {
this._profileCount = profilersNamespace.count('ssi_heuristic.number_of_profiles', tags)
this._runtimeIdCount = profilersNamespace.count('ssi_heuristic.number_of_runtime_id', tags)

if (!this._emittedRuntimeId && decision[0] === 'triggered') {
// Tags won't change anymore, so we can emit the runtime ID metric now
if (
!this._emittedRuntimeId &&
decision[0] === 'triggered' &&
// When enablement choice is SSI_ENABLED, hasSentProfiles can transition from false to true when the
// profiler gets started and the first profile is submitted, so we have to wait for it.
(this.enablementChoice !== EnablementChoice.SSI_ENABLED || this.hasSentProfiles)
) {
// Tags won't change anymore, so we can emit the runtime ID metric now.
this._emittedRuntimeId = true
this._runtimeIdCount.inc()
}
Expand Down
13 changes: 11 additions & 2 deletions packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,17 @@ class Tracer extends NoopProxy {
ssiTelemetry.start()
if (config.profiling.enabled) {
this._profilerStarted = this._startProfiler(config)
} else if (ssiTelemetry.enabled()) {
require('./profiling/ssi-telemetry-mock-profiler').start(config)
} else if (config.profiling.ssi) {
const mockProfiler = require('./profiling/ssi-telemetry-mock-profiler')
mockProfiler.start(config)

if (config.profiling.heuristicsEnabled) {
ssiTelemetry.onHeuristicsTriggered(() => {
mockProfiler.stop()
this._startProfiler(config)
ssiTelemetry.onHeuristicsTriggered()
})
}
}
if (!this._profilerStarted) {
this._profilerStarted = Promise.resolve(false)
Expand Down

0 comments on commit dd67713

Please sign in to comment.