Skip to content

feat(node-server): add offline rules-based core provider - #469

Open
sameerank wants to merge 19 commits into
mainfrom
sameerank/node-core-provider-offline-init
Open

sameerank wants to merge 19 commits into
mainfrom
sameerank/node-core-provider-offline-init

Conversation

@sameerank

@sameerank sameerank commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Support offline initialization and dynamic, per-request flag evaluation in Node from a portable rules configuration. A valid local snapshot should be usable on the first invocation without a configuration request or PROVIDER_NOT_READY.

This is the provider building block. Customer-facing dd-trace exports, tracking factories, and package releases are follow-up work.

Changes

  • Add DatadogCoreProvider(configuration, options?) to the Node /rules-based entry point. It supports synchronous OpenFeature registration, evaluates each invocation's context locally, and does not start fetching, polling, or uploading.
  • Take detached snapshots on construction and replacement. Invalid replacements leave the active configuration unchanged. setConfiguration() emits a configuration-change event after replacement; getConfiguration() returns a detached copy. Mixed inputs use their rules, not context-bound precomputed assignments.
  • Share the existing Node provider's exposure hook and dependency sidecar. Add internal createExposureTracking() to /rules-based: its providerOptions share deduplication and dependency state, createHook(sink) creates an explicitly registered hook, and clear() resets exposure state. Constructing the helper or provider installs no hooks or uploaders. Preserve the existing internal exposure-channel integration. Preserve deduplication, failed-hook handling, consent metadata, and the current Node experimentation opt-out modes.
  • Keep the root entry point protobuf-free and the declarations self-contained without a runtime OpenFeature dependency. Add regression and installed-package coverage, including cross-entry-point sidecar types.
import { OpenFeature } from '@openfeature/server-sdk'
import { configurationFromString, DatadogCoreProvider } from '@datadog/openfeature-node-server/rules-based'

// wire was prepared with fetchRulesConfiguration({ distributionChannel: 'server', ... })
const provider = new DatadogCoreProvider(configurationFromString(wire))
OpenFeature.setProvider('offline', provider)
const client = OpenFeature.getClient('offline')
const enabled = await client.getBooleanValue('checkout-enabled', false, context)

// Refresh is caller-controlled; evaluations keep using the active snapshot while fetching.
provider.setConfiguration(nextConfiguration)

There is no implicit expiry or refresh ordering policy. Applications own freshness, retries, and storage. Server-distributed rules must stay on the server. Evaluation telemetry opt-out, upload, and writer cleanup remain the tracer integration's responsibility.

Test instructions

  • Node unit suite: 1,089 tests passed across 18 suites with the committed fixture revisions. Includes deterministic overlap coverage for context-only dependency lookup, one-time consumption, distinct root/dependency values, exposure attribution, and assignment-token exclusion.
  • Core and Node builds, browser CommonJS build, Node typecheck, changed-file Biome/Prettier checks, and git diff --check: passed.
  • Built and installed local tarballs in isolated consumers. Runtime and TypeScript checks passed without OpenFeature, with the minimum supported SDK (1.15.0 / core 1.3.0), and with repository versions (1.22.0 / core 1.11.0). OpenFeature-dependent cases are skipped when the SDK is absent. Type checks cover classic, Node16, and NodeNext resolution, including a typed exposure sink with Node 18 declarations.
  • Package-purity and CommonJS/ESM entry-point checks passed. The default entry point still does not load protobuf or export the tracking factory.

The committed package-install tests also run in CI via yarn test:node-install and yarn test:node-install:with-of.

Rollout after this PR

  1. Merge this provider building block and select the Node building-block changes to include in the release.
  2. In a separate follow-up, add a fresh-process provider system-test harness that loads local server rules before synchronous registration. Cover first-evaluation readiness with zero configuration requests, request isolation, explicit refresh, opt-in tracking, and context-bound precomputed rejection. Test the built Node package directly; this does not require tracer exports.
  3. Release the required @datadog/flagging-core changes first, then @datadog/openfeature-node-server with an exact core dependency pin. This PR does not change versions or publish packages.
  4. Update dd-trace-js to consume that release and expose the provider and optional tracking hooks. Reuse its existing exposure and evaluation writers, separate tracking setup from configuration-source startup, and define hook/writer lifecycle ownership. Reuse the offline-provider harness scenarios through the tracer integration.
  5. Release dd-trace-js and activate gated building-block tests once the required exports are available.

Checklist

  • Updated Documentation
  • Tested locally
  • Tested on staging (not part of this local provider change)
  • Added unit tests for this change.
  • Added e2e/integration tests for this change (packed-package consumer tests).

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

OpenFeature Browser Provider Bundle Sizes

Measured from the Vite production output after installing packed @datadog/flagging-core and @datadog/openfeature-browser tarballs.

Both scenarios initialize an OpenFeature provider, evaluate a boolean flag, change context, and evaluate again. Telemetry is disabled for DatadogProvider; no tracking hooks are registered for DatadogCoreProvider. DatadogProvider fetches precomputed assignments for each context; DatadogCoreProvider receives rules from fetchRulesConfiguration once and evaluates locally.

Sizes include OpenFeature and the same small scenario harness. Configuration responses are supplied by Playwright and are not bundled. These are complete scenario JS sizes, not configuration payload sizes or isolated provider/Protobuf costs; the difference between rows is not a decoder-only delta.

Scenario HTML JS Assets Raw JS Gzip JS Protobuf Markers
DatadogProvider (precomputed fetching) provider.html 14 307.9 KiB 95.4 KiB no
DatadogCoreProvider + fetchRulesConfiguration core-provider.html 14 397.5 KiB 120.2 KiB yes

Dependency checks passed: no Protobuf markers in default/precomputed scenarios; markers present in rules-based scenarios.

OpenFeature Browser Tracking Hook Bundle Sizes

Synthetic entrypoints import and call tracking hook factories from the packed @datadog/openfeature-browser/rules-based ESM package. Deltas are measured against the no-hook baseline from the same Vite production build.

Scenario HTML JS Assets Raw JS Raw Δ Gzip JS Gzip Δ
tracking hook baseline tracking-baseline.html 5 13.0 KiB 0 B 5.4 KiB 0 B
exposure logging hook tracking-exposure.html 9 242.2 KiB +229.2 KiB 73.7 KiB +68.3 KiB
evaluation logging hook tracking-evaluation.html 10 237.5 KiB +224.5 KiB 72.3 KiB +66.9 KiB
RUM tracking hook tracking-rum.html 7 33.5 KiB +20.5 KiB 12.1 KiB +6.7 KiB
all tracking hooks tracking-all.html 12 249.8 KiB +236.8 KiB 77.0 KiB +71.7 KiB

OpenFeature Node Server Bundle Sizes

Independent Webpack production builds of the installed core and Node SDK tarballs, targeting Node 18 with ESM (module export condition). Node built-ins remain external. OpenFeature, dd-trace, and configuration fixtures are not bundled.

Scenario Raw JS Gzip JS Protobuf Modules
Node provider only 62.0 KiB 18.4 KiB no
SSR helpers only (fetch client rules + serialize) 85.1 KiB 25.0 KiB yes
Node provider + SSR helpers 145.4 KiB 42.1 KiB yes
Precompute only (parsed rules) 54.9 KiB 18.1 KiB no
Node provider + precompute 83.2 KiB 25.4 KiB no
Precomputed fetch + serialize (root) 16.3 KiB 5.9 KiB no
Precomputed fetch + serialize (/rules-based) 16.3 KiB 5.9 KiB no

Adding SSR helpers to the provider adds 83.4 KiB raw / 23.7 KiB gzip in this build. This includes fetching, parsing, and serialization, not just the decoder. SSR helpers fetch rules for the browser, not for configuring that provider (which uses its existing JSON API).

Adding precomputation to the provider adds 21.2 KiB raw / 7.0 KiB gzip in this build. Both precompute scenarios import precomputeConfiguration from /rules-based and receive already-parsed rules from the test harness; they do not fetch, parse, or serialize configuration.

These are bundler sizes, not npm install sizes, unbundled Node require/import costs, payload sizes, or latency. Gzip compares compressed artifacts. Deltas compare scenarios in this build, not changes against the base branch. The browser scenarios include OpenFeature and a different harness, so their sizes are not directly comparable.

Dependency checks passed: no Protobuf runtime or generated schema modules in the provider-only, precompute, or precomputed-fetch bundles; present in both rules-fetch SSR bundles (checked using Webpack module statistics).

This report shows current PR artifact sizes only; it does not compare against the base branch.

@sameerank sameerank added crucible: reviewing A Crucible review has started; this PR has reviewer attention. and removed crucible: reviewing A Crucible review has started; this PR has reviewer attention. labels Nov 10, 2026
@sameerank
sameerank marked this pull request as ready for review November 10, 2026 21:25
@sameerank
sameerank requested a review from a team as a code owner November 10, 2026 21:25
@sameerank
sameerank force-pushed the sameerank/node-core-provider-offline-init branch from df3af46 to c2f24b0 Compare November 16, 2026 19:38
@sameerank

Copy link
Copy Markdown
Contributor Author

FFE reviewer selection

✅ 🤖 Automated reviewer routing, requested by the PR author. Review coverage is not approval.

Initiative: Dynamic clients, portable configuration and offline startup (local-evaluation-bootstrap)
Adds a Node DatadogCoreProvider that initializes synchronously from a portable rules or precomputed snapshot with no startup fetch, evaluates per-request context locally, and supports caller-controlled refresh via setConfiguration().

Additional review area: OpenFeature architecture
Moves the existing Node provider's exposure hook and dependency-telemetry sidecar into a shared module and adds createExposureTracking(). This changes exposure-hook registration, shared deduplication-cache ownership and provider shutdown contracts used by the tracer integration.

Reviewer Role Request
@typotter Initiative owner; OpenFeature architecture specialist Requested
@leoromanovsky Initiative owner Requested

Existing review requests were preserved. To change routing, correct the PR description or add a reviewer manually.

Routing details
  • Head: 6980922b192d30b9c6f32500b21933337d0148d8
  • Initiative evidence: packages/node-server/src/core-provider.ts, packages/node-server/src/rules-based.ts, packages/node-server/test/core-provider.spec.ts, packages/node-server/test/core-provider-precomputed.spec.ts
  • Architecture evidence: packages/node-server/src/tracking.ts, packages/node-server/src/exposure-tracking.ts, packages/node-server/src/provider.ts, packages/node-server/test/core-provider-tracking.spec.ts

@sameerank
sameerank requested a review from typotter November 17, 2026 19:01
@leoromanovsky leoromanovsky added crucible: reviewing A Crucible review has started; this PR has reviewer attention. and removed crucible: reviewing A Crucible review has started; this PR has reviewer attention. labels Nov 18, 2026
@leoromanovsky

Copy link
Copy Markdown
Collaborator

Merging latest main in and resolving conflicts; then reviewing.

Merge main at 97f730b.
Preserve the Node opt-out policy documentation and regenerate declarations.
@leoromanovsky leoromanovsky added crucible: reviewing A Crucible review has started; this PR has reviewer attention. and removed crucible: reviewing A Crucible review has started; this PR has reviewer attention. labels Nov 18, 2026
Compare Date-valued contexts without record aliases, preserve malformed-flag quarantine across snapshot copies, and contain cache admission failures per exposure. Clarify tracking and cache contracts and strengthen regression coverage.
Retain normalized consent and lenient split features across snapshot copies. Return saved terminal flag errors, avoid exception-based Date checks for foreign records, and add regression coverage.
@typotter

Copy link
Copy Markdown
Collaborator

🤖 Comment from Codex working with @typotter:

Heads up: consider a dedicated offline-initialization system-test harness

For the planned system-test follow-up, could we add a small Node harness that loads a local server-rules fixture before registering DatadogCoreProvider? This would exercise the provider independently of a configuration source, then let the tracer integration reuse the same scenarios once its exports are available.

Suggested harness and assertions
  • Launch a fresh Node process with automatic configuration fetching disabled. Load a local rules fixture, register synchronously, and evaluate immediately. Assert READY, the expected value/variant/reason, and zero configuration requests.
  • Evaluate the same flag with two contexts that deliberately select different values. Overlap the requests and check each result and dependency batch against its original subject.
  • Drive refresh explicitly: verify a valid replacement and its change event, a failed fetch that preserves the active snapshot, and an invalid replacement that throws without replacing it.
  • Run with tracking absent and with an explicitly registered sink. Check no implicit uploader, exposure deduplication, dependency/root attribution, failed-hook rollback and supplied-versus-owned cleanup.
  • Add a context-bound precomputed arm for matching and mismatching contexts, plus consent metadata on rejection.
  • Make the harness load the package built from the reviewed revision. Record its artifact hash, SDK/test SHAs, runtime, commands and pass/fail/skip counts in the local execution receipt.

The existing standalone helper runner offers a fresh-process starting point. These proposed assertions are additional provider coverage. They have not been executed as system tests in this review.

This fits the follow-up already listed in the rollout plan; it is a harness suggestion rather than a request to add tracer exports here.

@sameerank

Copy link
Copy Markdown
Contributor Author

Comment from Codex working with @sameerank:

We plan to add the dedicated offline-provider system-test harness as a separate follow-up. The PR's "Rollout after this PR" section now makes that explicit. The harness will test the built Node package without waiting for tracer exports. We will then reuse those scenarios through dd-trace-js.

@sameerank

Copy link
Copy Markdown
Contributor Author

Started drafting the harness here DataDog/system-tests#8604 and verified by running tests locally

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants