Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(flags): update openfeature sample code #12222

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 49 additions & 2 deletions docs/platforms/python/integrations/openfeature/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,34 @@ pip install --upgrade 'sentry-sdk'

Add `OpenFeatureIntegration()` to your `integrations` list:

```python
```python {tabTitle: sentry-sdk >= v2.TODO: (Track One Client)}
import sentry_sdk
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
from openfeature import api

client = api.get_client()

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
OpenFeatureIntegration(client=client),
],
)
```

```python {tabTitle: sentry-sdk >= v2.TODO: (Track All Clients)}
import sentry_sdk
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
OpenFeatureIntegration(),
],
)
```

```python {tabTitle: sentry-sdk <= v2.TODO: (Track All Clients)}
import sentry_sdk
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration

Expand All @@ -35,7 +62,27 @@ sentry_sdk.init(

The integration is tested by evaluating a feature flag using your OpenFeature SDK before capturing an exception.

```python
```python {tabTitle: sentry-sdk >= v2.TODO: (Track One Client)}
from openfeature import api
import sentry_sdk

# Reference `client` from the Configure step.
client.get_boolean_value("hello", default_value=False)

sentry_sdk.capture_exception(Exception("Something went wrong!"))
```

```python {tabTitle: sentry-sdk >= v2.TODO: (Track All Clients)}
from openfeature import api
import sentry_sdk

client = api.get_client()
client.get_boolean_value("hello", default_value=False)

sentry_sdk.capture_exception(Exception("Something went wrong!"))
```

```python {tabTitle: sentry-sdk <= v2.TODO: (Track All Clients)}
from openfeature import api
import sentry_sdk

Expand Down
29 changes: 23 additions & 6 deletions platform-includes/configuration/openfeature/javascript.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Before using this integration, you need to install and instrument the [OpenFeature SDK](https://www.npmjs.com/package/@openfeature/web-sdk) in your app. Learn more by reading OpenFeature's [SDK docs](https://openfeature.dev/docs/reference/technologies/client/web/) and [provider docs](https://openfeature.dev/docs/reference/concepts/provider).

```javascript {tabTitle: JavaScript (Track All Evals)}
```javascript {tabTitle: @sentry/browser >= v8.TODO: (Track One Client)}
import * as Sentry from '@sentry/browser';
import { OpenFeature } from '@openfeature/web-sdk';

OpenFeature.setProvider(new MyProviderOfChoice());
const client = OpenFeature.getClient();
const openFeatureIntegration = Sentry.openFeatureIntegration({openFeatureClient: client});

Sentry.init({
dsn: '___PUBLIC_DSN___',
integrations: [openFeatureIntegration]
});

const result = client.getBooleanValue('test-flag', false); // evaluate with a default value
Sentry.captureException(new Error('Something went wrong!'));
```

```javascript {tabTitle: @sentry/browser <= v8.TODO: (Track One Client)}
import * as Sentry from '@sentry/browser';
import { OpenFeature } from '@openfeature/web-sdk';

Expand All @@ -10,14 +27,14 @@ Sentry.init({
});

OpenFeature.setProvider(new MyProviderOfChoice());
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());

const client = OpenFeature.getClient();
client.addHooks(new Sentry.OpenFeatureIntegrationHook());

const result = client.getBooleanValue('test-flag', false); // evaluate with a default value
Sentry.captureException(new Error('Something went wrong!'));
```

```javascript {tabTitle: JavaScript (Track One Client)}
```javascript {tabTitle: @sentry/browser <= v8.TODO: (Track All Clients)}
import * as Sentry from '@sentry/browser';
import { OpenFeature } from '@openfeature/web-sdk';

Expand All @@ -27,9 +44,9 @@ Sentry.init({
});

OpenFeature.setProvider(new MyProviderOfChoice());
const client = OpenFeature.getClient();
client.addHooks(new Sentry.OpenFeatureIntegrationHook());
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());

const client = OpenFeature.getClient();
const result = client.getBooleanValue('test-flag', false); // evaluate with a default value
Sentry.captureException(new Error('Something went wrong!'));
```
Loading