Skip to content

[chain-pr 7/10] DatadogFlags: typed-bus migration#2933

Open
maxep wants to merge 3 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-7
Open

[chain-pr 7/10] DatadogFlags: typed-bus migration#2933
maxep wants to merge 3 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-7

Conversation

@maxep

@maxep maxep commented May 19, 2026

Copy link
Copy Markdown
Member

This PR is part of a chain split from maxep/message-bus-subscription by chain-pr.

What and why?

With CoreMessageBus implementing the typed MessageBus protocol (PR #2929), DatadogFlags can stop routing flag evaluation events through FeatureScope and send them directly on the typed bus.

RUMFlagEvaluationReporter previously held a FeatureScope reference and called featureScope.send(message: .payload(RUMFlagEvaluationMessage(...))). The FeatureScope was only used for its send capability, not for event writing, making it a heavier dependency than needed. It now holds a MessageBus reference and calls messageBus.send(message:) directly.

This simplifies the FlagsFeature factory: makeRUMFlagEvaluationReporter previously required a FeatureScope argument passed through from FlagsClient. That argument is removed — the factory closure now captures core.messageBus directly at feature initialisation time.

How?

RUMFlagEvaluationReporter.swiftFeatureScopeMessageBus

// Before
private let featureScope: any FeatureScope
init(featureScope: any FeatureScope) { ... }

func sendFlagEvaluation<T>(flagKey: String, value: T) where T: FlagValue {
    featureScope.send(message: .payload(RUMFlagEvaluationMessage(flagKey: flagKey, value: value)))
}

// After
private let messageBus: any MessageBus
init(messageBus: any MessageBus) { ... }

func sendFlagEvaluation<T>(flagKey: String, value: T) where T: FlagValue {
    messageBus.send(message: RUMFlagEvaluationMessage(flagKey: flagKey, value: value))
}

FlagsFeature.swift — factory closure captures messageBus

// Before
let makeRUMFlagEvaluationReporter: (any FeatureScope) -> any RUMFlagEvaluationReporting

makeRUMFlagEvaluationReporter = { featureScope in
    return RUMFlagEvaluationReporter(featureScope: featureScope)
}

// After
let makeRUMFlagEvaluationReporter: () -> any RUMFlagEvaluationReporting

makeRUMFlagEvaluationReporter = { [messageBus = core.messageBus] in
    return RUMFlagEvaluationReporter(messageBus: messageBus)
}

FlagsClient.swift — call site simplification

// Before
rumFlagEvaluationReporter: feature.makeRUMFlagEvaluationReporter(featureScope)

// After
rumFlagEvaluationReporter: feature.makeRUMFlagEvaluationReporter()

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs - see our guidelines (internal)
  • Run make api-surface when adding new APIs

Chain overview

# PR Title
1 #2927 Typed MessageBus protocol and shared message types
2 #2928 Test infrastructure for typed message bus
3 #2929 DatadogCore: CoreMessageBus implementation and rename
4 #2930 DatadogCrashReporting: typed-bus migration
5 #2931 DatadogLogs: typed-bus migration
6 #2932 DatadogTrace: typed-bus migration
7 this PR DatadogFlags: typed-bus migration
8 #2934 DatadogRUM: typed-bus migration and TelemetryInterceptor merge
9 #2935 DatadogSessionReplay and DatadogWebViewTracking: typed-bus migration
10 #2936 Documentation updates
graph LR
    G1["1 — Typed MessageBus protocol and shared message types"]
    G2["2 — Test infrastructure for typed message bus"]
    G3["3 — DatadogCore: CoreMessageBus implementation and rename"]
    G4["4 — DatadogCrashReporting: typed-bus migration"]
    G5["5 — DatadogLogs: typed-bus migration"]
    G6["6 — DatadogTrace: typed-bus migration"]
    G7["7 — DatadogFlags: typed-bus migration"]
    G8["8 — DatadogRUM: typed-bus migration and TelemetryInterceptor merge"]
    G9["9 — DatadogSessionReplay and DatadogWebViewTracking: typed-bus migration"]
    G10["10 — Documentation updates"]
    G1 --> G2
    G2 --> G3
    G3 --> G4
    G3 --> G5
    G5 --> G6
    G3 --> G7
    G6 --> G8
    G7 --> G8
    G8 --> G9
    G1 --> G10
Loading

Merge in dependency order. PRs with no incoming edges from un-merged PRs can be reviewed in parallel.

@datadog-prod-us1-5

This comment has been minimized.

@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from ed91047 to 2469c47 Compare May 19, 2026 17:55
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-7 branch from 185b00a to f54b5ec Compare May 19, 2026 17:55
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from 2469c47 to 588136c Compare May 19, 2026 18:10
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-7 branch from f54b5ec to c97dbac Compare May 19, 2026 18:10
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from 588136c to c482945 Compare May 20, 2026 08:54
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-7 branch from c97dbac to 2f2ffbc Compare May 20, 2026 08:55
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from c482945 to c2710e2 Compare June 15, 2026 13:03
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-7 branch from 2f2ffbc to 176b9f2 Compare June 15, 2026 13:05
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch 2 times, most recently from 12483fe to 39dd976 Compare June 16, 2026 15:33
Base automatically changed from maxep/message-bus-subscription--chain-3 to feature/message-bus-subscription June 19, 2026 13:54
@maxep maxep marked this pull request as ready for review June 26, 2026 13:39
@maxep maxep requested review from a team as code owners June 26, 2026 13:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 775ac7ec68

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

telemetry: core.telemetry
)

core.messageBus.subscribe(receiver: FlagEvaluationReceiver(monitor: monitor))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid leaking flag receivers across RUM registrations

When RUM is enabled more than once on the same core, or when RUMFeature is constructed but core.register(feature:) later fails, this installs a new typed-bus FlagEvaluationReceiver that is never replaced or unsubscribed; the typed bus retains receivers until unsubscribe, unlike the legacy messageReceiver path that DatadogCore.register replaces by feature key. Later flag evaluations are therefore delivered to stale monitors as well as the current one, which can duplicate feature-flag updates or use stale RUM configuration. Store the receiver/subscription and remove or replace it during teardown/re-registration.

Useful? React with 👍 / 👎.

@sbarrio sbarrio requested a review from tienquocbui July 1, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant