You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/feature_flags/server/go.md
+256-2Lines changed: 256 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,263 @@ Feature Flags are in Preview. Complete the form to request access.
16
16
17
17
## Overview
18
18
19
-
This page describes how to instrument your Go application with the Datadog Feature Flags SDK.
19
+
This page describes how to instrument your Go application with the Datadog Feature Flags SDK. The Go SDK integrates with [OpenFeature][1], an open standard for feature flag management, and uses the Datadog tracer's Remote Configuration to receive flag updates in real time.
20
20
21
-
Documentation coming soon.
21
+
This guide explains how to install and enable the SDK, create an OpenFeature client, and evaluate feature flags in your application.
22
+
23
+
## Prerequisites
24
+
25
+
Before setting up the Go Feature Flags SDK, ensure you have:
26
+
27
+
-**Datadog Agent** with [Remote Configuration][2] enabled
28
+
-**Datadog Go tracer**`dd-trace-go` version 2.4.0 or later
29
+
30
+
Set the following environment variables:
31
+
32
+
{{< code-block lang="bash" >}}
33
+
# Required: Enable the feature flags provider
34
+
DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true
35
+
36
+
# Required: Service identification
37
+
DD_SERVICE=<YOUR_SERVICE_NAME>
38
+
DD_ENV=<YOUR_ENVIRONMENT>
39
+
{{< /code-block >}}
40
+
41
+
## Installation
42
+
43
+
Install the Datadog OpenFeature provider package:
44
+
45
+
{{< code-block lang="bash" >}}
46
+
go get github.com/DataDog/dd-trace-go/v2/openfeature
47
+
{{< /code-block >}}
48
+
49
+
You also need the OpenFeature Go SDK:
50
+
51
+
{{< code-block lang="bash" >}}
52
+
go get github.com/open-feature/go-sdk/openfeature
53
+
{{< /code-block >}}
54
+
55
+
## Initialize the SDK
56
+
57
+
Start the Datadog tracer and register the Datadog OpenFeature provider. The tracer must be started first because it enables Remote Configuration, which delivers flag configurations to your application.
58
+
59
+
### Blocking initialization
60
+
61
+
Use `SetProviderAndWait` to block until the initial flag configuration is received. This ensures flags are ready before your application starts handling requests.
// Flag evaluations return defaults until configuration is received
144
+
}
145
+
{{< /code-block >}}
146
+
147
+
## Create a client
148
+
149
+
Create an OpenFeature client to evaluate flags. You can create multiple clients with different names for different parts of your application:
150
+
151
+
{{< code-block lang="go" >}}
152
+
// Create a client for your application
153
+
client := openfeature.NewClient("my-service")
154
+
{{< /code-block >}}
155
+
156
+
## Set the evaluation context
157
+
158
+
Define an evaluation context that identifies the user or entity for flag targeting. The evaluation context includes attributes used to determine which flag variations should be returned:
The targeting key is used for consistent traffic distribution (percentage rollouts). Additional attributes enable targeting rules such as "enable for users in the US" or "enable for premium tier users."
173
+
174
+
## Evaluate flags
175
+
176
+
After setting up the provider and creating a client, you can evaluate flags throughout your application. Flag evaluation is local and fast—the SDK uses locally cached configuration data, so no network requests occur during evaluation.
177
+
178
+
Each flag is identified by a key (a unique string) and can be evaluated with a typed method that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value.
179
+
180
+
### Boolean flags
181
+
182
+
Use `BooleanValue` for flags that represent on/off or true/false conditions:
For numeric flags, use `IntValue` or `FloatValue`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier:
if configMap, ok := config.(map[string]interface{}); ok {
250
+
maxRetries := configMap["maxRetries"]
251
+
timeout := configMap["timeout"]
252
+
// Use configuration values
253
+
}
254
+
{{< /code-block >}}
255
+
256
+
### Flag evaluation details
257
+
258
+
When you need more than just the flag value, use the `*ValueDetails` methods. These return both the evaluated value and metadata explaining the evaluation:
0 commit comments