Skip to content

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

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

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

Conversation

@maxep

@maxep maxep commented May 11, 2026

Copy link
Copy Markdown
Member

⚠️ 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 maxep force-pushed the maxep/message-bus-subscription branch from 51f3870 to 0eb3c6a Compare May 11, 2026 09:28
maxep added 25 commits May 19, 2026 17:59
@maxep maxep force-pushed the maxep/message-bus-subscription branch from 162e6e0 to ea98185 Compare May 19, 2026 16:00
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented May 19, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 2 Pipeline jobs failed

DataDog/dd-sdk-ios | Unit Tests (visionOS)   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). Unit Tests failed with exit status 65 due to deprecated usage of 'FeatureMessageReceiver' and 'FeatureMessage' instead of 'BusMessageReceiver' and 'BusMessage'.

DataDog/dd-sdk-ios | Unit Tests (iOS)   View in Datadog   GitLab

🔄 Retry job. This looks flaky and may succeed on retry. Job failed: execution took longer than 1h0m0s seconds

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ea98185 | Docs | Datadog PR Page | Give us feedback!

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