diff --git a/integration-tests/profiler/profiler.spec.js b/integration-tests/profiler/profiler.spec.js index de9ab5626ef..0803e2e9ae4 100644 --- a/integration-tests/profiler/profiler.spec.js +++ b/integration-tests/profiler/profiler.spec.js @@ -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) ]) } diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index fb7367486e7..1ec2462aa69 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -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) { @@ -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,