Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/node-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ the delivery mechanism so an initialization result already in progress can be re

After `onClose()`, the provider reports no further diagnostics, even if it is initialized again.

### Offline core provider

`DatadogCoreProvider` accepts the same `onDiagnostic` callback and emits the same `SDKDiagnostic` observations.
Timing starts inside its constructor and includes snapshot validation and provider setup. A valid snapshot records
`configuration_received`; completed setup reports `ready`. Failed construction reports `INIT_FAILED` and throws the
original constructor error. Fetching or parsing completed before construction is outside these timings.

Observations are delivered synchronously during construction. Start diagnostic delivery before constructing the
provider so the first observation can be buffered. Callback promises are not awaited, and callback errors do not
affect construction. The provider has no `initialize()` method and remains ready on synchronous OpenFeature
registration. It starts no fetch, poll, or uploader. Without `onDiagnostic`, measurement is disabled.

Caller-owned refresh uses the same `reportConfigurationFetchStart()` and `reportConfigurationFetchResult(success)`
methods as `DatadogNodeServerProvider`. Report one start per sequential refresh attempt, including its retries, and
report the final fetch result. Do not report cancellation as failure. Report fetch success separately from applying
the configuration: invalid replacements and evaluation errors are not fetch failures. A failed refresh leaves the
active snapshot available. The shared outage suppression and cooldown rules above apply.

Successful replacements do not emit another initialization observation. `onClose()` stops diagnostics permanently;
await it before closing diagnostic delivery. Synchronous construction has already succeeded or failed, so closing
the core provider does not create an incomplete initialization observation.

## End-user license agreement

https://www.datadoghq.com/legal/eula
50 changes: 50 additions & 0 deletions packages/node-server/rules-based.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 35 additions & 10 deletions packages/node-server/src/core-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
import { evaluateWithTrace } from './configuration/evaluation'
import { type ExperimentationOptOutMode, resolveExperimentationOptOutMode } from './experimentation-opt-out'
import { NodeProviderEventEmitter } from './provider-event-emitter'
import { type SDKDiagnostic, SDKDiagnostics } from './sdk-diagnostics'
import {
DependencyTelemetrySidecar,
type DependencyTelemetrySidecarApi,
Expand All @@ -34,6 +35,8 @@ import {
} from './tracking'

export interface DatadogCoreProviderOptions {
/** Receives diagnostic observations during construction without awaiting delivery. Omit to disable measurement. */
onDiagnostic?: (diagnostic: SDKDiagnostic) => void | Promise<void>
/** Experiment exclusion policy. Defaults to Disabled. */
experimentationOptOutMode?: ExperimentationOptOutMode
/**
Expand All @@ -54,6 +57,7 @@ export class DatadogCoreProvider implements Provider {
readonly runsOn = 'server' as const
readonly hooks: Hook[] = []
readonly events: ProviderEventEmitter<ServerProviderEvents> = new NodeProviderEventEmitter()
private readonly diagnostics?: SDKDiagnostics
private configuration: FlagsConfiguration
private readonly experimentationOptOutMode: ExperimentationOptOutMode
private readonly exposureCache: AssignmentCache | undefined
Expand All @@ -62,16 +66,25 @@ export class DatadogCoreProvider implements Provider {

// No initialize(): a valid configuration is required before OpenFeature registration.
constructor(configuration: FlagsConfiguration, options: DatadogCoreProviderOptions = {}) {
this.experimentationOptOutMode = resolveExperimentationOptOutMode(options.experimentationOptOutMode)
this.configuration = snapshotConfiguration(configuration)
this.dependencyTelemetrySidecar = options.dependencyTelemetrySidecar ?? new DependencyTelemetrySidecar(false)
this.exposureCache = options.exposureCache
this.ownsExposureCache = options.exposureCache === undefined && options.exposureChannel !== undefined
if (options.exposureChannel) {
this.exposureCache ??= new LRUInMemoryAssignmentCache(50_000)
this.hooks.push(
new ExposureLoggingHook(this.exposureCache, options.exposureChannel, this.dependencyTelemetrySidecar)
)
this.diagnostics = options.onDiagnostic ? new SDKDiagnostics(options.onDiagnostic) : undefined
this.diagnostics?.start(false)
try {
this.experimentationOptOutMode = resolveExperimentationOptOutMode(options.experimentationOptOutMode)
this.configuration = snapshotConfiguration(configuration)
this.diagnostics?.configurationReceived()
this.dependencyTelemetrySidecar = options.dependencyTelemetrySidecar ?? new DependencyTelemetrySidecar(false)
this.exposureCache = options.exposureCache
this.ownsExposureCache = options.exposureCache === undefined && options.exposureChannel !== undefined
if (options.exposureChannel) {
this.exposureCache ??= new LRUInMemoryAssignmentCache(50_000)
this.hooks.push(
new ExposureLoggingHook(this.exposureCache, options.exposureChannel, this.dependencyTelemetrySidecar)
)
}
this.diagnostics?.finish('ready')
} catch (error) {
this.diagnostics?.finish('failed')
throw error
}
}

Expand All @@ -96,7 +109,19 @@ export class DatadogCoreProvider implements Provider {
this.events.emit('PROVIDER_CONFIGURATION_CHANGED' as ServerProviderEvents.ConfigurationChanged)
}

/** Called by the integration once before a sequential configuration poll, including its retries. */
reportConfigurationFetchStart(): void {
this.diagnostics?.fetchStarted()
}

/** Called after the poll succeeds or exhausts retries; cancellations are not fetch failures. */
reportConfigurationFetchResult(success: boolean): void {
this.diagnostics?.fetchResult(success)
}

/** Stops diagnostics permanently and clears the provider-owned exposure cache. Await before closing delivery. */
async onClose(): Promise<void> {
this.diagnostics?.close()
if (this.ownsExposureCache) await this.exposureCache?.clear()
}

Expand Down
1 change: 1 addition & 0 deletions packages/node-server/src/rules-based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { type PrecomputeConfigurationOptions, precomputeConfiguration } from './
export { DatadogCoreProvider, type DatadogCoreProviderOptions } from './core-provider'
export { ExperimentationOptOutMode } from './experimentation-opt-out'
export { createExposureTracking } from './exposure-tracking'
export type { SDKDiagnostic } from './sdk-diagnostics'
Loading