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 logging hook, rm logging from evaluation #1084

Merged
merged 7 commits into from
Sep 5, 2024

Conversation

toddbaert
Copy link
Member

@toddbaert toddbaert commented Sep 3, 2024

Implements: open-feature/spec#269

This PR removes logging from the main evaluation code path, with a couple exceptions:

  • unhandled errors in before/finally/error hooks (after hooks may throw in order to do validation)
  • unhandled errors in event handlers

(IMO these represent bugs in code, since they should be handled, and not transient errors).

It also adds a LoggingHook as per the spec link above, which adds SLF4J structured logs for evaluation objects.

@toddbaert toddbaert requested a review from a team as a code owner September 3, 2024 15:43
@toddbaert toddbaert force-pushed the feat/logging-compliance branch from 064c509 to fdb14a8 Compare September 3, 2024 15:43
Signed-off-by: Todd Baert <[email protected]>
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.31%. Comparing base (78e3371) to head (8e17466).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...dev/openfeature/sdk/hooks/logging/LoggingHook.java 96.77% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1084      +/-   ##
============================================
+ Coverage     95.03%   95.31%   +0.27%     
- Complexity      392      401       +9     
============================================
  Files            38       39       +1     
  Lines           886      917      +31     
  Branches         54       56       +2     
============================================
+ Hits            842      874      +32     
+ Misses           24       23       -1     
  Partials         20       20              
Flag Coverage Δ
unittests 95.31% <97.67%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Todd Baert <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
@@ -17,19 +17,28 @@
@SuppressWarnings({ "unchecked", "rawtypes" })
class HookSupport {
Copy link
Member Author

Choose a reason for hiding this comment

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

No functional changes in this class, I just re-ordered some methods to make the class read more sensibly, and added a bit more information to the log statement.

try {
hookCode.accept(hook);
} catch (Exception exception) {
log.error("Unhandled exception when running {} hook {} (only 'after' hooks should throw)", hookMethod,
Copy link
Member Author

Choose a reason for hiding this comment

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

This ONLY runs for hooks which we expect not to throw (before/finally/error).

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.

Please add a section that describes the logging hook to the readme.

Signed-off-by: Todd Baert <[email protected]>
@toddbaert
Copy link
Member Author

Please add a section that describes the logging hook to the readme.

Please check out my addition.

toddbaert added a commit to open-feature/spec that referenced this pull request Sep 4, 2024
As discussed in recent meetings, we've had complaints about this from
multiple sources. This PR adds a stipulation that no logging is done by
the SDK during flag evaluation. It also defines a very simple `logging
hook` concept as an included utility. These should be very simple to
write and will provide all the needed logging but give authors more
control than built in log statements. It will also be a very nice intro
to the hooks concept for users.

Here's the Java implementation:
open-feature/java-sdk#1084

---------

Signed-off-by: Todd Baert <[email protected]>
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan left a comment

Choose a reason for hiding this comment

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

Looks good. Please check this remark though [1]

[1] - https://github.com/open-feature/java-sdk/pull/1084/files#r1744351346

Copy link

sonarqubecloud bot commented Sep 5, 2024

@toddbaert toddbaert merged commit 037826f into main Sep 5, 2024
10 checks passed
@toddbaert toddbaert deleted the feat/logging-compliance branch September 5, 2024 16:33
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.

4 participants