UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

37 lines (31 loc) 1.4 kB
'use strict' const RemoteConfigCapabilities = require('../remote_config/capabilities') /** * Configures remote config handlers for openfeature feature flagging * * @param {object} rc - RemoteConfig instance * @param {object} config - Tracer config * @param {Function} getOpenfeatureProxy - Function that returns the OpenFeature proxy from tracer */ function enable (rc, config, getOpenfeatureProxy) { // Always enable capability for feature flag configuration // This indicates the library supports this capability via remote config rc.updateCapabilities(RemoteConfigCapabilities.FFE_FLAG_CONFIGURATION_RULES, true) // Only register product handler if the experimental feature is enabled if (!config.experimental.flaggingProvider.enabled) return // Set product handler for FFE_FLAGS rc.setProductHandler('FFE_FLAGS', (action, conf) => { if (action === 'apply' || action === 'modify') { // Feed UFC config directly to OpenFeature provider getOpenfeatureProxy()._setConfiguration(conf) } else if (action === 'unapply') { // Clear the configuration so evaluations return PROVIDER_NOT_READY, // consistent with Go and Python which also set config to null on RC deletion. // The evaluator returns PROVIDER_NOT_READY when config is null/undefined. getOpenfeatureProxy()._setConfiguration(null) } }) } module.exports = { enable, }