Managing Feature Flags
Codegen has been used in production for multi-million line codebases to automatically delete “dead” (rolled-out) feature flags. This guide will walk you through analyzing feature flag usage and safely removing rolled out flags.
Every codebase does feature flags differently. This guide shows common techniques and syntax but likely requires adaptation to codebase-specific circumstances.
Analyzing Feature Flag Usage
Before removing a feature flag, it’s important to analyze its usage across the codebase. Codegen provides tools to help identify where and how feature flags are used.
For Python Codebases
For Python codebases using a FeatureFlags
class pattern like so:
You can use Class.get_attribute(…) and Attribute.usages to analyze the coverage of your flags, like so:
This will output a table showing all feature flags and their usage counts, helping identify which flags are candidates for removal.
Learn more about Attributes and tracking usages here
Removing Rolled Out Flags
Once you’ve identified a flag that’s ready to be removed, Codegen can help safely delete it and its associated code paths.
This primarily leverages Codegen’s API for reduction conditions
Python Example
For Python codebases, here’s how to remove a feature flag and its usages:
React/TypeScript Example
For React applications using a hooks-based feature flag system:
This will:
- Remove the feature flag from the configuration
- Find all usages of the
useFeatureFlag
hook for this flag - Automatically reduce any conditional logic using the flag
- Handle common React patterns like ternaries and conditional rendering
Related Resources
- Reducing Conditions - Details on condition reduction APIs
- Dead Code Removal - Remove unused code after flag deletion
Was this page helpful?