Skip to content

Commit 40b1dcb

Browse files
committed
refactor(remote_config): move capability registration to feature modules
Move remote config capability and handler registration from central location to feature-specific modules for better separation of concerns. Changes: - Create tracing/remote_config.js for APM_TRACING_* capabilities and handler - Create openfeature/remote_config.js for FFE_FLAG_CONFIGURATION_RULES capability - Remove remote_config/index.js wrapper, instantiate RemoteConfig directly in proxy - Rename RemoteConfigManager class to RemoteConfig - Rename remote_config/manager.js to remote_config/index.js - Replace chai with node:assert/strict in remote_config tests - Use real implementations in proxy tests instead of stubbing This creates a consistent pattern where features own their remote config setup: - Core APM tracing → tracing/remote_config.js (always enabled) - OpenFeature → openfeature/remote_config.js (conditional) - AppSec → appsec/remote_config.js (conditional)
1 parent 7c19acf commit 40b1dcb

File tree

11 files changed

+1625
-1489
lines changed

11 files changed

+1625
-1489
lines changed

packages/dd-trace/src/appsec/remote_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ let rc
1111

1212
/**
1313
* Configures remote config handlers for appsec features
14-
* @param {Object} rcInstance - RemoteConfigManager instance
1514
*
15+
* @param {Object} rcInstance - RemoteConfig instance
1616
* @param {Object} config - Tracer config
1717
* @param {Object} appsec - Appsec module
1818
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
const RemoteConfigCapabilities = require('../remote_config/capabilities')
4+
5+
/**
6+
* Configures remote config for core APM tracing functionality
7+
*
8+
* @param {Object} rc - RemoteConfig instance
9+
* @param {Object} config - Tracer config
10+
* @param {Function} enableOrDisableTracing - Function to enable/disable tracing based on config
11+
*/
12+
function enable (rc, config, enableOrDisableTracing) {
13+
// Register core APM tracing capabilities
14+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_CUSTOM_TAGS, true)
15+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_HTTP_HEADER_TAGS, true)
16+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_LOGS_INJECTION, true)
17+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_SAMPLE_RATE, true)
18+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_ENABLED, true)
19+
rc.updateCapabilities(RemoteConfigCapabilities.APM_TRACING_SAMPLE_RULES, true)
20+
21+
// APM_TRACING product handler - manages tracer configuration
22+
rc.setProductHandler('APM_TRACING', (action, conf) => {
23+
if (action === 'unapply') {
24+
config.configure({}, true)
25+
} else {
26+
config.configure(conf.lib_config, true)
27+
}
28+
enableOrDisableTracing(config)
29+
})
30+
}
31+
32+
module.exports = {
33+
enable
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
3+
const RemoteConfigCapabilities = require('../remote_config/capabilities')
4+
5+
/**
6+
* Configures remote config handlers for openfeature feature flagging
7+
*
8+
* @param {Object} rc - RemoteConfig instance
9+
* @param {Object} config - Tracer config
10+
* @param {Function} getOpenfeatureProxy - Function that returns the OpenFeature proxy from tracer
11+
*/
12+
function enable (rc, config, getOpenfeatureProxy) {
13+
// Always enable capability for feature flag configuration
14+
// This indicates the library supports this capability via remote config
15+
rc.updateCapabilities(RemoteConfigCapabilities.FFE_FLAG_CONFIGURATION_RULES, true)
16+
17+
// Only register product handler if the experimental feature is enabled
18+
if (!config.experimental.flaggingProvider.enabled) return
19+
20+
// Set product handler for FFE_FLAGS
21+
rc.setProductHandler('FFE_FLAGS', (action, conf) => {
22+
// Feed UFC config directly to OpenFeature provider
23+
if (action === 'apply' || action === 'modify') {
24+
getOpenfeatureProxy()._setConfiguration(conf)
25+
}
26+
})
27+
}
28+
29+
module.exports = {
30+
enable
31+
}

packages/dd-trace/src/proxy.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,11 @@ class Tracer extends NoopProxy {
126126
}
127127

128128
if (config.remoteConfig.enabled && !config.isCiVisibility) {
129-
const rc = require('./remote_config').enable(config)
129+
const RemoteConfig = require('./remote_config')
130+
const rc = new RemoteConfig(config)
130131

131-
rc.setProductHandler('APM_TRACING', (action, conf) => {
132-
if (action === 'unapply') {
133-
config.configure({}, true)
134-
} else {
135-
config.configure(conf.lib_config, true)
136-
}
137-
this._enableOrDisableTracing(config)
138-
})
132+
const tracingRemoteConfig = require('./config/remote_config')
133+
tracingRemoteConfig.enable(rc, config, this._enableOrDisableTracing.bind(this))
139134

140135
rc.setProductHandler('AGENT_CONFIG', (action, conf) => {
141136
if (!conf?.name?.startsWith('flare-log-level.')) return
@@ -165,14 +160,8 @@ class Tracer extends NoopProxy {
165160
DynamicInstrumentation.start(config, rc)
166161
}
167162

168-
if (config.experimental.flaggingProvider.enabled) {
169-
rc.setProductHandler('FFE_FLAGS', (action, conf) => {
170-
// Feed UFC config directly to OpenFeature provider
171-
if (action === 'apply' || action === 'modify') {
172-
this.openfeature._setConfiguration(conf)
173-
}
174-
})
175-
}
163+
const openfeatureRemoteConfig = require('./openfeature/remote_config')
164+
openfeatureRemoteConfig.enable(rc, config, () => this.openfeature)
176165
}
177166

178167
if (config.profiling.enabled === 'true') {

0 commit comments

Comments
 (0)