For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • Get started
    • Overview
    • Onboarding
    • Get started
    • Launch Insights
    • LaunchDarkly architecture
    • LaunchDarkly vocabulary
  • AgentControl
    • AgentControl
    • Manage AgentControl
  • Feature flags
    • Create flags
    • Target with flags
    • Flag templates
    • Manage flags
    • Code references
    • Contexts
    • Segments
  • Releases
    • Releasing features with LaunchDarkly
    • Release policies
    • Percentage rollouts
    • Progressive rollouts
    • Guarded rollouts
      • Creating guarded rollouts
        • Setting up contexts for guarded rollouts
        • Guarded rollout health checks
      • Managing guarded rollouts
    • Feature monitoring
    • Release pipelines
    • Engineering insights
    • Release management tools
    • Applications and app versions
    • Change history
    • Restoring previous flag versions
  • Observability
    • Observability
    • Session replay
    • Error monitoring
    • Logs
    • Traces
    • Observability metrics
    • Product analytics events
    • LLM observability
    • Alerts
    • Dashboards
    • Service map
    • Vega for auto-remediation
    • Observability MCP server
    • Search specification
    • Observability settings
    • Observability integrations
  • Experimentation
    • Experimentation
    • Experiment metric types
    • Experiment configuration
    • Managing experiments
    • Analyzing experiments
    • Multi-armed bandits
    • Holdouts
  • Metrics and events
    • Metrics in LaunchDarkly
    • Creating metrics
    • Metric groups
    • Events
    • Autogenerated metrics
  • Warehouse native
    • Warehouse native metrics
    • Setting up external warehouses
    • Creating experiments using warehouse native metrics
  • Infrastructure
    • Connect apps and services to LaunchDarkly
    • LaunchDarkly in China and Pakistan
    • LaunchDarkly in the European Union (EU)
    • LaunchDarkly in federal environments
    • Public IP list
  • Your account
    • Projects
    • Views
    • Environments
    • Tags
    • Teams
    • Members
    • Roles
    • Account security
    • Feature previews
    • Billing and usage
    • Changelog
Sign inTry it free
LogoLogo
On this page
  • Overview
  • Randomization units
  • Choose the randomization unit
  • Requests
  • Users
  • Multi-contexts
  • Mark context kinds available for guarded rollouts
ReleasesGuarded rolloutsCreating guarded rollouts

Setting up contexts for guarded rollouts

Was this page helpful?
Previous

Health checks for guarded rollouts

Next
Built with

Overview

This topic explains how to set up context kinds for use in guarded rollouts.

Guarded rollouts availability

All LaunchDarkly accounts include a limited trial of guarded rollouts. Use them to understand how well the feature supports your release process in production.

Randomization units

A guarded rollout uses a single context kind, called a randomization unit, to determine how to assign traffic to flag variations.

Most guarded rollouts use the request or user context kind as the randomization unit. This means the rollout assigns the new or original variation based on the request or user encountering the flag. You can also use another context kind, such as device or organization, depending on how your application is configured.

Choose the randomization unit

The randomization unit must be available in both the flag and in any metrics you want to monitor.

We recommend choosing a randomization unit that represents a large number of unique contexts. This helps LaunchDarkly detect performance differences between variations more quickly.

Minimum context requirement for guarded rollouts

A minimum number of contexts must be served the new variation before the next stage of the rollout begins. If this minimum requirement is not met, LaunchDarkly automatically extends the current stage to allow more contexts to receive the new variation. If the requirement is still not met after the extension period, LaunchDarkly rolls back the release.

Requests

For backend-only changes, the request context kind is often the best choice. Systems typically generate many distinct requests, and backend metrics like latency and error rate are usually measured per request.

To use request contexts, configure a context with the kind set to "request" and a key that uniquely identifies the request and remains consistent throughout the request lifecycle:

1{
2 "kind": "request",
3 "key": "request-key-abc-123"
4}

Users

A user randomization unit is often the best choice for:

  • Frontend-only changes
  • Backend changes that may affect frontend metrics
  • Backend changes that may impact performance outside the scope of the current request
Use distinct user keys

Most LaunchDarkly SDKs use user contexts by default. Ensure that your user keys uniquely identify individual users of your application. If they represent something else, such as organizations or requests, rollouts may not behave as expected.

To use user contexts, configure a context with the kind set to "user" and a key that uniquely identifies the user across all interactions:

1{
2 "kind": "user",
3 "key": "example-user-key",
4 "name": "Anna"
5}

If your application supports both logged-in and logged-out end users, make sure each user has a distinct key that remains consistent throughout their experience. To learn more, read Maintaining consistency across user sessions when running experiments.

Multi-contexts

To make a context kind available for use in your guarded rollouts, you must instrument your application code consistently. To simplify this, we recommend using multi-contexts to include multiple context kinds in each flag request.

For example, if your application has both a frontend and a backend service:

  • On the client side, set the current context to a multi-context that includes all the contexts the frontend knows about, such as user and device.
  • On the server side, create a multi-context that includes all the contexts the backend knows about, such as user and request. Use this multi-context when evaluating flags.
    • Use the same multi-context in any custom event tracking calls to ensure consistency with how variations are served.
    • In larger codebases, use middleware to consistently set the LaunchDarkly context for each request.

Mark context kinds available for guarded rollouts

In LaunchDarkly, the default context kind of user is automatically available for use in guarded rollouts. If you have created other context kinds and want to use them as randomization units, make sure they are marked as Available for experiments and guarded rollouts. To learn more, read Mark context kinds available for experiments.

The "New context kind" dialog with the "Available for experiments and guarded rollouts" option checked.

The "New context kind" dialog with the "Available for experiments and guarded rollouts" option checked.

After that, you can configure any metrics that apply to that context kind to use it as a randomization unit.

When creating a guarded rollout, you must choose a randomization unit supported by all the metrics you want to monitor. Only context kinds supported by the selected metrics’ randomization units are available for guarded rollouts.