Skip to content

[chain-pr 3/10] DatadogCore: CoreMessageBus implementation and rename#2929

Draft
maxep wants to merge 4 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-3
Draft

[chain-pr 3/10] DatadogCore: CoreMessageBus implementation and rename#2929
maxep wants to merge 4 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-3

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?

The typed MessageBus protocol introduced in PR #2927 and the test infrastructure added in PR #2928 are ready, but the production MessageBus class in DatadogCore still only implements the legacy FeatureMessage dispatch path. Until CoreMessageBus implements the typed protocol, no production code can route messages through the new typed bus.

This PR is the core implementation layer: it renames the internal MessageBus class to CoreMessageBus to free the protocol name, implements the typed MessageBus protocol on it with a bucket-based dispatch table, wires DatadogCore to expose it via the messageBus property, and migrates the two DatadogContext receivers (ContextSharingTransformer and NetworkContextCoreProvider) from the legacy FeatureMessageReceiver interface to the typed BusMessageReceiver.

How?

MessageBus.swiftCoreMessageBus.swift — typed protocol implementation

CoreMessageBus gains a keyed dispatch table and a full MessageBus conformance:

Addition Detail
receivers: [String: [ObjectIdentifier: Dispatch]] Bucket-based registry keyed by BusMessage.key; inner key is the receiver's object identity. Only receivers registered for a given message kind are iterated on dispatch.
subscribe<Receiver>(receiver:) Registers a typed BusMessageReceiver; captures it strongly in a Dispatch closure. Re-subscribing replaces the previous entry.
unsubscribe<Receiver>(receiver:) Removes the receiver from its bucket; prunes empty buckets.
send<Message>(message:else:) Dispatches typed messages to the matching bucket. Intercepts .configuration telemetry for the existing deferred-accumulation path. Calls fallback when the core is nil or the bucket is empty.

Configuration telemetry is still intercepted before bucket dispatch to preserve the existing deferred-accumulation behaviour, and the legacy FeatureMessage path is kept for receivers that haven't migrated yet:

// Typed dispatch to TelemetryMessage subscribers (new)
if let bucket = self.receivers[TelemetryMessage.key] {
    let message = TelemetryMessage.configuration(configuration)
    bucket.values.forEach { dispatch in dispatch(message, core) }
}

// Legacy dispatch for receivers still on the FeatureMessage bus (kept until all migrate)
self.bus.values.forEach {
    $0.receive(message: .telemetry(.configuration(configuration)), from: core)
}

DatadogCore — expose the typed bus

DatadogCore renames its bus property type from MessageBus (the old class, now CoreMessageBus) and exposes the typed bus through DatadogCoreProtocol:

var messageBus: MessageBus { bus }

Context updates are now routed through the typed bus:

// Before
self.contextProvider.publish { [weak self] context in
    self?.send(message: .context(context))
}

// After
self.contextProvider.publish { [weak self] context in
    self?.bus.send(message: context)
}

ContextSharingTransformer and NetworkContextCoreProvider — typed-bus migration

Both DatadogContext receivers are migrated from FeatureMessageReceiver to BusMessageReceiver:

Type Old New
ContextSharingTransformer FeatureMessageReceiver — switches on .context BusMessageReceiver<DatadogContext> — receives typed context directly
NetworkContextCoreProvider FeatureMessageReceiver — guards on .context BusMessageReceiver<DatadogContext> — receives typed context directly

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 this PR DatadogCore: CoreMessageBus implementation and rename
4 DatadogCrashReporting: typed-bus migration
5 DatadogLogs: typed-bus migration
6 DatadogTrace: typed-bus migration
7 DatadogFlags: typed-bus migration
8 DatadogRUM: typed-bus migration and TelemetryInterceptor merge
9 DatadogSessionReplay and DatadogWebViewTracking: typed-bus migration
10 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-datadog-prod-us1

This comment has been minimized.

@maxep maxep force-pushed the maxep/message-bus-subscription--chain-2 branch from 12f8b82 to e2c1a49 Compare May 19, 2026 16:43
@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-2 branch from e2c1a49 to eebd698 Compare May 19, 2026 18:10
@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-2 branch from eebd698 to 0d4a09e Compare May 20, 2026 08:54
@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-2 branch from 0d4a09e to 9abfa86 Compare June 11, 2026 14:30
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-2 branch 2 times, most recently from 9c99efb to 219583e Compare June 11, 2026 16:49
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from c482945 to c2710e2 Compare June 15, 2026 13:03
Base automatically changed from maxep/message-bus-subscription--chain-2 to feature/message-bus-subscription June 16, 2026 10:55
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from c2710e2 to bf59182 Compare June 16, 2026 11:03
@maxep maxep force-pushed the maxep/message-bus-subscription--chain-3 branch from 12483fe to 39dd976 Compare June 16, 2026 15:33
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