Skip to content

[chain-pr 5/10] DatadogLogs: typed-bus migration - #2931

Merged
maxep merged 11 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-5
Jul 20, 2026
Merged

[chain-pr 5/10] DatadogLogs: typed-bus migration#2931
maxep merged 11 commits into
feature/message-bus-subscriptionfrom
maxep/message-bus-subscription--chain-5

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), DatadogLogs can retire its FeatureMessageReceiver switch and adopt the typed bus throughout.

LogMessageReceiver and WebViewLogReceiver previously implemented FeatureMessageReceiver with a runtime guard on the .payload case and a cast to the expected type. They now conform to BusMessageReceiver directly, receiving their concrete message type with no envelope or cast.

RemoteLogger previously called featureScope.send(message: .payload(RUMErrorMessage(...))) to forward log errors to RUM. It now holds a MessageBus reference and calls messageBus.send(message:) directly, severing the dependency on FeatureScope for cross-feature emission.

The LogEventAttributes broadcast triggered by Logs.updateGlobalAttribute / Logs.removeGlobalAttribute also moves from core.send(message: .payload(...)) to core.messageBus.send(message:).

How?

MessageReceivers.swiftBusMessageReceiver conformance

Both receivers change from struct to final class (required by BusMessageReceiver) and replace the receive(message: FeatureMessage, from:) -> Bool method with a typed variant:

Receiver Old New
LogMessageReceiver FeatureMessageReceiver — guards on .payload(log as LogMessage) BusMessageReceiver<LogMessage> — receives LogMessage directly
WebViewLogReceiver FeatureMessageReceiver — guards on .webview(.log(event)) BusMessageReceiver<WebViewLogMessage> — receives WebViewLogMessage directly

LogsFeature.swift — retained receiver references and subscription wiring

LogsFeature now holds strong references to the two receivers so that Logs.enable can subscribe them after feature creation:

// In Logs.enable:
core.messageBus.subscribe(receiver: feature.logMessageReceiver)
core.messageBus.subscribe(receiver: feature.webViewLogReceiver)

The old CombinedFeatureMessageReceiver wiring in the DatadogRemoteFeature initialiser is replaced with NOPFeatureMessageReceiver().

RemoteLogger.swift — direct bus send for RUM error forwarding

// Before
self.featureScope.send(message: .payload(RUMErrorMessage(...)))

// After
self.messageBus.send(message: RUMErrorMessage(...))

RemoteLogger now receives a MessageBus at init and stores it as let messageBus: MessageBus. The featureScope reference is no longer used for cross-feature emission.

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 this PR DatadogLogs: typed-bus migration
6 #2932 DatadogTrace: typed-bus migration
7 #2933 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-official

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-5 branch from 21314b1 to ec7dc67 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-5 branch from ec7dc67 to ba7bf22 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-5 branch from ba7bf22 to a00efe9 Compare May 20, 2026 08:54
@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-5 branch from a00efe9 to 935cf5e 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 11:09
@maxep
maxep requested review from a team as code owners June 26, 2026 11:09

@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: dd5e9e2e56

ℹ️ 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".

Comment thread DatadogLogs/Sources/Logs.swift Outdated
@sbarrio
sbarrio requested a review from arroz July 6, 2026 09:55

@arroz arroz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Left a comment regarding memory handling, feel free to dismiss if it's safe.

Comment thread DatadogLogs/Sources/Feature/MessageReceivers.swift
CrashContextCoreProvider consumes LogEventAttributes as a legacy
FeatureMessageReceiver, so routing Logs.addAttribute/removeAttribute
through the typed bus dropped global log attributes from crash reports.
Revert sendAttributesChanged to the legacy bus until CrashReporting
migrates, and add an integration test covering the crash-context path.

@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: 8f8da76055

ℹ️ 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".

try core.register(feature: feature)

// Subscribe typed-bus receivers:
core.messageBus.subscribe(receiver: feature.logMessageReceiver)

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 accumulating log receivers on re-enable

When Logs.enable(in:) is called more than once for the same core, each call creates a new LogMessageReceiver instance and subscribes it here. The typed bus de-duplicates only the same object identity, whereas the old legacy receiver was replaced under the single "logging" feature key, so subsequent TracingWithLoggingIntegration / span.log LogMessages are delivered to every accumulated receiver and written multiple times.

Useful? React with 👍 / 👎.

@maxep
maxep merged commit d3693c5 into feature/message-bus-subscription Jul 20, 2026
19 checks passed
@maxep
maxep deleted the maxep/message-bus-subscription--chain-5 branch July 20, 2026 14:05
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.

2 participants