Skip to content

Add API to clear feature flag buffer #5422

@sentry-junior

Description

@sentry-junior

Problem

When users switch accounts in-app, previously recorded feature flag evaluations from the old user persist in the buffer and get attached to error events for the new user. There is no public API to clear or reset the feature flag buffer.

Example:

  • UserA has: experimentA=control, experimentB=experiment
  • UserB has: experimentB=experiment, experimentC=experiment
  • After switching from UserA → UserB, error events report: experimentA=control, experimentB=experiment, experimentC=experiment
  • Expected: only UserB's flags (experimentB=experiment, experimentC=experiment)

Why existing APIs don't work

  • Scope.clear() does not reset the featureFlags field (Scope.java#L564-L578)
  • pushIsolationScope() clones the existing scope (including flags) via isolationScope.clone(), so stale flags carry over
  • addFeatureFlag() updates existing entries by name but cannot remove flags that don't apply to the new user
  • FeatureFlagBuffer and IFeatureFlagBuffer have no clear() method

Proposed changes

  1. Add clear() to IFeatureFlagBuffer and FeatureFlagBuffer
  2. Include featureFlags in Scope.clear() (reset to a fresh buffer)
  3. Optionally expose clearFeatureFlags() on IScope for targeted use

Precedent

The Python SDK already supports this — FlagBuffer.clear() exists and Scope.clear() resets flags to None (sentry-python feature_flags.py#L30, scope.py#L756).

Action taken on behalf of Michael Chai.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions