Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df0dc3b

Browse files
authored
docs: restructure to focus on Openfeature (#81)
1 parent 3b32935 commit df0dc3b

File tree

1 file changed

+73
-69
lines changed

1 file changed

+73
-69
lines changed

README.md

Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,63 @@
11
# Confidence Go SDK
22

3-
This repo contains the [Confidence](https://confidence.spotify.com/) Go SDK.
3+
This repo contains the [Confidence](https://confidence.spotify.com/) Go SDK and the Confidence OpenFeature provider. We recommend using the [OpenFeature Go SDK](https://github.com/open-feature/go-sdk) to access Confidence feature flags.
44

5-
## Adding the dependency
5+
6+
## Confidence OpenFeature Go Provider
7+
8+
Before starting to use the provider, it can be helpful to read through the general [OpenFeature docs](https://docs.openfeature.dev/) and get familiar with the concepts.
9+
10+
Get started by adding the dependencies:
611
<!---x-release-please-start-version-->
712
```
13+
require (
14+
github.com/open-feature/go-sdk v1.7.0
15+
)
816
require (
917
github.com/spotify/confidence-sdk-go v0.4.5
1018
)
1119
```
1220
<!---x-release-please-end-->
1321

14-
## Creating and using the SDK
15-
16-
Below is an example for how to create an instance of the Confidence SDK, and then resolve a flag with a boolean attribute.
22+
### Creating and using the flag provider
1723

18-
The SDK is configured via `SetAPIConfig(...)` and `*c.NewAPIConfig(...)`, with which you can set the api key for authentication.
19-
Optionally, a custom resolve API url can be configured if, for example, the resolver service is running on a locally deployed side-car (`NewAPIConfigWithUrl(...)`).
24+
Below is an example for how to obtain an OpenFeature _client_ using the Confidence flag provider, and then resolve
25+
a flag with a boolean attribute.
2026

27+
The Provider constructor accepts a confidence instance: `NewFlagProvider(confidenceSdk)`, please refer to [this section](#creating-and-using-the-sdk)
28+
for more detailed information on how to set that up.
2129

22-
You can retrieve properties on the flag variant using property dot notation, meaning `test-flag.boolean-key` will retrieve the attribute `boolean-key` on the flag `test-flag`.
30+
You can retrieve attributes on the flag variant using property dot notation, meaning `test-flag.boolean-key` will retrieve
31+
the attribute `boolean-key` on the flag `test-flag`.
2332

24-
You can also use only the flag name `test-flag` and retrieve all values as a map with `GetObjectFlag()`.
33+
You can also use only the flag name `test-flag` and retrieve all values as a map with `client.ObjectValue()`.
2534

2635
The flag's schema is validated against the requested data type, and if it doesn't match it will fall back to the default value.
2736

2837
```go
2938
import (
39+
o "github.com/open-feature/go-sdk/openfeature"
3040
c "github.com/spotify/confidence-sdk-go/pkg/confidence"
41+
p "github.com/spotify/confidence-sdk-go/pkg/provider"
3142
)
3243

3344
confidenceSdk := c.NewConfidenceBuilder().SetAPIConfig(*c.NewAPIConfig("clientSecret")).Build()
45+
confidenceProvider := p.NewFlagProvider(confidenceSdk)
3446

35-
confidence.PutContext("targeting_key", "Random_targeting_key")
36-
flagValue := confidence.GetBoolFlag(context.Background(), "test-flag.boolean-key", false).Value
37-
// we can also pull flag values using a Confidence instance with extra context
38-
confidence.WithContext(map[string]interface{}{
39-
"Something": 343,
40-
}).GetBoolFlag(context.Background(), "test-flag.boolean-key", false).Value
41-
```
42-
43-
The flag will be applied immediately, meaning that Confidence will count the targeted user as having received the treatment once they have have been evaluated.
44-
45-
### Tracking
46-
47-
Confidence support event tracking through the SDK. The `Track()` function accepts an en event name and a map of arbitrary data connected to the event.
48-
The current context will also be appended to the event data.
49-
50-
```go
51-
wg := confidence.Track(context.Background(), "checkout-complete", map[string]interface{}{
52-
"orderId": 1234,
53-
"total": 100.0,
54-
"items": []string{"item1", "item2"},
55-
})
56-
wg.Wait()
57-
```
58-
59-
### Telemetry
6047

61-
The SDK includes telemetry functionality that helps monitor SDK performance and usage. By default, telemetry is enabled and collects metrics (anonymously) such as resolve latency and request status. This data is used by the Confidence team, and in certain cases it is also exposed to the SDK adopters. You can disable telemetry by setting `DisableTelemetry: true` in the `APIConfig`:
48+
o.SetProvider(confidenceProvider)
49+
client := o.NewClient("testApp")
50+
51+
attributes := make(map[string]interface{})
52+
attributes["country"] = "SE"
53+
attributes["plan"] = "premium"
54+
attributes["user_id"] = "user1"
6255

63-
```go
64-
config := c.NewAPIConfig("clientSecret")
65-
config.DisableTelemetry = true
66-
confidenceSdk := c.NewConfidenceBuilder().SetAPIConfig(*config).Build()
56+
boolValue, error := client.BooleanValue(context.Background(), "test-flag.boolean-key", false,
57+
o.NewEvaluationContext("", attributes))
6758
```
6859

69-
## Logging
60+
### Logging
7061

7162
Unless specifically configured using the `ConfidenceBuilder` `setLogger()` function; Confidence uses the default instance of [slog](https://pkg.go.dev/log/slog) for logging valuable information during runtime.
7263
When getting started with Confidence, we suggest you configure [slog](https://pkg.go.dev/log/slog) to emit debug level information:
@@ -78,58 +69,71 @@ h := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: programLevel})
7869
slog.SetDefault(slog.New(h))
7970
```
8071

81-
## Demo app
72+
### Telemetry
8273

83-
To run the demo app, replace the `CLIENT_SECRET` with client secret setup in the
84-
[Confidence](https://confidence.spotify.com/) console, the flags with existing flags and execute
85-
the app with `cd demo && go run GoDemoApp.go`.
74+
The SDK includes telemetry functionality that helps monitor SDK performance and usage. By default, telemetry is enabled and collects metrics (anonymously) such as resolve latency and request status. This data is used by the Confidence team, and in certain cases it is also exposed to the SDK adopters. You can disable telemetry by setting `DisableTelemetry: true` in the `APIConfig`:
8675

87-
## Confidence OpenFeature Go Provider
76+
```go
77+
config := c.NewAPIConfig("clientSecret")
78+
config.DisableTelemetry = true
79+
confidenceSdk := c.NewConfidenceBuilder().SetAPIConfig(*config).Build()
80+
```
81+
82+
## Using Confidence without OpenFeature
8883

89-
The SDK can be combined with the [OpenFeature Go SDK](https://github.com/open-feature/go-sdk), the repo also contains an OpenFeature Provider. Before starting to use the provider, it can be helpful to read through the general [OpenFeature docs](https://docs.openfeature.dev/)
90-
and get familiar with the concepts.
91-
It's also important to add the underlying OpenFeature SDK dependency:
84+
### Adding the dependency
85+
<!---x-release-please-start-version-->
9286
```
9387
require (
94-
github.com/open-feature/go-sdk v1.7.0
88+
github.com/spotify/confidence-sdk-go v0.4.5
9589
)
9690
```
91+
<!---x-release-please-end-->
9792

98-
### Creating and using the flag provider
93+
### Creating and using the SDK
9994

100-
Below is an example for how to create a OpenFeature client using the Confidence flag provider, and then resolve
101-
a flag with a boolean attribute.
95+
Below is an example for how to create an instance of the Confidence SDK, and then resolve a flag with a boolean attribute.
10296

103-
The Provider constructor accepts a confidence instance: `NewFlagProvider(confidenceSdk)`, please refer to the previous sections
104-
of this readme for more detailed information on how to set that up.
97+
The SDK is configured via `SetAPIConfig(...)` and `*c.NewAPIConfig(...)`, with which you can set the api key for authentication.
98+
Optionally, a custom resolve API url can be configured if, for example, the resolver service is running on a locally deployed side-car (`NewAPIConfigWithUrl(...)`).
10599

106-
You can retrieve attributes on the flag variant using property dot notation, meaning `test-flag.boolean-key` will retrieve
107-
the attribute `boolean-key` on the flag `test-flag`.
108100

109-
You can also use only the flag name `test-flag` and retrieve all values as a map with `client.ObjectValue()`.
101+
You can retrieve properties on the flag variant using property dot notation, meaning `test-flag.boolean-key` will retrieve the attribute `boolean-key` on the flag `test-flag`.
102+
103+
You can also use only the flag name `test-flag` and retrieve all values as a map with `GetObjectFlag()`.
110104

111105
The flag's schema is validated against the requested data type, and if it doesn't match it will fall back to the default value.
112106

113107
```go
114108
import (
115-
o "github.com/open-feature/go-sdk/openfeature"
116109
c "github.com/spotify/confidence-sdk-go/pkg/confidence"
117-
p "github.com/spotify/confidence-sdk-go/pkg/provider"
118110
)
119111

120112
confidenceSdk := c.NewConfidenceBuilder().SetAPIConfig(*c.NewAPIConfig("clientSecret")).Build()
121-
confidenceProvider := p.NewFlagProvider(confidenceSdk)
122113

114+
confidence.WithContext(map[string]interface{}{
115+
"Something": 343,
116+
}).GetBoolFlag(context.Background(), "test-flag.boolean-key", false).Value
117+
```
118+
119+
The flag will be applied immediately, meaning that Confidence will count the targeted user as having received the treatment once they have have been evaluated.
123120

124-
o.SetProvider(confidenceProvider)
125-
client := o.NewClient("testApp")
126-
127-
attributes := make(map[string]interface{})
128-
attributes["country"] = "SE"
129-
attributes["plan"] = "premium"
130-
attributes["user_id"] = "user1"
121+
#### Tracking
131122

132-
boolValue, error := client.BooleanValue(context.Background(), "test-flag.boolean-key", false,
133-
o.NewEvaluationContext("", attributes))
123+
Confidence support event tracking through the SDK. The `Track()` function accepts an en event name and a map of arbitrary data connected to the event.
124+
The current context will also be appended to the event data.
125+
126+
```go
127+
wg := confidence.Track(context.Background(), "checkout-complete", map[string]interface{}{
128+
"orderId": 1234,
129+
"total": 100.0,
130+
"items": []string{"item1", "item2"},
131+
})
132+
wg.Wait()
134133
```
135134

135+
## Demo app
136+
137+
To run the demo app, replace the `CLIENT_SECRET` with client secret setup in the
138+
[Confidence](https://confidence.spotify.com/) console, the flags with existing flags and execute
139+
the app with `cd demo && go run GoDemoApp.go`.

0 commit comments

Comments
 (0)