UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

71 lines (60 loc) 2.37 kB
'use strict' const { DatadogNodeServerProvider } = require('@datadog/openfeature-node-server') const { channel } = require('dc-polyfill') const log = require('../log') const { EXPOSURE_CHANNEL } = require('./constants/constants') const EvalMetricsHook = require('./eval-metrics-hook') const SpanEnrichmentHook = require('./span-enrichment-hook') /** * OpenFeature provider that integrates with Datadog's feature flagging system. * Extends DatadogNodeServerProvider to add tracer integration and configuration management. */ class FlaggingProvider extends DatadogNodeServerProvider { /** @type {SpanEnrichmentHook?} */ #spanEnrichmentHook /** * @param {import('../tracer')} tracer - Datadog tracer instance * @param {import('../config')} config - Tracer configuration object */ constructor (tracer, config) { // Call parent constructor with required options and timeout super({ exposureChannel: channel(EXPOSURE_CHANNEL), initializationTimeoutMs: config.experimental.flaggingProvider.initializationTimeoutMs, }) this._tracer = tracer this._config = config this.hooks.push(new EvalMetricsHook(config)) if (config.experimental.flaggingProvider.spanEnrichment?.enabled) { this.#spanEnrichmentHook = new SpanEnrichmentHook(tracer) this.hooks.push(this.#spanEnrichmentHook) log.info('%s span enrichment enabled', this.constructor.name) } else { log.info('%s span enrichment disabled', this.constructor.name) } log.debug('%s created with timeout: %dms', this.constructor.name, config.experimental.flaggingProvider.initializationTimeoutMs) } /** * Called when the provider is shut down. * Cleans up resources including channel subscriptions. */ onClose () { this.#spanEnrichmentHook?.destroy() } /** * Internal method to update flag configuration from Remote Config. * This method is called automatically when Remote Config delivers UFC updates. * * @internal * @param {import('@datadog/openfeature-node-server').UniversalFlagConfigurationV1} ufc * - Universal Flag Configuration object */ _setConfiguration (ufc) { if (typeof this.setConfiguration === 'function') { this.setConfiguration(ufc) } log.debug('%s provider configuration updated', this.constructor.name) } } module.exports = FlaggingProvider