Skip to content

Commit

Permalink
PROF-9791: Recognize DD_PROFILING_ENABLED=auto as an alternative for …
Browse files Browse the repository at this point in the history
…SSI profiling (#4375)

* Recognize DD_PROFILING_ENABLED=auto as an alternative to DD_INJECTION_ENABLED=profiler

* Fix incorrect use of 'profiling' in DD_INJECTION_ENABLED, rely on already established env properties.
  • Loading branch information
szegedi committed Jun 5, 2024
1 parent 4d52460 commit c831ffa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
60 changes: 36 additions & 24 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,53 +500,65 @@ describe('profiler', () => {

describe('does not trigger for', () => {
it('a short-lived app that creates no spans', () => {
return heuristicsDoesNotTriggerFor([], false)
return heuristicsDoesNotTriggerFor([], false, false)
})

it('a short-lived app that creates a span', () => {
return heuristicsDoesNotTriggerFor(['create-span'], true)
return heuristicsDoesNotTriggerFor(['create-span'], true, false)
})

it('a long-lived app that creates no spans', () => {
return heuristicsDoesNotTriggerFor(['long-lived'], false)
return heuristicsDoesNotTriggerFor(['long-lived'], false, false)
})

it('a short-lived app that creates no spans with the auto env var', () => {
return heuristicsDoesNotTriggerFor([], false, true)
})

it('a short-lived app that creates a span with the auto env var', () => {
return heuristicsDoesNotTriggerFor(['create-span'], true, true)
})

it('a long-lived app that creates no spans with the auto env var', () => {
return heuristicsDoesNotTriggerFor(['long-lived'], false, true)
})
})

it('triggers for long-lived span-creating app', () => {
return checkProfiles(agent,
forkSsi(['create-span', 'long-lived']),
timeout,
DEFAULT_PROFILE_TYPES,
false,
// Will receive 2 messages: first one is for the trace, second one is for the profile. We
// only need the assertions in checkProfiles to succeed for the one with the profile.
2)
return heuristicsTrigger(false)
})

it('triggers for long-lived span-creating app with the auto env var', () => {
return heuristicsTrigger(true)
})
})

function forkSsi (args) {
function forkSsi (args, whichEnv) {
const profilerEnablingEnv = whichEnv ? { DD_PROFILING_ENABLED: 'auto' } : { DD_INJECTION_ENABLED: 'profiler' }
return fork(ssiTestFile, args, {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_INJECTION_ENABLED: 'profiler',
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300'
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300',
...profilerEnablingEnv
}
})
}

function heuristicsDoesNotTriggerFor (args, allowTraceMessage) {
proc = fork(ssiTestFile, args, {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_INJECTION_ENABLED: 'profiler',
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300'
}
})
function heuristicsTrigger (whichEnv) {
return checkProfiles(agent,
forkSsi(['create-span', 'long-lived'], whichEnv),
timeout,
DEFAULT_PROFILE_TYPES,
false,
// Will receive 2 messages: first one is for the trace, second one is for the profile. We
// only need the assertions in checkProfiles to succeed for the one with the profile.
2)
}

function heuristicsDoesNotTriggerFor (args, allowTraceMessage, whichEnv) {
return Promise.all([
processExitPromise(proc, timeout, false),
processExitPromise(forkSsi(args, whichEnv), timeout, false),
expectTimeout(expectProfileMessagePromise(agent, 1500), allowTraceMessage)
])
}
Expand Down
8 changes: 3 additions & 5 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,9 @@ class Config {
this._setBoolean(env, 'profiling.enabled', coalesce(DD_EXPERIMENTAL_PROFILING_ENABLED, DD_PROFILING_ENABLED))
this._setString(env, 'profiling.exporters', DD_PROFILING_EXPORTERS)
this._setBoolean(env, 'profiling.sourceMap', DD_PROFILING_SOURCE_MAP && !isFalse(DD_PROFILING_SOURCE_MAP))
if (DD_INJECTION_ENABLED) {
if (DD_PROFILING_ENABLED === 'auto' || DD_INJECTION_ENABLED) {
this._setBoolean(env, 'profiling.ssi', true)
if (DD_INJECTION_ENABLED.split(',').includes('profiler')) {
if (DD_PROFILING_ENABLED === 'auto' || DD_INJECTION_ENABLED.split(',').includes('profiler')) {
this._setBoolean(env, 'profiling.heuristicsEnabled', true)
}
if (DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD) {
Expand Down Expand Up @@ -720,9 +720,7 @@ class Config {
this._setBoolean(env, 'telemetry.dependencyCollection', DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED)
this._setValue(env, 'telemetry.heartbeatInterval', maybeInt(Math.floor(DD_TELEMETRY_HEARTBEAT_INTERVAL * 1000)))
const hasTelemetryLogsUsingFeatures =
isTrue(DD_IAST_ENABLED) ||
isTrue(DD_PROFILING_ENABLED) ||
(typeof DD_INJECTION_ENABLED === 'string' && DD_INJECTION_ENABLED.split(',').includes('profiling'))
env['iast.enabled'] || env['profiling.enabled'] || env['profiling.heuristicsEnabled']
? true
: undefined
this._setBoolean(env, 'telemetry.logCollection', coalesce(DD_TELEMETRY_LOG_COLLECTION_ENABLED,
Expand Down

0 comments on commit c831ffa

Please sign in to comment.