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: Implement Default Logging Hook #308

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

Conversation

kylejuliandev
Copy link

@kylejuliandev kylejuliandev commented Oct 4, 2024

This PR

  • Adds in default Logging Hook

Related Issues

Fixes #299

Notes

Follow-up Tasks

How to test

@beeme1mr
Copy link
Member

beeme1mr commented Oct 9, 2024

Hey @kylejuliandev, thanks for the PR. Could you please sign off your commits? The CNCF requires you to acknowledge that you're willing and able to donate this code.

To add your Signed-off-by line to every commit in this branch:

Thanks!

@kylejuliandev kylejuliandev force-pushed the feat/add-logging-hook branch from d5d08f7 to b4b4765 Compare October 9, 2024 21:18
@kylejuliandev
Copy link
Author

Hi @beeme1mr!

No worries, I've pushed up the signed commits now. Happy to donate this code, although it is incomplete at the moment. Will resume and get some unit tests in. Logging semantics (log IDs, log levels, content, etc...) are still left to determine - although I have tried to adhere to the spec

@askpt
Copy link
Member

askpt commented Jan 9, 2025

Hey, @kylejuliandev!

Great work on this PR; everything seems good to go. As you pointed out, however, a few unit tests are missing to get this PR out. Would you like some help?

Just a tiny suggestion: I would move the src/OpenFeature/LoggingHook.cs file into src/OpenFeature/Hooks/LoggingHook.cs and change the namespace to OpenFeature.Hooks.

@kylejuliandev
Copy link
Author

Thanks for the reminder @askpt - I completely forgot about this, my bad!

I have added some unit tests now to cover the LoggingHook. I suspect another task may include updating the README for guidance on how to use the hook.

@kylejuliandev kylejuliandev force-pushed the feat/add-logging-hook branch from 0f48130 to dff409c Compare January 9, 2025 21:04
@kylejuliandev kylejuliandev force-pushed the feat/add-logging-hook branch from dff409c to ea2b393 Compare January 9, 2025 21:15
@beeme1mr
Copy link
Member

beeme1mr commented Jan 9, 2025

I suspect another task may include updating the README for guidance on how to use the hook.

Yes please! Here's an example from the Java SDK. Thanks

https://github.com/open-feature/java-sdk?tab=readme-ov-file#logging-hook

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 94.50549% with 5 lines in your changes missing coverage. Please review.

Project coverage is 86.19%. Comparing base (1b5a0a9) to head (0b46216).

Files with missing lines Patch % Lines
src/OpenFeature/Hooks/LoggingHook.cs 94.50% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #308      +/-   ##
==========================================
+ Coverage   85.49%   86.19%   +0.69%     
==========================================
  Files          38       39       +1     
  Lines        1517     1608      +91     
  Branches      154      173      +19     
==========================================
+ Hits         1297     1386      +89     
+ Misses        188      186       -2     
- Partials       32       36       +4     

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

@kylejuliandev kylejuliandev marked this pull request as ready for review January 9, 2025 21:45
@kylejuliandev kylejuliandev requested a review from a team as a code owner January 9, 2025 21:45
Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

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

Added a few comments.

Comment on lines 25 to 27
if (logger == null) throw new ArgumentNullException(nameof(logger));

this._logger = logger;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (logger == null) throw new ArgumentNullException(nameof(logger));
this._logger = logger;
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));

Copy link
Author

Choose a reason for hiding this comment

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

Good shout! I've added the null-coalesing operator inplace of doing a seperate if null check

Comment on lines 124 to 126
stringBuilder.Append("Domain:");
stringBuilder.Append(this._domain);
stringBuilder.Append(Environment.NewLine);
Copy link
Member

Choose a reason for hiding this comment

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

This code can be simplified. The same applies for the next lines.

Suggested change
stringBuilder.Append("Domain:");
stringBuilder.Append(this._domain);
stringBuilder.Append(Environment.NewLine);
stringBuilder.AppendLine($"Domain: {this._domain}");

Copy link
Author

Choose a reason for hiding this comment

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

I forgot about this method on StringBuilder - I've switched to stringBuilder.AppendLine instead of manually Appending Environment.NewLine

* Adopt StringBuilder.AppendLine instead of manually referring to
  Environment.NewLine
* Use null-coalescing operator inplace of adding a if null check

Signed-off-by: Kyle Julian <[email protected]>
* Suppress ConfigureAwait warnings in unit test class

Signed-off-by: Kyle Julian <[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.

[FEATURE] Implement Logging Hook
3 participants