Feature flags launchdarkly statsig

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Feature flags launchdarkly statsig is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://openfeature.dev/ · https://docs.launchdarkly.com/ · https://docs.statsig.com/ · https://docs.getunleash.io/

How to use this skill

Skill file

<!--

Source: https://openfeature.dev/ · https://docs.launchdarkly.com/ · https://docs.statsig.com/ · https://docs.getunleash.io/

Authored: June 2026 for the devops-engineer agent bundle.

-->

Feature Flags (OpenFeature + LaunchDarkly / Statsig / Unleash / Flagsmith)

Decouple deploy from release. OpenFeature (CNCF, vendor-neutral SDK) as

the application layer + backend of choice: LaunchDarkly (enterprise),

Statsig (modern, generous free tier), Unleash (OSS, self-host),

Flagsmith (OSS), GrowthBook (OSS + paid). Ship dark, enable by

cohort, monitor SLI, expand. Tie flag changes to incident.io for auto-rollback.

When to use

Skip when: configuration that almost never changes (use ConfigMap);

secrets (use Vault); team is 1-2 people on a side project.

Setup

# OpenFeature SDKs
uv add openfeature-sdk                          # Python
npm install @openfeature/server-sdk             # Node
go get github.com/open-feature/go-sdk           # Go

# Provider SDKs (pick one)
uv add openfeature-launchdarkly-provider
uv add openfeature-statsig-provider
uv add openfeature-unleash-provider

# Backend CLIs
brew install launchdarkly/tap/ldcli              # LaunchDarkly
npm install -g statsig-cli                       # Statsig
brew install unleash/unleash/unleash-cli         # Unleash

API keys:

Common recipes

Recipe 1 — OpenFeature Python with LaunchDarkly

from openfeature import api
from openfeature.contrib.provider.launchdarkly import LaunchDarklyProvider
import launchdarkly_server_sdk as ld

ld_client = ld.LDClient(config=ld.Config(sdk_key=os.environ["LD_SDK_KEY"]))
api.set_provider(LaunchDarklyProvider(ld_client))

client = api.get_client()

# Evaluate
show_new_checkout = client.get_boolean_value(
    flag_key="new-checkout-flow",
    default_value=False,
    evaluation_context={
        "targetingKey": user_id,
        "plan": user.plan,
        "country": user.country,
    },
)

The flag evaluation context drives the targeting rules in the backend UI.

Recipe 2 — OpenFeature TypeScript with Statsig

import { OpenFeature } from "@openfeature/server-sdk";
import { StatsigProvider } from "@openfeature/statsig-provider";

OpenFeature.setProvider(new StatsigProvider({
  sdkKey: process.env.STATSIG_SECRET!,
  options: { environment: { tier: process.env.NODE_ENV } },
}));

const client = OpenFeature.getClient();

const showNewCheckout = await client.getBooleanValue(
  "new-checkout-flow",
  false,
  { targetingKey: userId, plan: user.plan, country: user.country }
);

Recipe 3 — LaunchDarkly REST API (declarative flag changes)

# Toggle a flag via API
curl -X PATCH "https://app.launchdarkly.com/api/v2/flags/my-project/new-checkout-flow" \
  -H "Authorization: $LD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{ "op": "replace", "path": "/environments/production/on", "value": true }]'

# Bulk export
ldcli flags list --project my-project --output json > flags.json
ldcli flags import --project my-project --file flags-updated.json

Recipe 4 — Statsig CLI ops

statsig-cli gates list --env prod
statsig-cli gates create --name new_checkout --description "..."
statsig-cli gates update --name new_checkout --target-app "ios,web" --pass-percentage 10
statsig-cli experiments create --name checkout_layout_test --variants "A,B"

Recipe 5 — Unleash self-hosted (OSS)

# Deploy to K8s
helm repo add unleash https://docs.getunleash.io/helm-charts
helm upgrade --install unleash unleash/unleash -n unleash --create-namespace

# Use
curl -X POST http://unleash.myorg.com/api/admin/projects/default/features \
  -H "Authorization: $UNLEASH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "new-checkout-flow", "type": "release", "description": "..."}'
from openfeature.contrib.provider.unleash import UnleashProvider
import UnleashClient

unleash = UnleashClient(
    url="http://unleash.myorg.com/api/",
    app_name="my-app",
    custom_headers={"Authorization": os.environ["UNLEASH_TOKEN"]},
)
unleash.initialize_client()
api.set_provider(UnleashProvider(unleash))

Recipe 6 — Progressive rollout (5 → 25 → 50 → 100%)

# LaunchDarkly via API
for pct in 5 25 50 75 100; do
  curl -X PATCH ".../flags/new-checkout-flow" -H "Authorization: $LD_API_KEY" \
    -d "[{\"op\":\"replace\",\"path\":\"/environments/production/rules/0/clauses/0/values\",\"value\":[\"${pct}%\"]}]"
  sleep 1800           # 30 min between stages
  # In real practice: query SLI, abort on regression
done

In LD UI, this is Targeting → Add Rule → Percentage rollout.

Recipe 7 — Auto-rollback on SLO breach

# alertmanager → webhook → flag-killswitch Lambda
- alert: NewCheckoutErrorRateHigh
  expr: rate(http_errors_total{flag="new-checkout-flow",exposed="true"}[5m]) > 0.05
  for: 2m
  labels: { severity: critical }
  annotations:
    summary: "Auto-disabling new-checkout-flow"
    webhook_url: "https://lambda.aws.com/disable-flag?name=new-checkout-flow"

Lambda calls LaunchDarkly REST to set flag off + posts to Slack.

Recipe 8 — Flag-as-code (Terraform LaunchDarkly provider)

resource "launchdarkly_feature_flag" "new_checkout" {
  project_key = "myorg"
  key         = "new-checkout-flow"
  name        = "New checkout flow"
  description = "Enables the 2026 checkout redesign"
  variation_type = "boolean"
  variations {
    value = "true"
    name  = "Enabled"
  }
  variations {
    value = "false"
    name  = "Disabled"
  }
  defaults {
    on_variation  = 0
    off_variation = 1
  }
  tags = ["growth", "checkout"]
}

resource "launchdarkly_feature_flag_environment" "new_checkout_prod" {
  flag_id        = launchdarkly_feature_flag.new_checkout.id
  env_key        = "production"
  on             = true
  fallthrough { rollout_weights = [25000, 75000] }   # 25% enabled
  off_variation = 1
}
tofu plan && tofu apply

Recipe 9 — Local dev fallback

# Defaults work offline / on misconfigured providers
client = api.get_client()
value = client.get_boolean_value("flag", default_value=False, ...)
# If provider is down, returns default_value (False). Always set a safe default.

Recipe 10 — Experimentation (Statsig)

const experiment = await client.getObjectValue(
  "checkout_layout_test",
  { layout: "control" },
  { targetingKey: userId }
);
// Statsig exposes: experiment.layout = "A" | "B" | "control"

// Log conversion event for stat sig analysis
statsig.logEvent({ user, eventName: "purchase", value: cart.total });

Statsig auto-computes p-values + lift; LaunchDarkly Experimentation +

GrowthBook similar.

Recipe 11 — Choose backend

| Tool | Best for | Pricing | OSS? |

|---|---|---|---|

| LaunchDarkly | Enterprise; rich targeting; experimentation | $$$$ paid | Closed |

| Statsig | Mid-size; great free tier; experimentation-first | Generous free + paid | Closed (SDKs open) |

| Unleash | Self-hosted; OSS-first | OSS free + paid managed | Apache 2.0 |

| Flagsmith | Self-hosted OSS alt | OSS free + paid | BSD-3 |

| GrowthBook | OSS A/B testing + flags | OSS free + paid | MIT |

| OpenFeature | SDK only; pair with a backend | Free | Apache 2.0 |

Recipe 12 — Flag debt cleanup

Flag debt = flags that are 100% on or 100% off and forgotten. Tools:

# LaunchDarkly Code References finds usages in repos
ldcli code-refs --project myorg --repo-name myorg/api --branch main
# Reports flags with no code refs → safe to delete

# Manual review query
ldcli flags list --output json | \
  jq '.items[] | select(.environments.production.on == false and .environments.production.fallthrough.variation == 1) | .key'

Quarterly flag review: delete dead flags; convert "permanent" toggles to

config.

Examples

Example 1 — Ship checkout rewrite behind a flag

Goal: New checkout flow live but disabled; ramp over a week.

  1. Create flag new-checkout-flow in LaunchDarkly (Recipe 3 or UI).
  2. Code path:

```python

if client.get_boolean_value("new-checkout-flow", False, eval_ctx):

return new_checkout(...)

return old_checkout(...)

```

  1. Deploy with flag at 0% — code is shipped but inert.
  2. Day 1: 1% rollout, watch SLI for 4h.
  3. Day 2: 5%. Day 3: 25%. Day 5: 50%. Day 7: 100%.
  4. After 1 week stable at 100%, delete the old code path + remove flag.

Result: Deploy without rollout coupling; any regression aborts via flag flip.

Example 2 — Vendor migration: LaunchDarkly → Statsig

Goal: Cut LaunchDarkly cost; migrate to Statsig free tier.

  1. Add OpenFeature abstraction (Recipe 1).
  2. Replace provider import: LaunchDarklyProvider → StatsigProvider.
  3. Export flag config from LD (Recipe 3); import to Statsig.
  4. Dual-write phase: keep both providers; OpenFeature's MultiProvider votes

on values, logs disagreements.

  1. After 2 weeks parity: remove LD provider, cancel LD plan.

Result: Same code, different backend, lower cost.

Edge cases / gotchas

Don't fetch from network on every request.

returns the default. Always default to the SAFE behavior (typically

False for new feature flags, True for kill switches).

cost. Use group/cohort attrs where possible.

flags accordingly; auto-cleanup tools flag dead ones.

streams rules to SDK and evaluates locally); ensure SDK has the latest.

before the kill propagates to all SDKs. For instant kill, route via

service mesh.

doesn't separate envs by API key like LD does.

Enterprise-only. Plan for that if compliance matters.

flag groups can't be A/B-tested.

Test the matrix or simplify.

Pin to >= 1.0 and migrate on majors.

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.