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 hooks implementation #95

Merged
merged 9 commits into from
Jan 13, 2025

Conversation

MaximFischuk
Copy link
Contributor

@MaximFischuk MaximFischuk commented Dec 16, 2024

This PR

This pull request introduces the implementation of Hooks in the OpenFeature SDK following the OpenFeature standard. The changes include the addition of hooks to various stages in the feature flag evaluation process, such as before, after, error, and finally. The implementation provides capabilities to add hooks at the global, client, provider, and invocation levels, which allows for extensive customizability and control over the feature flag lifecycle.

  • Adds hooks to support the OpenFeature specification for flag evaluation.
  • Implements the capability to register hooks at various levels including global, client, provider, and invocation.
  • Introduces logging for lifecycle events using hooks.
  • Provides test cases for the new hooks capability to ensure compliance with the OpenFeature specification.

Related Issues

Fixes #5

Notes

  • Make sure logging is appropriately configured in the consuming application to take advantage of the logging hooks.
  • This implementation supports extensibility for additional hooks in the future by following the standardized hook interface.

Follow-up Tasks

  • Consider implementing example hooks that demonstrate different use cases, like metrics collection or error reporting.
  • Evaluate if default hooks should be provided in the SDK for common use cases.

How to test

  1. Build and run the example included in examples/hooks.rs to see a working implementation of the hooks in action.
  2. Review test cases provided in src/hooks/mod.rs to ensure they cover expected behaviors and edge cases.
  3. Ensure that the hooks are called in the correct order and can handle errors gracefully.

@MaximFischuk MaximFischuk changed the title Feature/hooks feat: Add hooks implementation Dec 16, 2024
@MaximFischuk MaximFischuk force-pushed the feature/hooks branch 4 times, most recently from 1d86d02 to fafe675 Compare December 17, 2024 09:53
Signed-off-by: Maxim Fischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
@MaximFischuk MaximFischuk marked this pull request as ready for review December 18, 2024 13:35
src/hooks/logging.rs Outdated Show resolved Hide resolved
…ment 4.3.8` of OpenFeature specification

Signed-off-by: MaximFischuk <mfischuk@vareger.com>
@beeme1mr
Copy link
Member

Hey @MaximFischuk, reviews may be slower than usual around the holidays. Hopefully, someone can take a look soon.

I'll do my best to review, but my Rust skills are basically non-existent 😄

Copy link
Member

@gruebel gruebel left a comment

Choose a reason for hiding this comment

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

overall great job 🍻

Cargo.toml Outdated Show resolved Hide resolved
src/api/api.rs Outdated Show resolved Hide resolved
src/evaluation/context_field_value.rs Show resolved Hide resolved
src/api/client.rs Outdated Show resolved Hide resolved
src/api/client.rs Outdated Show resolved Hide resolved
src/hooks/logging.rs Outdated Show resolved Hide resolved
src/serde_json.rs Outdated Show resolved Hide resolved
…ncy, remove accidentally committed todos

Signed-off-by: MaximFischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
src/hooks/logging.rs Outdated Show resolved Hide resolved
src/hooks/logging.rs Outdated Show resolved Hide resolved
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.

This PR looks good from a spec perspective.

Before this is merged, could you please update the hooks section in the readme?

Thanks @MaximFischuk!

src/hooks/logging.rs Outdated Show resolved Hide resolved
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
Signed-off-by: MaximFischuk <mfischuk@vareger.com>
@MaximFischuk
Copy link
Contributor Author

@beeme1mr @jbovet @gruebel Thank you for your review!

I've extended the implementation of the logging hook to support both text and structured features of the log crate. Unfortunately, it's impossible to serialize EvaluationContext into JSON for structured logging without changing EvaluationContextFieldValue type for a moment, so I've currently left it as is.

@beeme1mr Also, I've updated README.md to include documentation about new features.

@MaximFischuk MaximFischuk requested a review from jbovet January 10, 2025 21:20
@beeme1mr
Copy link
Member

I'll give folks the weekend to review. If there are no concerns, I'll merge early next week. Thanks @MaximFischuk.

Copy link
Member

@gruebel gruebel left a comment

Choose a reason for hiding this comment

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

nice work 🍻

@jbovet
Copy link

jbovet commented Jan 13, 2025

I've extended the implementation of the logging hook to support both text and structured features of the log crate. Unfortunately, it's impossible to serialize EvaluationContext into JSON for structured logging without changing EvaluationContextFieldValue type for a moment, so I've currently left it as is.

changes look great! Implementation of the logging hook provides a flexible solution for tracking feature flag evaluations into the SDK.
Overall, this is an excellent contribution that enhances the observability capabilities while maintaining flexibility and usability. Great work @MaximFischuk

Copy link

@jbovet jbovet left a comment

Choose a reason for hiding this comment

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

@MaximFischuk well done!

@beeme1mr beeme1mr merged commit 2fd80ae into open-feature:main Jan 13, 2025
8 checks passed
@jbovet jbovet mentioned this pull request Jan 13, 2025
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.

[SDK] implement hooks
4 participants