From 30485d4788dfb33ed3601b66da72e35829f35cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Tue, 10 Sep 2024 16:24:43 +0200 Subject: [PATCH] [test visibility] Enable log collection for test visibility (#4657) --- packages/dd-trace/src/config.js | 9 +-------- packages/dd-trace/src/telemetry/index.js | 1 + packages/dd-trace/test/config.spec.js | 17 +++-------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index 625a9ce19fa..db473b42525 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -535,7 +535,7 @@ class Config { this._setValue(defaults, 'telemetry.dependencyCollection', true) this._setValue(defaults, 'telemetry.enabled', true) this._setValue(defaults, 'telemetry.heartbeatInterval', 60000) - this._setValue(defaults, 'telemetry.logCollection', false) + this._setValue(defaults, 'telemetry.logCollection', true) this._setValue(defaults, 'telemetry.metrics', true) this._setValue(defaults, 'traceId128BitGenerationEnabled', true) this._setValue(defaults, 'traceId128BitLoggingEnabled', false) @@ -1068,13 +1068,6 @@ class Config { calc['tracePropagationStyle.inject'] = calc['tracePropagationStyle.inject'] || defaultPropagationStyle calc['tracePropagationStyle.extract'] = calc['tracePropagationStyle.extract'] || defaultPropagationStyle } - - const iastEnabled = coalesce(this._options['iast.enabled'], this._env['iast.enabled']) - const profilingEnabled = coalesce(this._options['profiling.enabled'], this._env['profiling.enabled']) - const injectionIncludesProfiler = (this._env.injectionEnabled || []).includes('profiler') - if (iastEnabled || ['auto', 'true'].includes(profilingEnabled) || injectionIncludesProfiler) { - this._setBoolean(calc, 'telemetry.logCollection', true) - } } _applyRemote (options) { diff --git a/packages/dd-trace/src/telemetry/index.js b/packages/dd-trace/src/telemetry/index.js index 612c23b7ca1..a0b0619a11d 100644 --- a/packages/dd-trace/src/telemetry/index.js +++ b/packages/dd-trace/src/telemetry/index.js @@ -137,6 +137,7 @@ function appClosing () { sendData(config, application, host, reqType, payload) // We flush before shutting down. metricsManager.send(config, application, host) + telemetryLogger.send(config, application, host) } function onBeforeExit () { diff --git a/packages/dd-trace/test/config.spec.js b/packages/dd-trace/test/config.spec.js index 1150a98c257..0c18150850e 100644 --- a/packages/dd-trace/test/config.spec.js +++ b/packages/dd-trace/test/config.spec.js @@ -360,7 +360,7 @@ describe('Config', () => { { name: 'telemetry.dependencyCollection', value: true, origin: 'default' }, { name: 'telemetry.enabled', value: true, origin: 'env_var' }, { name: 'telemetry.heartbeatInterval', value: 60000, origin: 'default' }, - { name: 'telemetry.logCollection', value: false, origin: 'default' }, + { name: 'telemetry.logCollection', value: true, origin: 'default' }, { name: 'telemetry.metrics', value: true, origin: 'default' }, { name: 'traceId128BitGenerationEnabled', value: true, origin: 'default' }, { name: 'traceId128BitLoggingEnabled', value: false, origin: 'default' }, @@ -1450,7 +1450,7 @@ describe('Config', () => { expect(config.telemetry).to.not.be.undefined expect(config.telemetry.enabled).to.be.true expect(config.telemetry.heartbeatInterval).to.eq(60000) - expect(config.telemetry.logCollection).to.be.false + expect(config.telemetry.logCollection).to.be.true expect(config.telemetry.debug).to.be.false expect(config.telemetry.metrics).to.be.true }) @@ -1488,7 +1488,7 @@ describe('Config', () => { process.env.DD_TELEMETRY_METRICS_ENABLED = origTelemetryMetricsEnabledValue }) - it('should not set DD_TELEMETRY_LOG_COLLECTION_ENABLED', () => { + it('should disable log collection if DD_TELEMETRY_LOG_COLLECTION_ENABLED is false', () => { const origLogsValue = process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED = 'false' @@ -1499,17 +1499,6 @@ describe('Config', () => { process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED = origLogsValue }) - it('should set DD_TELEMETRY_LOG_COLLECTION_ENABLED if DD_IAST_ENABLED', () => { - const origIastEnabledValue = process.env.DD_IAST_ENABLED - process.env.DD_IAST_ENABLED = 'true' - - const config = new Config() - - expect(config.telemetry.logCollection).to.be.true - - process.env.DD_IAST_ENABLED = origIastEnabledValue - }) - it('should set DD_TELEMETRY_DEBUG', () => { const origTelemetryDebugValue = process.env.DD_TELEMETRY_DEBUG process.env.DD_TELEMETRY_DEBUG = 'true'