Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add hook-data concept for hooks. #273

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

kinyoklion
Copy link
Member

This PR

Add support for the hook-data concept for hooks. Hook-data allows for per-evaluation data to be propagated between hooks.

This is especially useful for analytics purposes where you may want to measure things that happen between stages, or you want to do something like create a span in one stage and close it in another.

This concept is similar to the series data concept for LaunchDarkly hooks. https://github.com/launchdarkly/open-sdk-specs/tree/main/specs/HOOK-hooks#evaluationseriesdata

Unlike series data the data in this approach is mutable. This is because the before stage already has a return value. We could workaround this by specifying a return structure, but it maybe seems more complex. The data is only passed to a specific hook instance, so mutability is not of great concern.

Some functional languages may still need to use an immutable with return values approach.

I can create an OFEP if we think this merits discussion prior to proposal.

Related Issues

Related discussion in a PR comment.
open-feature/java-sdk#1049 (comment)

@@ -31,7 +31,9 @@ Hooks can be configured to run globally (impacting all flag evaluations), per cl

### Definitions

**Hook**: Application author/integrator-supplied logic that is called by the OpenFeature framework at a specific stage. **Stage**: An explicit portion of the flag evaluation lifecycle. e.g. `before` being "before the [resolution](../glossary.md#resolving-flag-values) is run. **Invocation**: A single call to evaluate a flag. `client.getBooleanValue(..)` is an invocation. **API**: The global API singleton.
**Hook**: Application author/integrator-supplied logic that is called by the OpenFeature framework at a specific stage.
Copy link
Member Author

Choose a reason for hiding this comment

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

These were all on one line, which seemed hard to read. So I put a blank line between them to get them on multiple lines.

@@ -81,75 +83,154 @@ see: [dynamic-context paradigm](../glossary.md#dynamic-context-paradigm)

> Condition: The provider `metadata` field in the `hook context` **MUST** be immutable.

### 4.3. Hook creation and parameters
### 4.3. Hook data
Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer not renumbering, but I did in this case as conceptually it makes sense to group all the parameter requirements together. I could move this to retain the existing numbering.


> `Hook data` **MUST** must be created before the first `stage` invoked in a hook for a specific evaluation and propagated between each `stage` of the hook.

Example showing data between `before` and `after` stage for two different hooks.
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if the diagram is overkill, but a key concept is that data is not shared between hooks and not shared between evaluations.

Signed-off-by: Ryan Lamb <[email protected]>
Copy link
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

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

I like this proposal, but I would like to see how it could be implemented in an SDK. Properly scoping hook data may be complicated.

specification/sections/04-hooks.md Outdated Show resolved Hide resolved
Co-authored-by: Michael Beemer <[email protected]>
Signed-off-by: Ryan Lamb <[email protected]>
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.

2 participants