open-feature / ruby-sdk

Ruby implementation of the OpenFeature SDK
https://openfeature.dev
Apache License 2.0
25 stars 9 forks source link

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK #152

Closed Kameleoon closed 1 month ago

Kameleoon commented 1 month ago

Hello guys!

In the latest version (0.4.0), the fetch_{result_type}_{suffix} evaluation methods are not functioning as expected. This issue appears to stem from a call to an undefined method evaluation_context in the OpenFeature::SDK. Below is the problematic code:

def fetch_#{result_type}_#{suffix}(flag_key:, default_value:, evaluation_context: nil)
  built_context = EvaluationContextBuilder.new.call(api_context: OpenFeature::SDK.evaluation_context, client_context: self.evaluation_context, invocation_context: evaluation_context)
  resolution_details = @provider.fetch_#{result_type}_value(flag_key:, default_value:, evaluation_context: built_context). 
  evaluation_details = EvaluationDetails.new(flag_key:, resolution_details:)
  #{"evaluation_details.value" if suffix == :value}
end

There is a problematic line in the code:

built_context = EvaluationContextBuilder.new.call(api_context: OpenFeature::SDK.evaluation_context, client_context: self.evaluation_context, invocation_context: evaluation_context)

Any call to fetch_{result_type}_{suffix} throws the following error:

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK
beeme1mr commented 1 month ago

Hey @maxveldink, is this something you could help with?

maxveldink commented 1 month ago

Sure! I've got an idea to expand that section out anyway and remove that metaprogramming. I'll clean it up tomorrow morning if I've got some time, and when I'm back from vacation Monday if not.

maxveldink commented 1 month ago

Apologies for the delay here; I'm taking a look this morning. I'm not able to replicate this locally loading the gem in a console and my projects utilizing OF don't appear to have this issue. That method is being appropriately forwarded to the API instance. Do you have a snippet of calling code which is triggering this?

Related to this issue, I do plan on expanding this metaprogramming out so it's clearer and tooling can better analyze the eval methods. That could eliminate this issue as well, or help us pinpoint it.

Kameleoon commented 1 month ago

Hello @maxveldink

Do you have a snippet of calling code which is triggering this?

client = OpenFeature::SDK::API.instance.build_client
evaluation_details = client.fetch_string_details(flag_key: feature_key, default_value: 'test',
evaluation_context: eval_context)

throws:

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK
/opt/homebrew/lib/ruby/gems/3.3.0/gems/openfeature-sdk-0.4.0/lib/open_feature/sdk/client.rb:29:in `fetch_string_details'
DmitryAE commented 1 month ago

Hello @maxveldink.

Hope you're well.

Do you have any news? Estimated time?

Thanks!

maxveldink commented 1 month ago

Yes, sorry for the delay; I'll be working on this tomorrow (I think I've got the under lying reason) and will cut a release once that's approved.

maxveldink commented 1 month ago

@Kameleoon I've been playing around with this issue tonight, and I'm unable to replicate that problem locally on main. Your snippet was helpful, but I'm seeing a successful evaluation there.

One thing I noticed was you're creating the client through the singleton instance method; the primary entrypoint should be OpenFeature::SDK.build_client (but I don't see how that would cause this problem, but would be worth a shot).

I've been meaning to refactor away from metaprogramming here in favor of explicit method defs, so I've created a draft to do that at #154. Could you also build off of that branch and see if you're seeing the same issue?

@Kameleoon can you provide any more context around how you're initializing OF in your project, or a wider code snippet? @DmitryAE I wonder if you could provide a code snippet/context as well.

Thank you 🙏🏻

Kameleoon commented 1 month ago

Hello @maxveldink

I hope you're doing well.

I want to sincerely apologize for the delayed response. After applying your suggestion to call methods without API.instance, we identified an issue on our end with how we imported the OpenFeature SDK. We mistakenly imported open_feature/sdk/api, which was necessary due to our use of API.instance (as we thought), and this turned out to be the root cause.

We deeply regret any inconvenience this may have caused you. Your guidance was invaluable, and we greatly appreciate your support throughout this process.

Thank you once again for your help!

Best regards, The Kameleoon Team

P.S. Please disregard the message from @DmitryAE, which is the personal account of one of our developers. It pertained to the same issue.

maxveldink commented 1 month ago

Glad that we got it solved! Reach out if you have any other issues with the SDK!