Skip to content

Commit

Permalink
Recognize DD_PROFILING_ENABLED=heuristic as an alternative to DD_INJE…
Browse files Browse the repository at this point in the history
…CTION_ENABLED=profiler
  • Loading branch information
szegedi committed Jun 4, 2024
1 parent 9b410b7 commit b4c54ff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 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 other env var', () => {
return heuristicsDoesNotTriggerFor([], false, true)
})

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

it('a long-lived app that creates no spans with the other 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 other env var', () => {
return heuristicsTrigger(true)
})
})

function forkSsi (args) {
function forkSsi (args, whichEnv) {
const profilerEnablingEnv = whichEnv ? { DD_INJECTION_ENABLED: 'profiler' } : { DD_PROFILING_ENABLED: 'heuristic' }
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
4 changes: 2 additions & 2 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 === 'heuristic' || DD_INJECTION_ENABLED) {
this._setBoolean(env, 'profiling.ssi', true)
if (DD_INJECTION_ENABLED.split(',').includes('profiler')) {
if (DD_PROFILING_ENABLED === 'heuristic' || DD_INJECTION_ENABLED.split(',').includes('profiler')) {
this._setBoolean(env, 'profiling.heuristicsEnabled', true)
}
if (DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD) {
Expand Down

0 comments on commit b4c54ff

Please sign in to comment.