feat(node-server): detailed flag evaluation trace (RFC)#246
Draft
typotter wants to merge 3 commits into
Draft
Conversation
Implements the detailed flag evaluation trace RFC. Every evaluation now produces a DDFlagEvaluationDetails with per-allocation outcomes (BEFORE_START_TIME, AFTER_END_TIME, RULES_MISMATCH, TRAFFIC_MISS, MISSING_VARIATION, UNEVALUATED) and a matched allocation record. The provider converts this to ResolutionDetails via toResolutionDetails(). An opt-in includeEvaluationTrace provider option serializes the full trace into flagMetadata.ddEvaluationTrace for observability use cases. Pre-waterfall error paths (PROVIDER_NOT_READY, FLAG_NOT_FOUND, etc.) are handled with empty allocation lists per PRE_WATERFALL_CODES. Rules matching now exposes findMatchingRuleIndex so the matched rule position is captured in the trace.
Adds the design document that specifies DDFlagEvaluationDetails, the AllocationOutcomeCode enum, DDFlagEvaluationDetailsBuilder, and the toResolutionDetails() OpenFeature boundary conversion implemented in the preceding commit.
Adds 5 unit tests covering the full ddEvaluationTrace JSON content (all top-level fields, waterfall with AFTER_END_TIME/BEFORE_START_TIME/ RULES_MISMATCH, DEFAULT with all unmatched, FLAG_NOT_FOUND with empty arrays, early MATCH with unevaluated allocations). Adds demo.spec.ts showing EvaluationDetails returned from the OpenFeature client with the full ddEvaluationTrace for three scenarios: US user (MATCH via rule index 1), GB user (RULES_MISMATCH → default-off), flag not found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the detailed flag evaluation trace RFC for the
@datadog/openfeature-node-serverpackage.Every flag evaluation now produces a
DDFlagEvaluationDetailsobject with a full allocation waterfall trace, surfacing why each allocation was skipped or matched. The trace is available at the OpenFeature boundary via an opt-inincludeEvaluationTraceprovider option.What's new
DDFlagEvaluationDetails<T>— internal evaluation result with per-allocation outcome records, matched rule index, config metadata, and a structuredoutcomeCodeenumDDFlagEvaluationDetailsBuilder— recordsBEFORE_START_TIME,AFTER_END_TIME,RULES_MISMATCH,TRAFFIC_MISS,MISSING_VARIATION, andUNEVALUATEDoutcomes as the waterfall executestoResolutionDetails()— converts the internal type toResolutionDetails; serializes the full trace intoflagMetadata.ddEvaluationTracewhenincludeEvaluationTrace: truefindMatchingRuleIndex()inrules.ts— returns the 0-indexed matched rule position for trace capturePROVIDER_NOT_READY,FLAG_NOT_FOUND,TARGETING_KEY_MISSING) now carryconfigFetchedAtandenvironmentNamewhen availableChanges
src/configuration/flagEvaluationDetails.ts— new file (types, builder,toResolutionDetails)src/configuration/evaluateForSubject.ts— returnsDDFlagEvaluationDetails, records per-allocation outcomessrc/configuration/evaluation.ts— returnsDDFlagEvaluationDetails, threads config metadatasrc/rules/rules.ts— addsfindMatchingRuleIndexsrc/provider.ts— addsincludeEvaluationTraceoption, callstoResolutionDetailstest/flagEvaluationDetails.spec.ts— 37 tests (32 original + 5 covering full trace JSON content)test/demo.spec.ts— interactive demo (not a CI test; see below)docs/rfc-detailed-flag-evaluation.md— design documentRunning the demo
demo.spec.tsexercises three evaluation scenarios through the real OpenFeature client and prints theEvaluationDetailsobject and the full parsedddEvaluationTracefor each:Scenarios covered:
MATCHat allocationus-betavia rule index 1, two prior allocations skipped (AFTER_END_TIME,BEFORE_START_TIME), one unevaluatedAFTER_END_TIME,BEFORE_START_TIME,RULES_MISMATCHtodefault-off(MATCH)FLAG_NOT_FOUNDwith null match fields and empty allocation arraysTest plan
npm testpasses (280 tests, all suites green)includeEvaluationTrace: false(default) produces noddEvaluationTraceinflagMetadataincludeEvaluationTrace: trueproduces a parseable JSON trace with correctoutcomeCode, allocation lists, and config metadatanpx jest --testPathPatterns=demo --verbose --silent=false) and inspect the printed trace