Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions providers/openfeature-go-feature-flag-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ gem install openfeature-go-feature-flag-provider

The `OpenFeature::GoFeatureFlag::Provider` needs some options to be created and then set in the OpenFeature SDK.

| **Option** | **Description** |
|------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.<br />*(example: `https://relay.proxy.gofeatureflag.org/`)* |
| `headers` | A `Hash` object containing the headers to send to the relay-proxy.<br/>*(example to send APIKey: `{"Authorization" => "Bearer my-api-key"}` |

| **Option** | **Description** |
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.<br />*(example: `https://relay.proxy.gofeatureflag.org/`)* |
| `headers` | A `Hash` object containing the headers to send to the relay-proxy.<br/>*(example to send APIKey: `{"Authorization" => "Bearer my-api-key"}` |
| `instrumentation` | [Faraday instrumentation](https://github.com/lostisland/faraday/blob/main/docs/middleware/included/instrumentation.md) hash |
The only required option to create a `GoFeatureFlagProvider` is the URL _(`endpoint`)_ to your GO Feature Flag relay-proxy instance.

```ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Provider
def initialize(options: Options.new)
@metadata = SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME)
@options = options
@goff_api = GoFeatureFlagApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers)
@goff_api = GoFeatureFlagApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers, instrumentation: options.instrumentation)
end

def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ module OpenFeature
module GoFeatureFlag
# This class is the entry point for the GoFeatureFlagProvider
class GoFeatureFlagApi
def initialize(endpoint: nil, custom_headers: nil)
def initialize(endpoint: nil, custom_headers: nil, instrumentation: nil)
@faraday_connection = Faraday.new(url: endpoint, headers: headers(custom_headers)) do |f|
f.request :instrumentation, instrumentation if instrumentation
f.adapter :net_http_persistent do |http|
http.idle_timeout = 30
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ module OpenFeature
module GoFeatureFlag
# This class is the configuration class for the GoFeatureFlagProvider
class Options
attr_accessor :endpoint, :custom_headers, :exporter_metadata
attr_accessor :endpoint, :custom_headers, :exporter_metadata, :instrumentation

def initialize(endpoint: nil, headers: {}, exporter_metadata: {})
def initialize(endpoint: nil, headers: {}, exporter_metadata: {}, instrumentation: nil)
validate_endpoint(endpoint: endpoint)
validate_instrumentation(instrumentation: instrumentation)
@endpoint = endpoint
@custom_headers = headers
@exporter_metadata = exporter_metadata
@instrumentation = instrumentation
Comment thread
avelicka marked this conversation as resolved.
end

private
Expand All @@ -25,6 +27,13 @@ def validate_endpoint(endpoint: nil)
rescue URI::InvalidURIError
raise ArgumentError, "Invalid URL for endpoint: #{endpoint}"
end

def validate_instrumentation(instrumentation: nil)
return if instrumentation.nil?
return if instrumentation.is_a?(Hash)

raise ArgumentError, "Invalid type for instrumentation: #{instrumentation.class}"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,14 @@
it "should raise if endpoint is not http" do
expect { OpenFeature::GoFeatureFlag::Options.new(endpoint: "ftp://gofeatureflag.org") }.to raise_error(ArgumentError, "Invalid URL for endpoint: ftp://gofeatureflag.org")
end

it "should return instrumentation if configured" do
options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031", instrumentation: {name: "custom_name"})
expect(options.instrumentation).to eql(name: "custom_name")
end
Comment thread
avelicka marked this conversation as resolved.

it "should raise if instrumentation is not hash" do
expect { OpenFeature::GoFeatureFlag::Options.new(instrumentation: "custom_name") }.to raise_error(ArgumentError, "Invalid type for instrumentation: String")
end
end
end