Skip to content

Run the OpenFeature provider's hooks behind one hook (FFE optimization) - #13693

Open
dougqh wants to merge 4 commits into
masterfrom
dougqh/ffe-composite-provider-hook
Open

dougqh wants to merge 4 commits into
masterfrom
dougqh/ffe-composite-provider-hook

Conversation

@dougqh

@dougqh dougqh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

The Datadog OpenFeature provider now registers its hooks with OpenFeature as one hook, CompositeProviderHook, instead of up to five. Evaluation results, telemetry, exposures, span enrichment and debug logging are unchanged.

Motivation

On every evaluation, the OpenFeature Java SDK (1.23.0, the version dd-openfeature builds against) does setup work for each registered hook: it merges and filters the hook lists into a new list of Pairs, creates a HookContext and a DefaultHookData for each hook, and then calls every hook at every stage. The provider registers two to five hooks (flag evaluation metrics, flag evaluation logging, span enrichment, debug logging and exposures). With the telemetry opt-out on, each telemetry hook is also wrapped in its own EvaluationTelemetryOptOutHook.

All of those hooks act only at the finally stage, so one hook can run them all. The SDK then does its per-hook setup once.

Measured with #13529's ClientEvaluationBenchmark on a roll-up of the open FFE optimization PRs, with and without this change (same jar build, JDK 17, G1 with a 2 GB heap, -t 4, 3 forks per side, -prof gc):

Scenario Before After Change
flags, unpaced 1,457 ns [1,343–1,518], 816 B 1,122 ns [1,092–1,165], 655 B −23% time, −160 B
flags, paced at 10k 853 B 692 B −161 B, time within noise
splits, paced at 4k 1,552 B 1,402 B −150 B, time within noise
variations, paced at 20k 7,585 B 7,453 B −132 B, time within noise

The benchmark host had high CPU steal (median 23%), so deltas under about 5–7% are unconfirmed. The flags time gap is well outside that.

For scale: on the same client and benchmark, a provider that returns a constant and registers no hooks costs 107 ns and 136 B per evaluation. That's the SDK's floor for any provider.

Additional Notes

  • Same behavior as separate hooks: the hooks run in registration order (exposures last). A hook is skipped for a flag type it doesn't support, and a hook that throws is logged without stopping the others. That matches what the SDK does at the finally stage.
  • Evaluation telemetry opt-out: the dd_evaluation_telemetry_opt_out decision is made once per evaluation in the composite's before stage, with the same fallback to the error stage when an application before hook fails. It replaces one EvaluationTelemetryOptOutHook per telemetry hook, which is deleted. Exposures and debug logging still aren't gated. The existing opt-out tests pass unchanged.
  • Shared hook data: the inner hooks share the composite's HookContext, including its hook data. Only the opt-out used hook data, so nothing collides today. The class Javadoc notes that hook data keys must be distinct.
  • Tests: registration tests now look at the hooks behind the composite. New unit tests cover hook order, failure isolation, flag-type filtering and the opt-out gating, and a guard test fails if any provider hook starts acting outside the finally stage, since the composite would never call it there.
  • Alternative not taken: most of this cost is in the SDK client and applies to every provider. A separate upstream change (parallel arrays or a cached filtered hook list in HookSupport) would reduce it for everyone. This change only reduces how many hooks we ask the SDK to set up.

🤖 Generated with Claude Code

The OpenFeature SDK builds a list entry, a hook context and hook data for
every registered hook on every evaluation, then calls each hook at every
stage. All of the provider's hooks act only at the finally stage, so they
now run behind one CompositeProviderHook: in registration order, skipped
for unsupported flag types, and with a failing hook logged without
stopping the rest, as the SDK does. The evaluation telemetry opt-out is
decided once per evaluation, replacing one EvaluationTelemetryOptOutHook
wrapper per telemetry hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements tag: performance Performance related changes tag: ai generated Largely based on code generated by an AI or LLM comp: openfeature OpenFeature labels Nov 25, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 95.52%
• Overall Coverage: 83.46% (+22.24%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 90785a7 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.89 s 14.76 s [+0.2%; +1.6%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.71 s 13.80 s [-1.5%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.78 s 17.63 s [-0.0%; +1.7%] (no difference)
startup:petclinic:iast:Agent 17.47 s 17.69 s [-2.0%; -0.5%] (maybe better)
startup:petclinic:profiling:Agent 17.45 s 17.28 s [-0.2%; +2.1%] (no difference)
startup:petclinic:sca:Agent 17.60 s 17.66 s [-1.1%; +0.5%] (no difference)
startup:petclinic:tracing:Agent 16.79 s 16.88 s [-1.7%; +0.6%] (no difference)

Commit: 90785a75 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh
dougqh marked this pull request as ready for review November 30, 2026 18:46
@dougqh
dougqh requested review from a team as code owners November 30, 2026 18:46
@dougqh
dougqh requested review from PerfectSlayer, ValentinZakharov, leoromanovsky and sarahchen6 and removed request for a team November 30, 2026 18:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T18:50:46.690160Z 3d32e3e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The static reviewer identified no reportable defect in hook consolidation or telemetry opt-out handling. Exact equivalence with OpenFeature SDK hook ordering remains unverified because dependency sources and binaries were unavailable locally.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3d32e3e

@sarahchen6 sarahchen6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable!

*
* <p>On every evaluation, the OpenFeature SDK builds a list entry, a hook context and hook data for
* each registered hook, then calls each hook at every stage. All of the provider's hooks only act
* at the finally stage, so running them behind one hook pays that setup once, whatever the number

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
* at the finally stage, so running them behind one hook pays that setup once, whatever the number
* at the final stage, so running them behind one hook pays that setup once, whatever the number

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 11d0adb.

final HookContext<Object> context,
final FlagEvaluationDetails<Object> details,
final Map<String, Object> hints) {
final boolean optedOut =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from Codex that seems valid to me-

Keep exposure and debug hooks running if the telemetry opt-out lookup throws. The lookup now happens before the per-hook try block in finallyAfter(). If an application-supplied EvaluationContext throws on that lookup, OpenFeature catches the exception from the composite after it has already skipped exposure and debug logging. Previously, each telemetry wrapper failed independently. Catch and log the lookup failure, skip telemetry, and continue the ungated hooks. Add a regression test that throws during the final lookup and asserts the exposure hook still runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that was a real regression. Fixed in 11d0adb: finallyAfter now logs a failing opt-out lookup and skips only the telemetry hooks, so exposures and debug logging still run, as they did when each telemetry hook was gated separately. aThrowingOptOutLookupSkipsTelemetryButNotTheOtherHooks uses a context whose lookups throw; it fails on the previous code and passes now. before and error keep the old behavior: with the per-hook wrappers, a throwing lookup there failed in the same way.

}
hooks.addTelemetry(spanEnrichmentHook);
}
hooks.optOutEnabled(options.isEvaluationTelemetryOptOutParameterEnabled(this.settings));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can gate this check on evaluationTelemetryEnabled as well? if evaluationTelemetryEnabled=false then can skip this opt-out check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 11d0adb, one level down: the builder turns the opt-out off when no telemetry hook is registered. All three telemetry hooks (metrics, EVP logging, span enrichment) are only created with evaluationTelemetryEnabled, so that covers your case, plus the one where metrics are unavailable without the OTel API. withoutTelemetryHooksTheOptOutParameterIsNotRead checks that the parameter isn't read.

}
}

private static final class MapHookData implements HookData {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (from Codex): replace MapHookData with OpenFeature's public DefaultHookData which is already used by the OpenFeature Java SDK: https://github.com/open-feature/java-sdk/blob/v1.23.0/src/main/java/dev/openfeature/sdk/HookSupport.java#L69-L72

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 11d0adb: the test uses the SDK's public DefaultHookData (we build against 1.23.0, where it's public with a public constructor), and MapHookData is gone.

dougqh and others added 3 commits November 30, 2026 16:12
The composite reads the telemetry opt-out once, ahead of every hook, so a
context that threw on that lookup skipped exposures and debug logging
too. The failure is now logged and only telemetry is skipped, as when
each telemetry hook was gated separately. With no telemetry hooks
registered, the parameter isn't read at all. The test uses the SDK's
DefaultHookData instead of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Return the hooks through one unmodifiable view, make isOptedOut private,
rejoin two comments the formatter split mid-sentence, and drop a
redundant line from the hook-name test. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document that only finallyAfter runs for the hooks behind the composite,
and guard it with a test that fails if any provider hook overrides the
before, after or error stage. Warn once when the opt-out lookup throws,
then log at debug, as the sibling hooks do. Static-import the
Collections helpers, reword a comment the formatter kept splitting, and
rename a stale test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aarsilv aarsilv added the crucible: reviewing A Crucible review has started; this PR has reviewer attention. label Dec 1, 2026
@dd-octo-sts

dd-octo-sts Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

PR Blocked - Invalid Label

The pull request introduced unexpected labels:

  • crucible: reviewing

This PR is blocked until:

  1. The invalid labels are deleted, and
  2. A maintainer deletes this comment to unblock the PR

Note: Simply removing labels from the pull request is not enough - a maintainer must delete this comment then remove the label to remove the block.

@aarsilv aarsilv removed the crucible: reviewing A Crucible review has started; this PR has reviewer attention. label Dec 1, 2026

@leoromanovsky leoromanovsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. I'm also investigating an upstream improvement to per-hook overhead in the OpenFeature Java SDK. It would complement this change rather than replace it, since the provider has to keep supporting SDK versions that don't have it.

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

comp: openfeature OpenFeature tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants