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
The tracking API allows you to use OpenFeature abstractions and objects to associate user actions with feature flag evaluations.
285
+
This is essential for robust experimentation powered by feature flags.
286
+
For example, a flag enhancing the appearance of a UI component might drive user engagement to a new feature; to test this hypothesis, telemetry collected by a [hook](#hooks) or [provider](#providers) can be associated with telemetry reported in the client's `track` function.
287
+
288
+
```ts
289
+
// flag is evaluated
290
+
client.getBooleanValue('new-feature', false);
291
+
292
+
// new feature is used and track function is called recording the usage
293
+
useNewFeature();
294
+
client.track('new-feature-used');
295
+
```
296
+
281
297
### Shutdown
282
298
283
299
The OpenFeature API provides a close function to perform a cleanup of all registered providers.
@@ -336,7 +352,7 @@ class MyProvider implements Provider {
336
352
}
337
353
338
354
// implement with "new OpenFeatureEventEmitter()", and use "emit()" to emit events
@@ -51,6 +51,7 @@ In addition to the feature provided by the [web sdk](/docs/reference/technologie
51
51
-[Re-rendering with Context Changes](#re-rendering-with-context-changes)
52
52
-[Re-rendering with Flag Configuration Changes](#re-rendering-with-flag-configuration-changes)
53
53
-[Suspense Support](#suspense-support)
54
+
-[Tracking](#tracking)
54
55
-[Testing](#testing)
55
56
-[FAQ and troubleshooting](#faq-and-troubleshooting)
56
57
-[Resources](#resources)
@@ -129,7 +130,7 @@ function App() {
129
130
130
131
#### Evaluation hooks
131
132
132
-
Within the provider, you can use the various evaluation hooks to evaluate flags.
133
+
Within the provider, you can use the various evaluation hooks to evaluate flags.
133
134
134
135
```tsx
135
136
function Page() {
@@ -233,7 +234,7 @@ Note that if your provider doesn't support updates, this configuration has no im
233
234
234
235
#### Suspense Support
235
236
236
-
> [!NOTE]
237
+
> [!NOTE]
237
238
> React suspense is an experimental feature and subject to change in future versions.
238
239
239
240
Frequently, providers need to perform some initial startup tasks.
@@ -270,11 +271,32 @@ function Fallback() {
270
271
// component to render before READY.
271
272
return <p>Waiting for provider to be ready...</p>;
272
273
}
273
-
274
274
```
275
275
276
276
This can be disabled in the hook options (or in the [OpenFeatureProvider](#openfeatureprovider-context-provider)).
277
277
278
+
#### Tracking
279
+
280
+
The tracking API allows you to use OpenFeature abstractions and objects to associate user actions with feature flag evaluations.
281
+
This is essential for robust experimentation powered by feature flags.
282
+
For example, a flag enhancing the appearance of a UI component might drive user engagement to a new feature; to test this hypothesis, telemetry collected by a [hook](#hooks) or [provider](#providers) can be associated with telemetry reported in the client's `track` function.
283
+
284
+
The React SDK includes a hook for firing tracking events in the <OpenFeatureProvider> context in use:
285
+
286
+
```tsx
287
+
function MyComponent() {
288
+
289
+
// get a tracking function for this <OpenFeatureProvider>.
290
+
const { track } =useTrack();
291
+
292
+
// call the tracking event
293
+
// can be done in render, useEffect, or in handlers, depending on your use case
294
+
track(eventName, trackingDetails);
295
+
296
+
return <>...</>;
297
+
}
298
+
```
299
+
278
300
### Testing
279
301
280
302
The React SDK includes a built-in context provider for testing.
The standard Go log package is used by default to show error logs.
175
-
This can be overridden using the structured logging, [logr](https://github.com/go-logr/logr) API, allowing integration to any package.
176
-
There are already [integration implementations](https://github.com/go-logr/logr#implementations-non-exhaustive) for many of the popular logger packages.
174
+
Note that in accordance with the OpenFeature specification, the SDK doesn't generally log messages during flag evaluation.
175
+
176
+
#### Logging Hook
177
+
178
+
The GO SDK includes a `LoggingHook`, which logs detailed information at key points during flag evaluation, using [slog](https://pkg.go.dev/log/slog) structured logging API.
179
+
This hook can be particularly helpful for troubleshooting and debugging; simply attach it at the global, client or invocation level and ensure your log level is set to "debug".
180
+
181
+
##### Usage example
177
182
178
183
```go
179
-
varl logr.Logger
180
-
l = integratedlogr.New() // replace with your chosen integrator
{"time":"2024-10-23T13:33:09.8968242+03:00","level":"ERROR","msg":"Error stage","domain":"test-client","provider_name":"InMemoryProvider","flag_key":"not-exist","default_value":true,"error_message":"error code: FLAG_NOT_FOUND: flag for key not-exist not found"}
207
+
```
208
+
209
+
See [hooks](#hooks) for more information on configuring hooks.
189
210
190
211
### Domains
191
-
Clients can be assigned to a domain. A domain is a logical identifier which can be used to associate clients with a particular provider. If a domain has no associated provider, the default provider is used.
212
+
213
+
Clients can be assigned to a domain. A domain is a logical identifier that can be used to associate clients with a particular provider. If a domain has no associated provider, the default provider is used.
0 commit comments