Skip to content

Commit 88e0da3

Browse files
committed
ref(flags): update openfeature sample code
1 parent 5f28814 commit 88e0da3

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

docs/platforms/python/integrations/openfeature/index.mdx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,34 @@ pip install --upgrade 'sentry-sdk'
1919

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

22-
```python
22+
```python {tabTitle: sentry-sdk >= v2.TODO: (Track One Client)}
23+
import sentry_sdk
24+
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
25+
from openfeature import api
26+
27+
client = api.get_client()
28+
29+
sentry_sdk.init(
30+
dsn="___PUBLIC_DSN___",
31+
integrations=[
32+
OpenFeatureIntegration(client=client),
33+
],
34+
)
35+
```
36+
37+
```python {tabTitle: sentry-sdk >= v2.TODO: (Track All Clients)}
38+
import sentry_sdk
39+
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
40+
41+
sentry_sdk.init(
42+
dsn="___PUBLIC_DSN___",
43+
integrations=[
44+
OpenFeatureIntegration(),
45+
],
46+
)
47+
```
48+
49+
```python {tabTitle: sentry-sdk <= v2.TODO: (Track All Clients)}
2350
import sentry_sdk
2451
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
2552

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

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

38-
```python
65+
```python {tabTitle: sentry-sdk >= v2.TODO: (Track One Client)}
66+
from openfeature import api
67+
import sentry_sdk
68+
69+
# Reference `client` from the Configure step.
70+
client.get_boolean_value("hello", default_value=False)
71+
72+
sentry_sdk.capture_exception(Exception("Something went wrong!"))
73+
```
74+
75+
```python {tabTitle: sentry-sdk >= v2.TODO: (Track All Clients)}
76+
from openfeature import api
77+
import sentry_sdk
78+
79+
client = api.get_client()
80+
client.get_boolean_value("hello", default_value=False)
81+
82+
sentry_sdk.capture_exception(Exception("Something went wrong!"))
83+
```
84+
85+
```python {tabTitle: sentry-sdk <= v2.TODO: (Track All Clients)}
3986
from openfeature import api
4087
import sentry_sdk
4188

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
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).
22

3-
```javascript {tabTitle: JavaScript (Track All Evals)}
3+
```javascript {tabTitle: @sentry/browser >= v8.TODO: (Track One Client)}
4+
import * as Sentry from '@sentry/browser';
5+
import { OpenFeature } from '@openfeature/web-sdk';
6+
7+
OpenFeature.setProvider(new MyProviderOfChoice());
8+
const client = OpenFeature.getClient();
9+
const openFeatureIntegration = Sentry.openFeatureIntegration({openFeatureClient: client});
10+
11+
Sentry.init({
12+
dsn: '___PUBLIC_DSN___',
13+
integrations: [openFeatureIntegration]
14+
});
15+
16+
const result = client.getBooleanValue('test-flag', false); // evaluate with a default value
17+
Sentry.captureException(new Error('Something went wrong!'));
18+
```
19+
20+
```javascript {tabTitle: @sentry/browser <= v8.TODO: (Track One Client)}
421
import * as Sentry from '@sentry/browser';
522
import { OpenFeature } from '@openfeature/web-sdk';
623

@@ -10,14 +27,14 @@ Sentry.init({
1027
});
1128

1229
OpenFeature.setProvider(new MyProviderOfChoice());
13-
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());
14-
1530
const client = OpenFeature.getClient();
31+
client.addHooks(new Sentry.OpenFeatureIntegrationHook());
32+
1633
const result = client.getBooleanValue('test-flag', false); // evaluate with a default value
1734
Sentry.captureException(new Error('Something went wrong!'));
1835
```
1936

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

@@ -27,9 +44,9 @@ Sentry.init({
2744
});
2845

2946
OpenFeature.setProvider(new MyProviderOfChoice());
30-
const client = OpenFeature.getClient();
31-
client.addHooks(new Sentry.OpenFeatureIntegrationHook());
47+
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());
3248

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

0 commit comments

Comments
 (0)