UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

64 lines (52 loc) 2.26 kB
'use strict' const { channel } = require('dc-polyfill') const log = require('../log') const configurationSource = require('./configuration_source') const { EXPOSURE_CHANNEL } = require('./constants/constants') const EvalMetricsHook = require('./eval-metrics-hook') const SpanEnrichmentHook = require('./span-enrichment-hook') const { DatadogNodeServerProvider } = require('./require-provider') /** * 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 | undefined} */ #spanEnrichmentHook /** @type {{ start: Function, stop: Function } | undefined} */ #configurationSource /** * @param {import('../tracer')} tracer - Datadog tracer instance * @param {import('../config/config-base')} config - Tracer configuration object */ constructor (tracer, config) { super({ exposureChannel: channel(EXPOSURE_CHANNEL), initializationTimeoutMs: config.experimental.flaggingProvider.initializationTimeoutMs, }) this.hooks.push(new EvalMetricsHook(config)) if (config.experimental.flaggingProvider.spanEnrichment?.enabled) { this.#spanEnrichmentHook = new SpanEnrichmentHook(tracer) // @ts-expect-error The upstream constructor always initializes its optional hooks property. 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) this.#configurationSource = configurationSource.create(config, this.setConfiguration.bind(this)) this.#configurationSource?.start() } /** * Called when the provider is shut down. * Cleans up resources including channel subscriptions. */ onClose () { this.#configurationSource?.stop() this.#configurationSource = undefined this.#spanEnrichmentHook?.destroy() this.#spanEnrichmentHook = undefined } } module.exports = FlaggingProvider