Skip to content

Flags Feature#2982

Merged
dd-mergequeue[bot] merged 213 commits into
developfrom
merge-from-feature-flagging-feature-branch
Nov 5, 2025
Merged

Flags Feature#2982
dd-mergequeue[bot] merged 213 commits into
developfrom
merge-from-feature-flagging-feature-branch

Conversation

@typotter

@typotter typotter commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR introduces DatadogFlags (dd-sdk-android-flags), a new module for feature flag evaluation in Android applications. The module enables dynamic configuration and A/B testing by integrating with Datadog's Feature Flag product.

Key capabilities:

  • Feature flag evaluation with type-safe APIs for boolean, string, number (int/double), and JSON values
  • Automatic exposure tracking and RUM integration for correlating flags with user sessions
  • Local storage with persistent caching of flag assignments using DataStore
  • Evaluation context management (user attributes, targeting keys)
  • Named client support for multi-project or multi-environment scenarios
  • Bounded LRU cache for exposure event de-duplication to prevent duplicate tracking

Motivation

This feature allows Android developers to dynamically control application behavior through feature flags, enabling:

  • Safe feature rollouts with gradual releases
  • A/B testing and experimentation
  • Runtime configuration without app updates
  • Correlation of feature usage with application performance and user behavior through RUM integration

This implementation follows similar patterns established in the Datadog iOS SDK and aligns with OpenFeature specification principles for provider API design.

Additional Notes

Module Architecture

Core Components:

  • FlagsClient - Main API interface for flag evaluation with methods like resolve(), resolveBooleanValue(), resolveStringValue(), resolveIntValue(), resolveDoubleValue(), and resolveStructureValue()
  • DatadogFlagsClient - Production implementation that integrates with Datadog's flag evaluation system, manages flag resolution, type conversion, and tracking
  • FlagsRepository - Manages Flag and evaluation context storage and, retrieval using DataStore for persistent caching
  • PrecomputedAssignmentsDownloader - Handles fetching precomputed flag assignments from CDN endpoints via HTTP requests
  • PrecomputedAssignmentsRequestFactory - Factory for creating authenticated HTTP requests to the Datadog feature flags service
  • PrecomputeMapper - Parses and maps JSON responses from the CDN into internal flag models
  • EvaluationsManager - Orchestrates flag evaluation context updates and triggers background fetching of flag assignments
  • ExposureEventsProcessor - Tracks flag evaluations with bounded LRU cache for de-duplication, preventing duplicate exposure events
  • RumEvaluationLogger - Reports flag evaluations to RUM for correlation with user sessions and application behavior
  • FlagsFeature - Core feature registration, lifecycle management, and client registry

Supporting Components:

  • FlagsConfiguration - Configuration for RUM integration, exposure tracking, and custom endpoints
  • EvaluationContext - Contains targeting key and attributes for flag evaluation
  • ResolutionDetails - Comprehensive resolution information including value, variant, reason, error details, and metadata
  • FlagValueConverter - Type-safe conversion between flag values and expected types with validation
  • NoOpFlagsClient - Fallback client implementation for graceful error handling when feature is not properly initialized

Related PRs

Key Features

  1. Type-Safe Flag Resolution:

    • Convenience methods for common types (boolean, string, int, double, JSON)
    • Detailed resolve() method with comprehensive metadata and error information
    • Automatic type conversion with fallback to default values on mismatch
  2. Exposure Tracking:*

    • Track when user is exposed to a flag treatment via EvP track
    • De-duplicated exposure event logging with bounded LRU cache
    • Configurable exposure tracking via FlagsConfiguration.trackExposures
    • JSON schema-based event serialization
  3. RUM Integration:

    • Automatic attachment of flag evaluations to RUM views
    • Correlation with user sessions for analysis
    • Configurable via FlagsConfiguration.rumIntegrationEnabled
  4. Named Client Support:

    • Multiple named clients per SDK instance for different domains
    • Thread-safe client registry within FlagsFeature
    • Retrieval of existing clients via FlagsClient.get(name)
  5. Persistent Storage:

    • DataStore-based repository for caching flag assignments
    • Survives app restarts for consistent flag evaluation
    • Background fetching with asynchronous context updates
  6. Error Handling:

    • Comprehensive error codes (FLAG_NOT_FOUND, TYPE_MISMATCH, PARSE_ERROR, etc.)
    • Graceful degradation with default values
    • NoOp client fallback for missing feature initialization

Configuration Options

val flagsConfig = FlagsConfiguration.Builder()
    .rumIntegrationEnabled(true)  // Enable RUM integration (default: true)
    .trackExposures(true)          // Enable exposure tracking (default: true)
    .useCustomFlagEndpoint(url)    // Custom CDN endpoint (optional)
    .useCustomExposureEndpoint(url) // Custom exposure endpoint (optional)
    .build()

Flags.enable(flagsConfig)

Usage Example

// Enable feature
Flags.enable(FlagsConfiguration.Builder().build())

// Create client
val client = FlagsClient.Builder().build()

// Set evaluation context
client.setEvaluationContext(
    EvaluationContext(
        targetingKey = "user-123",
        attributes = mapOf("plan" to "premium")
    )
)

// Evaluate flags
val enabled = client.resolveBooleanValue("new-feature", false)

// Get detailed resolution
val result = client.resolve("experiment-variant", "control")
println("Value: ${result.value}, Variant: ${result.variant}")

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

jonathanmos and others added 30 commits September 11, 2025 16:11
Co-authored-by: Nikita Ogorodnikov <[email protected]>
Co-authored-by: Nikita Ogorodnikov <[email protected]>
…ent-manager-or-eliminate' into typo/FFL-1117-pass-default-client-configuration-to-flags-enable
@typotter
typotter dismissed stale reviews from aleksandr-gringauz, 0xnm, and janine-c via 33c8342 November 5, 2025 16:28
@typotter
typotter requested review from 0xnm and janine-c November 5, 2025 17:03

@typotter typotter left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @janine-c and @0xnm. Just need final stamps.

Comment thread features/dd-sdk-android-flags/README.md Outdated

The Datadog Feature Flags SDK for Android allows you to evaluate feature flags and experiments in your Android application and automatically send flag evaluation data to Datadog for monitoring and analysis.

## Installation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree there's ambiguity. I've reflected the same pattern as the core README: Getting Started and Initial Setup sections.

Comment thread features/dd-sdk-android-flags/README.md Outdated

The `FlagsConfiguration.Builder` supports the following options:

#### RUM integration

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Comment thread features/dd-sdk-android-flags/README.md Outdated
.build()
```

**Note:** This setting only has an effect if you have enabled RUM (see `Prerequisites` section). If RUM is not enabled, flag evaluations are not sent to RUM regardless of this setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

ncreated
ncreated previously approved these changes Nov 5, 2025

@ncreated ncreated left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@janine-c janine-c self-assigned this Nov 5, 2025

@janine-c janine-c left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, thanks for addressing my feedback so quickly! Couple tiny suggestions but no major blockers 🙂

The Datadog Feature Flags SDK for Android allows you to evaluate feature flags and experiments in your Android application and automatically send flag evaluation data to Datadog for monitoring and analysis.

## Installation
## Getting Started

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Getting Started
## Getting started

```

## Prerequisites
### Initial Setup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Initial Setup
### Initial setup

```

**Note:** This setting only has an effect if you have enabled RUM (see `Prerequisites` section). If RUM is not enabled, flag evaluations are not sent to RUM regardless of this setting.
**Note:** This setting only has an effect if you have enabled RUM (see [Initial Setup](#initial-setup) section). If RUM is not enabled, flag evaluations are not sent to RUM regardless of this setting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** This setting only has an effect if you have enabled RUM (see [Initial Setup](#initial-setup) section). If RUM is not enabled, flag evaluations are not sent to RUM regardless of this setting.
**Note:** This setting only has an effect if you have enabled RUM (see [Initial setup](#initial-setup)). If RUM is not enabled, flag evaluations are not sent to RUM regardless of this setting.

- `flagMetadata: Map<String, Any>?` - Optional metadata associated with the flag

**Error Codes:**
##### Error Codes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### Error Codes
##### Error codes

My bad for missing this before, sorry!

## Prerequisites for RUM Integration
1. Add the `dd-sdk-android-rum` dependency to your project
2. Enable RUM before initializing the Flags feature (see `Prerequisites` section)
2. Enable RUM before initializing the Flags feature (see [Initial Setup](#initial-setup) section)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Enable RUM before initializing the Flags feature (see [Initial Setup](#initial-setup) section)
2. Enable RUM before initializing the Flags feature (see [Initial setup](#initial-setup))

@typotter

typotter commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Nov 5, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-11-05 21:06:37 UTC ℹ️ Start processing command /merge


2025-11-05 21:06:43 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in develop is approximately 51m (p90).


2025-11-05 22:15:40 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit 6fc42d0 into develop Nov 5, 2025
27 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the merge-from-feature-flagging-feature-branch branch November 5, 2025 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants