Skip to content

Commit

Permalink
ref(flags): add install/configure/verify steps for eval tracking onbo…
Browse files Browse the repository at this point in the history
…arding (#85679)
  • Loading branch information
aliu39 authored Feb 28, 2025
1 parent 8891498 commit fd6afc7
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 43 deletions.
88 changes: 66 additions & 22 deletions static/app/gettingStartedDocs/javascript/javascript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ type Params = DocsParams<PlatformOptions>;

type FeatureFlagConfiguration = {
integrationName: string;
makeCodeSnippet: (dsn: string) => string;
makeConfigureCode: (dsn: string) => string;
makeVerifyCode: () => string;
packageName: string;
};

const FEATURE_FLAG_CONFIGURATION_MAP: Record<
Expand All @@ -76,14 +78,15 @@ const FEATURE_FLAG_CONFIGURATION_MAP: Record<
> = {
[FeatureFlagProviderEnum.GENERIC]: {
integrationName: `featureFlagsIntegration`,
makeCodeSnippet: (dsn: string) => `import * as Sentry from "@sentry/browser";
packageName: '',
makeConfigureCode: (dsn: string) => `import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "${dsn}",
integrations: [Sentry.featureFlagsIntegration()],
});
const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>("FeatureFlags");
});`,
makeVerifyCode:
() => `const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>("FeatureFlags");
if (flagsIntegration) {
flagsIntegration.addFeatureFlag("test-flag", false);
} else {
Expand All @@ -94,7 +97,8 @@ Sentry.captureException(new Error("Something went wrong!"));`,

[FeatureFlagProviderEnum.LAUNCHDARKLY]: {
integrationName: `launchDarklyIntegration`,
makeCodeSnippet: (dsn: string) => `import * as Sentry from "@sentry/browser";
packageName: 'launchdarkly-js-client-sdk',
makeConfigureCode: (dsn: string) => `import * as Sentry from "@sentry/browser";
import * as LaunchDarkly from "launchdarkly-js-client-sdk";
Sentry.init({
Expand All @@ -106,17 +110,17 @@ const ldClient = LaunchDarkly.initialize(
"my-client-ID",
{ kind: "user", key: "my-user-context-key" },
{ inspectors: [Sentry.buildLaunchDarklyFlagUsedHandler()] },
);
);`,

// Evaluate a flag with a default value. You may have to wait for your client to initialize first.
makeVerifyCode: () => `// You may have to wait for your client to initialize first.
ldClient?.variation("test-flag", false);
Sentry.captureException(new Error("Something went wrong!"));`,
},

[FeatureFlagProviderEnum.OPENFEATURE]: {
integrationName: `openFeatureIntegration`,
makeCodeSnippet: (dsn: string) => `import * as Sentry from "@sentry/browser";
packageName: '@openfeature/web-sdk',
makeConfigureCode: (dsn: string) => `import * as Sentry from "@sentry/browser";
import { OpenFeature } from "@openfeature/web-sdk";
Sentry.init({
Expand All @@ -125,16 +129,17 @@ Sentry.init({
});
OpenFeature.setProvider(new MyProviderOfChoice());
OpenFeature.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
makeVerifyCode: () => `const client = OpenFeature.getClient();
const result = client.getBooleanValue("test-flag", false);
Sentry.captureException(new Error("Something went wrong!"));`,
},

[FeatureFlagProviderEnum.STATSIG]: {
integrationName: `statsigIntegration`,
makeCodeSnippet: (dsn: string) => `import * as Sentry from "@sentry/browser";
packageName: '@statsig/js-client',
makeConfigureCode: (dsn: string) => `import * as Sentry from "@sentry/browser";
import { StatsigClient } from "@statsig/js-client";
const statsigClient = new StatsigClient(
Expand All @@ -148,17 +153,19 @@ Sentry.init({
integrations: [
Sentry.statsigIntegration({ featureFlagClient: statsigClient }),
],
});
});`,

await statsigClient.initializeAsync(); // or statsigClient.initializeSync();
makeVerifyCode:
() => `await statsigClient.initializeAsync(); // or statsigClient.initializeSync();
const result = statsigClient.checkGate("my-feature-gate");
Sentry.captureException(new Error("something went wrong"));`,
},

[FeatureFlagProviderEnum.UNLEASH]: {
integrationName: `unleashIntegration`,
makeCodeSnippet: (dsn: string) => `import * as Sentry from "@sentry/browser";
packageName: 'unleash-proxy-client',
makeConfigureCode: (dsn: string) => `import * as Sentry from "@sentry/browser";
import { UnleashClient } from "unleash-proxy-client";
Sentry.init({
Expand All @@ -174,11 +181,10 @@ const unleash = new UnleashClient({
appName: "my-webapp",
});
unleash.start();
unleash.start();`,

// Evaluate a flag with a default value. You may have to wait for your client to synchronize first.
makeVerifyCode: () => `// You may have to wait for your client to synchronize first.
unleash.isEnabled("test-flag");
Sentry.captureException(new Error("Something went wrong!"));`,
},
};
Expand Down Expand Up @@ -736,11 +742,37 @@ const profilingOnboarding: OnboardingConfig<PlatformOptions> = {
export const featureFlagOnboarding: OnboardingConfig = {
install: () => [],
configure: ({featureFlagOptions = {integration: ''}, dsn}) => {
const {integrationName, makeCodeSnippet} =
const {integrationName, makeConfigureCode, makeVerifyCode, packageName} =
FEATURE_FLAG_CONFIGURATION_MAP[
featureFlagOptions.integration as keyof typeof FEATURE_FLAG_CONFIGURATION_MAP
]!;

const installConfig = [
{
language: 'bash',
code: [
{
label: 'npm',
value: 'npm',
language: 'bash',
code: `npm install --save @sentry/browser ${packageName}`,
},
{
label: 'yarn',
value: 'yarn',
language: 'bash',
code: `yarn add @sentry/browser ${packageName}`,
},
],
},
];

return [
{
type: StepType.INSTALL,
description: t('Install Sentry and the selected feature flag SDK.'),
configurations: installConfig,
},
{
type: StepType.CONFIGURE,
description: tct(
Expand All @@ -752,7 +784,19 @@ export const featureFlagOnboarding: OnboardingConfig = {
configurations: [
{
language: 'JavaScript',
code: `${makeCodeSnippet(dsn.public)}`,
code: makeConfigureCode(dsn.public),
},
],
},
{
type: StepType.VERIFY,
description: t(
'Test your setup by evaluating a flag, then capturing an exception. Check the Feature Flags table in Issue Details to confirm that your error event has recorded the flag and its result.'
),
configurations: [
{
language: 'JavaScript',
code: makeVerifyCode(),
},
],
},
Expand Down
89 changes: 68 additions & 21 deletions static/app/gettingStartedDocs/python/python.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type Params = DocsParams;

type FeatureFlagConfiguration = {
integrationName: string;
makeCodeSnippet: (dsn: string) => string;
makeConfigureCode: (dsn: string) => string;
makeVerifyCode: () => string;
packageName: string;
};

const FEATURE_FLAG_CONFIGURATION_MAP: Record<
Expand All @@ -27,7 +29,17 @@ const FEATURE_FLAG_CONFIGURATION_MAP: Record<
> = {
[FeatureFlagProviderEnum.GENERIC]: {
integrationName: ``,
makeCodeSnippet: (_dsn: string) => `import sentry_sdk
packageName: 'sentry-sdk',
makeConfigureCode: (dsn: string) => `sentry_sdk.init(
dsn="${dsn}",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
# your other integrations here
],
)`,
makeVerifyCode: () => `import sentry_sdk
from sentry_sdk.feature_flags import add_feature_flag
add_feature_flag('test-flag', False) # Records an evaluation and its result.
Expand All @@ -36,7 +48,8 @@ sentry_sdk.capture_exception(Exception("Something went wrong!"))`,

[FeatureFlagProviderEnum.LAUNCHDARKLY]: {
integrationName: `LaunchDarklyIntegration`,
makeCodeSnippet: (dsn: string) => `import sentry_sdk
packageName: "'sentry-sdk[launchdarkly]'",
makeConfigureCode: (dsn: string) => `import sentry_sdk
from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
import ldclient
Expand All @@ -48,16 +61,16 @@ sentry_sdk.init(
integrations=[
LaunchDarklyIntegration(),
],
)
client = ldclient.get()
)`,
makeVerifyCode: () => `client = ldclient.get()
client.variation("hello", Context.create("test-context"), False) # Evaluate a flag with a default value.
sentry_sdk.capture_exception(Exception("Something went wrong!"))`,
},

[FeatureFlagProviderEnum.OPENFEATURE]: {
integrationName: `OpenFeatureIntegration`,
makeCodeSnippet: (dsn: string) => `import sentry_sdk
packageName: "'sentry-sdk[openfeature]'",
makeConfigureCode: (dsn: string) => `import sentry_sdk
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
from openfeature import api
Expand All @@ -69,16 +82,16 @@ sentry_sdk.init(
integrations=[
OpenFeatureIntegration(),
],
)
client = api.get_client()
)`,
makeVerifyCode: () => `client = api.get_client()
client.get_boolean_value("hello", default_value=False) # Evaluate a flag with a default value.
sentry_sdk.capture_exception(Exception("Something went wrong!"))`,
},

[FeatureFlagProviderEnum.STATSIG]: {
integrationName: `StatsigIntegration`,
makeCodeSnippet: (dsn: string) => `import sentry_sdk
packageName: "'sentry-sdk[statsig]'",
makeConfigureCode: (dsn: string) => `import sentry_sdk
from sentry_sdk.integrations.statsig import StatsigIntegration
from statsig.statsig_user import StatsigUser
from statsig import statsig
Expand All @@ -91,9 +104,8 @@ sentry_sdk.init(
send_default_pii=True,
integrations=[StatsigIntegration()],
)
statsig.initialize("server-secret-key")
while not statsig.is_initialized():
statsig.initialize("server-secret-key")`,
makeVerifyCode: () => `while not statsig.is_initialized():
time.sleep(0.2)
result = statsig.check_gate(StatsigUser("my-user-id"), "my-feature-gate") # Evaluate a flag.
Expand All @@ -102,7 +114,8 @@ sentry_sdk.capture_exception(Exception("Something went wrong!"))`,

[FeatureFlagProviderEnum.UNLEASH]: {
integrationName: `UnleashIntegration`,
makeCodeSnippet: (dsn: string) => `import sentry_sdk
packageName: "'sentry-sdk[unleash]'",
makeConfigureCode: (dsn: string) => `import sentry_sdk
from sentry_sdk.integrations.unleash import UnleashIntegration
from UnleashClient import UnleashClient
Expand All @@ -115,9 +128,9 @@ sentry_sdk.init(
)
unleash = UnleashClient(...) # See Unleash quickstart.
unleash.initialize_client()
test_flag_enabled = unleash.is_enabled("test-flag") # Evaluate a flag.
unleash.initialize_client()`,
makeVerifyCode:
() => `test_flag_enabled = unleash.is_enabled("test-flag") # Evaluate a flag.
sentry_sdk.capture_exception(Exception("Something went wrong!"))`,
},
};
Expand Down Expand Up @@ -274,7 +287,8 @@ export const performanceOnboarding: OnboardingConfig = {
code: `
import sentry_sdk
sentry_sdk.init(
sentry_sdk.initimport { Context } from '@dnd-kit/sortable/dist/components';
(
dsn="${params.dsn.public}",
traces_sample_rate=1.0,
)`,
Expand Down Expand Up @@ -338,11 +352,32 @@ export function AlternativeConfiguration() {
export const featureFlagOnboarding: OnboardingConfig = {
install: () => [],
configure: ({featureFlagOptions = {integration: ''}, dsn}) => {
const {integrationName, makeCodeSnippet} =
const {integrationName, packageName, makeConfigureCode, makeVerifyCode} =
FEATURE_FLAG_CONFIGURATION_MAP[
featureFlagOptions.integration as keyof typeof FEATURE_FLAG_CONFIGURATION_MAP
]!;

return [
{
type: StepType.INSTALL,
description:
featureFlagOptions.integration === FeatureFlagProviderEnum.GENERIC
? t('Install the Sentry SDK.')
: t('Install the Sentry SDK with an extra.'),
configurations: [
{
language: 'bash',
code: [
{
label: 'pip',
value: 'pip',
language: 'bash',
code: `pip install --upgrade ${packageName}`,
},
],
},
],
},
{
type: StepType.CONFIGURE,
description:
Expand All @@ -354,7 +389,19 @@ export const featureFlagOnboarding: OnboardingConfig = {
configurations: [
{
language: 'python',
code: makeCodeSnippet(dsn.public),
code: makeConfigureCode(dsn.public),
},
],
},
{
type: StepType.VERIFY,
description: t(
'Test your setup by evaluating a flag, then capturing an exception. Check the Feature Flags table in Issue Details to confirm that your error event has recorded the flag and its result.'
),
configurations: [
{
language: 'python',
code: makeVerifyCode(),
},
],
},
Expand Down

0 comments on commit fd6afc7

Please sign in to comment.