Skip to content
Open
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
59 changes: 50 additions & 9 deletions docs/reference/concepts/01-evaluation-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ OpenFeature.setProvider(new YourProviderOfChoice());
<TabItem value="java" label="Java">

```java
import dev.openfeature.javasdk.OpenFeatureAPI;
import dev.openfeature.sdk.OpenFeatureAPI;

OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new YourProviderOfChoice());
Expand Down Expand Up @@ -85,6 +85,11 @@ openfeature.api.set_provider(YourProviderOfChoice())
</TabItem>
</Tabs>

Some providers need to establish connections, load flag data, or validate configuration before they can resolve flags accurately.
If your SDK exposes a blocking or awaitable registration method, use it during startup when your application needs to avoid default values while the provider initializes.
If you register the provider asynchronously, attach event handlers for [`PROVIDER_READY`](./events#provider_ready) and [`PROVIDER_ERROR`](./events#provider_error) so your application can react when initialization succeeds or fails.
See [Events](./events#event-handlers) for language-specific handler examples.

## Creating a client

The OpenFeature client is a lightweight abstraction used to evaluate feature flags.
Expand Down Expand Up @@ -275,15 +280,15 @@ These return the value, as well as additional metadata about the flag evaluation

#### Evaluation Details Structure Fields

| Field | Description |
| ------------------------ | --------------------------------------------------------------------------------------------- |
| flag key | the unique identifier for a feature flag |
| value | the value returned from a flag evaluation |
| reason (optional) | a string explaining why the flag value was returned |
| variant (optional) | the variant associated with the return flag value |
| flag metadata (optional) | a key-value structure which supports definition of arbitrary properties |
| Field | Description |
| ------------------------ | ---------------------------------------------------------------------------------------- |
| flag key | the unique identifier for a feature flag |
| value | the value returned from a flag evaluation |
| reason (optional) | a string explaining why the flag value was returned |
| variant (optional) | the variant associated with the return flag value |
| flag metadata (optional) | a key-value structure which supports definition of arbitrary properties |
| error code (optional) | an [error code](/specification/types#error-code) that categorizes flag evaluation errors |
| error message (optional) | a string detailing the error |
| error message (optional) | a string detailing the error |

<Tabs groupId="code">
<TabItem value="js" label="TypeScript">
Expand Down Expand Up @@ -404,3 +409,39 @@ details = client.get_object_details("objectFlag", {});

</TabItem>
</Tabs>

## API Shutdown

The OpenFeature API can shut down all registered providers so they can release connections, background workers, file watchers, or other resources.
Call this from your application shutdown path after you stop evaluating flags.
The method name varies by SDK; use the shutdown or close function documented by the SDK you are using.

<Tabs groupId="code">
<TabItem value="js" label="TypeScript">

```ts
import { OpenFeature } from '@openfeature/server-sdk';

await OpenFeature.close();
```

</TabItem>
<TabItem value="java" label="Java">

```java
import dev.openfeature.sdk.OpenFeatureAPI;

OpenFeatureAPI.getInstance().shutdown();
```

</TabItem>
<TabItem value="python" label="Python">

```python
from openfeature import api

api.shutdown()
```

</TabItem>
</Tabs>
65 changes: 65 additions & 0 deletions docs/reference/concepts/02-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,71 @@ const multiProvider = new MultiProvider(
await OpenFeature.setProviderAndWait(multiProvider);
```

### Provider lifecycle

Providers can implement lifecycle methods that the SDK calls when the provider is registered and when the API shuts down.
Use initialization to open network connections, load remote flag state, validate configuration, or start background workers that are required before evaluations should use the provider.
Use shutdown to release those same resources during application shutdown.
The exact method names vary by SDK, but they map to the same lifecycle: initialize when the provider is set, and clean up when the [Evaluation API is shut down](./evaluation-api#api-shutdown).
When your application needs to wait until initialization completes, use the SDK's waitable provider registration method when available.
If the provider is registered without waiting, application authors can use [`PROVIDER_READY`](./events#provider_ready) and [`PROVIDER_ERROR`](./events#provider_error) handlers to react to provider startup events.

<Tabs groupId="code">
<TabItem value="js" label="TypeScript">

```ts
import { EvaluationContext, Provider } from '@openfeature/server-sdk';

class MyFeatureProvider implements Provider {
readonly metadata = {
name: 'My Feature Provider',
} as const;

readonly runsOn = 'server';

async initialize(context?: EvaluationContext): Promise<void> {
// Open connections, validate configuration, or preload flag state here.
}

async onClose(): Promise<void> {
// Close connections or stop background workers here.
}

// Implement the required resolve*Evaluation methods shown in the provider examples below.
}
```

</TabItem>
<TabItem value="java" label="Java">

```java
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.FeatureProvider;
import dev.openfeature.sdk.Metadata;

public class MyProvider implements FeatureProvider {
@Override
public Metadata getMetadata() {
return () -> "My Provider";
}

@Override
public void initialize(EvaluationContext evaluationContext) throws Exception {
// Open connections, validate configuration, or preload flag state here.
}

@Override
public void shutdown() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In the OpenFeature Java SDK, the shutdown method in the FeatureProvider interface is defined with a throws Exception clause. While it is technically valid in Java to override a method and omit the throws clause if the implementation doesn't throw checked exceptions, it is better for documentation examples to match the interface signature for consistency with the initialize method shown above.

    @Override
    public void shutdown() throws Exception {

// Close connections or stop background workers here.
}

// Implement the required evaluation methods shown in the provider examples below.
}
```

</TabItem>
</Tabs>

### Examples

#### Dynamic Context Implementations (Server-side SDKs)
Expand Down