diff --git a/packages/dd-trace/src/appsec/remote_config/index.js b/packages/dd-trace/src/appsec/remote_config/index.js index 169e5c2dff7..64020f2aa48 100644 --- a/packages/dd-trace/src/appsec/remote_config/index.js +++ b/packages/dd-trace/src/appsec/remote_config/index.js @@ -28,7 +28,8 @@ function enable (config, appsec) { rc.updateCapabilities(RemoteConfigCapabilities.ASM_API_SECURITY_SAMPLE_RATE, true) } - rc.on('ASM_FEATURES', (action, rcConfig) => { + rc.on('ASM_FEATURES', (action, rcConfig, id, ack) => { + ack() if (!rcConfig) return if (activation === Activation.ONECLICK) { @@ -106,7 +107,7 @@ function disableWafUpdate () { } } -function noop () {} +function noop (a, b, c, ack) { ack() } module.exports = { enable, diff --git a/packages/dd-trace/src/appsec/remote_config/manager.js b/packages/dd-trace/src/appsec/remote_config/manager.js index 5b0044e2c71..7ac18f72073 100644 --- a/packages/dd-trace/src/appsec/remote_config/manager.js +++ b/packages/dd-trace/src/appsec/remote_config/manager.js @@ -258,11 +258,14 @@ class RemoteConfigManager extends EventEmitter { if (item.apply_state === UNACKNOWLEDGED || action === 'unapply') { try { // TODO: do we want to pass old and new config ? - const hadListeners = this.emit(item.product, action, item.file, item.id) - - if (hadListeners) { - item.apply_state = ACKNOWLEDGED - } + this.emit(item.product, action, item.file, item.id, (err) => { + if (err) { + item.apply_state = ERROR + item.apply_error = err.toString() + } else { + item.apply_state = ACKNOWLEDGED + } + }) } catch (err) { item.apply_state = ERROR item.apply_error = err.toString() diff --git a/packages/dd-trace/src/debugger/devtools_client/remote_config.js b/packages/dd-trace/src/debugger/devtools_client/remote_config.js index 928db448394..4b61429b2da 100644 --- a/packages/dd-trace/src/debugger/devtools_client/remote_config.js +++ b/packages/dd-trace/src/debugger/devtools_client/remote_config.js @@ -35,10 +35,12 @@ let sessionStarted = false // sampling: { snapshotsPerSecond: 5000 }, // evaluateAt: 'EXIT' // only used for method probes // } -rcPort.on('message', async ({ action, conf: probe }) => { +rcPort.on('message', async ({ action, conf: probe, ackId }) => { try { await processMsg(action, probe) + rcPort.postMessage({ ackId }) } catch (err) { + rcPort.postMessage({ ackId, error: err }) ackError(err, probe) } }) diff --git a/packages/dd-trace/src/debugger/index.js b/packages/dd-trace/src/debugger/index.js index 18019c16a83..9e5cf22fd34 100644 --- a/packages/dd-trace/src/debugger/index.js +++ b/packages/dd-trace/src/debugger/index.js @@ -17,13 +17,21 @@ function start (config, rc) { log.debug('Starting Dynamic Instrumentation client...') - rc.on('LIVE_DEBUGGING', (action, conf) => { - rcChannel.port2.postMessage({ action, conf }) - }) - + const rcAckCallbacks = new Map() const rcChannel = new MessageChannel() configChannel = new MessageChannel() + rc.on('LIVE_DEBUGGING', (action, conf, id, ack) => { + const ackId = `${id}-${conf.version}` + rcAckCallbacks.set(ackId, ack) + rcChannel.port2.postMessage({ action, conf, ackId }) + }) + + rcChannel.port2.on('message', ({ ackId, error }) => { + rcAckCallbacks.get(ackId)(error) + rcAckCallbacks.delete(ackId) + }) + worker = new Worker( join(__dirname, 'devtools_client', 'index.js'), { diff --git a/packages/dd-trace/src/proxy.js b/packages/dd-trace/src/proxy.js index 241141588c1..9c679e77045 100644 --- a/packages/dd-trace/src/proxy.js +++ b/packages/dd-trace/src/proxy.js @@ -84,7 +84,8 @@ class Tracer extends NoopProxy { if (config.remoteConfig.enabled && !config.isCiVisibility) { const rc = remoteConfig.enable(config, this._modules.appsec) - rc.on('APM_TRACING', (action, conf) => { + rc.on('APM_TRACING', (action, conf, id, ack) => { + ack() if (action === 'unapply') { config.configure({}, true) } else { @@ -93,7 +94,8 @@ class Tracer extends NoopProxy { this._enableOrDisableTracing(config) }) - rc.on('AGENT_CONFIG', (action, conf) => { + rc.on('AGENT_CONFIG', (action, conf, id, ack) => { + ack() if (!conf?.name?.startsWith('flare-log-level.')) return if (action === 'unapply') { @@ -104,7 +106,8 @@ class Tracer extends NoopProxy { } }) - rc.on('AGENT_TASK', (action, conf) => { + rc.on('AGENT_TASK', (action, conf, id, ack) => { + ack() if (action === 'unapply' || !conf) return if (conf.task_type !== 'tracer_flare' || !conf.args) return diff --git a/packages/dd-trace/test/appsec/remote_config/manager.spec.js b/packages/dd-trace/test/appsec/remote_config/manager.spec.js index 8e5fdc6b516..166d2f0bf49 100644 --- a/packages/dd-trace/test/appsec/remote_config/manager.spec.js +++ b/packages/dd-trace/test/appsec/remote_config/manager.spec.js @@ -3,7 +3,7 @@ const Capabilities = require('../../../src/appsec/remote_config/capabilities') const { UNACKNOWLEDGED, ACKNOWLEDGED, ERROR } = require('../../../src/appsec/remote_config/apply_states') -const noop = () => {} +const noop = (a, b, c, ack) => { ack() } describe('RemoteConfigManager', () => { let uuid