Skip to content

Conversation

@jaugustin
Copy link
Contributor

Change log message to follow best practice of PSR3, Log Exception object to help debuging, when provider throw Exception

This PR

  • Improve the log message and context, when the OpenFeatureClient catch Exception

Related Issues

Notes

Follow-up Tasks

How to test

  • Unit test updated to test the changes

@jaugustin jaugustin requested a review from tcarrio as a code owner September 2, 2025 07:43
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @jaugustin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the error handling and logging within the OpenFeature client. The primary goal is to make error messages more structured and informative, aligning with standard logging practices, and to provide richer context for debugging issues that arise during feature flag evaluation.

Highlights

  • Improved Error Logging: The error log message format in OpenFeatureClient has been updated to follow PSR-3 best practices, using placeholders for dynamic values.
  • Enhanced Debugging Context: The full Exception object is now included in the log context when an error occurs during feature flag evaluation, providing more comprehensive debugging information.
  • Unit Test Updates: Corresponding unit tests for OpenFeatureClient have been modified to assert the new log message format and the presence of the Exception object in the log context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves error logging in OpenFeatureClient by adopting PSR-3 best practices, including using placeholders and adding the full exception object to the log context. This is a valuable change for debugging. The corresponding unit test has been updated to reflect these changes. I've added one suggestion to further improve the test's maintainability by providing more specific failure messages.

Comment on lines 561 to 565
Mockery::on(fn ($context) => isset($context['flagKey'], $context['errorMessage'], $context['exception']) &&
$context['flagKey'] === 'flagKey' &&
$context['errorMessage'] === 'NETWORK_ERROR' &&
$context['exception'] instanceof Exception &&
$context['exception']->getMessage() === 'NETWORK_ERROR'),

Choose a reason for hiding this comment

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

medium

For better test failure diagnostics, consider using Mockery::with() along with PHPUnit assertions instead of Mockery::on(). When Mockery::on()'s closure returns false, the test failure message is generic. By using Mockery::with() and assertions, you get specific feedback on which assertion failed, making it easier to debug. This improves the maintainability of the test.

            Mockery::with(function ($context) {
                $this->assertIsArray($context);
                $this->assertArrayHasKey('flagKey', $context);
                $this->assertSame('flagKey', $context['flagKey']);
                $this->assertArrayHasKey('errorMessage', $context);
                $this->assertSame('NETWORK_ERROR', $context['errorMessage']);
                $this->assertArrayHasKey('exception', $context);
                $this->assertInstanceOf(Exception::class, $context['exception']);
                $this->assertSame('NETWORK_ERROR', $context['exception']->getMessage());

                return true;
            }),

@tcarrio
Copy link
Member

tcarrio commented Sep 2, 2025

Thank you for the PR @jaugustin 👋 I will have time to review, approve, and merge later this evening if all looks good. For now I have approved the CI run for you.

@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.41%. Comparing base (2123274) to head (913d407).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #156      +/-   ##
============================================
+ Coverage     95.19%   96.41%   +1.21%     
  Complexity      227      227              
============================================
  Files            40       40              
  Lines           583      585       +2     
============================================
+ Hits            555      564       +9     
+ Misses           28       21       -7     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Change log message to follow best practice of PSR3,
Log Exception object to help debuging, when provider throw Exception

Signed-off-by: jaugustin <564420+jaugustin@users.noreply.github.com>
Signed-off-by: jaugustin <564420+jaugustin@users.noreply.github.com>
@tcarrio tcarrio merged commit d28d9c3 into open-feature:main Sep 14, 2025
10 checks passed
tcarrio pushed a commit that referenced this pull request Sep 27, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.1.0](2.0.12...2.1.0)
(2025-09-14)


### ✨ New Features

* **log:** Improve error log in OpenFeatureClient
([#156](#156))
([d28d9c3](d28d9c3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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