Migrate feature-to-feature messaging to typed MessageBus#2899
Draft
maxep wants to merge 27 commits into
Draft
Conversation
…tor into TelemetryReceiver
…aring, and CrashReporting
…sionReplay; update tests
…pes; migrate sender
51f3870 to
0eb3c6a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 — sendersand 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 subscribinga
BusMessageReceiver<Message>to theMessageBus. The bus routes each message only tosubscribers that declared interest in it, eliminating broadcast dispatch and making message
contracts explicit and compiler-verified.
How?
BusMessageis a protocol with astatic var key: Stringused as the routing key.BusMessageReceiver<Message: BusMessage>isAnyObject-constrained so receivers can beidentified by
ObjectIdentifierfor subscription and unsubscription.MessageBusexposestyped
subscribe(receiver:)andsubscribe(block:)(returning an opaqueMessageBusSubscriptionhandle) alongside a typedsend<Message>(_ message:).CoreMessageBusimplements this inDatadogCore, dispatching each message only tosubscribers 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), mergingTelemetryInterceptorintoTelemetryReceiverRUMViewEvent,RUMViewReset,RUMSessionState,RUMEventAttributes,LogEventAttributesDatadogContextpropagation (full opt-in subscription model)WebViewLogMessage,WebViewRUMMessage,WebViewRecordMessageFeatureMessage,FeatureMessageReceiver, andMessageSendingare now deprecated.One intentional holdout:
ProfilerStoppayload (profiling still in development).Review checklist
make api-surfacewhen adding new APIs