Skip to content

Migrate feature-to-feature messaging to typed MessageBus#2899

Draft
maxep wants to merge 27 commits into
developfrom
maxep/message-bus-subscription
Draft

Migrate feature-to-feature messaging to typed MessageBus#2899
maxep wants to merge 27 commits into
developfrom
maxep/message-bus-subscription

Conversation

@maxep
Copy link
Copy Markdown
Member

@maxep maxep commented May 11, 2026

⚠️ This PR is not ready for review and will be split into smaller PRs before merging.

What and why?

The legacy feature bus was a broadcast mechanism: every message sent on the bus was delivered
to all registered features, each of which had to pattern-match to determine whether the message
was relevant to it. Message payloads were typed as Any, making contracts implicit — senders
and receivers relied on shared knowledge of the underlying type with no compile-time enforcement.

This PR introduces a typed, subscription-based message bus. Each message is an explicit Swift
type conforming to BusMessage. Features declare interest in specific message types by subscribing
a BusMessageReceiver<Message> to the MessageBus. The bus routes each message only to
subscribers that declared interest in it, eliminating broadcast dispatch and making message
contracts explicit and compiler-verified.

How?

BusMessage is a protocol with a static var key: String used as the routing key.
BusMessageReceiver<Message: BusMessage> is AnyObject-constrained so receivers can be
identified by ObjectIdentifier for subscription and unsubscription. MessageBus exposes
typed subscribe(receiver:) and subscribe(block:) (returning an opaque
MessageBusSubscription handle) alongside a typed send<Message>(_ message:).
CoreMessageBus implements this in DatadogCore, dispatching each message only to
subscribers registered for that key.

Features subscribe their receivers to the bus at their convenience.

Migrated messages:

  • CrashMessage, LogMessage (crash reporting ↔ logs)
  • RUMErrorMessage, RUMFlagEvaluationMessage (feature flags → RUM)
  • TelemetryMessage (all features → RUM), merging TelemetryInterceptor into TelemetryReceiver
  • Crash-context payloads: RUMViewEvent, RUMViewReset, RUMSessionState, RUMEventAttributes, LogEventAttributes
  • DatadogContext propagation (full opt-in subscription model)
  • WebViewLogMessage, WebViewRUMMessage, WebViewRecordMessage

FeatureMessage, FeatureMessageReceiver, and MessageSending are now deprecated.
One intentional holdout: ProfilerStop payload (profiling still in development).

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

maxep added 24 commits May 11, 2026 11:25
@maxep maxep force-pushed the maxep/message-bus-subscription branch from 51f3870 to 0eb3c6a Compare May 11, 2026 09:28
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