Skip to content

Commit 041ef5b

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 05e2209 commit 041ef5b

File tree

12 files changed

+1645
-1507
lines changed

12 files changed

+1645
-1507
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
"test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
2929
"test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
3030
"test:eslint-rules": "node eslint-rules/*.test.mjs",
31-
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
32-
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
31+
"test:trace:core": "npm run test:trace:core:tap && npm run test:trace:core:mocha",
32+
"test:trace:core:ci": "npm run test:trace:core:tap:ci && npm run test:trace:core:mocha:ci",
33+
"test:trace:core:tap": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
34+
"test:trace:core:tap:ci": "npm run test:trace:core:tap -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
35+
"test:trace:core:mocha": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/tracing/**/*.spec.js\"",
36+
"test:trace:core:mocha:ci": "nyc --no-clean --include=\"packages/dd-trace/src/**/*.js\" npm run test:trace:core:mocha",
3337
"test:trace:guardrails": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/guardrails/**/*.spec.js\"",
3438
"test:trace:guardrails:ci": "nyc --no-clean --include \"packages/dd-trace/src/guardrails/**/*.js\" -- npm run test:trace:guardrails",
3539
"test:esbuild": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-esbuild/test/**/*.spec.js\"",

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: 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('./tracing/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)