|
7 | 7 | **Overall:** Layered Event-Driven Architecture with Domain-Driven Design |
8 | 8 |
|
9 | 9 | **Key Characteristics:** |
| 10 | + |
10 | 11 | - Observable-based event system using pub/sub pattern (LifeCycle) |
11 | 12 | - Clear dependency layering: core → rum-core → rum/logs/rum-react |
12 | 13 | - Assembly pattern for event enrichment and transformation |
|
16 | 17 | ## Layers |
17 | 18 |
|
18 | 19 | **Core Layer:** |
| 20 | + |
19 | 21 | - Purpose: Foundation library providing shared utilities and primitives |
20 | 22 | - Location: `packages/core/src` |
21 | 23 | - Contains: Browser APIs, observables, transport, session management, configuration, error handling, telemetry |
22 | 24 | - Depends on: None (base layer) |
23 | 25 | - Used by: All other packages (rum-core, logs, rum-react, worker, flagging) |
24 | 26 |
|
25 | 27 | **RUM Core Layer:** |
| 28 | + |
26 | 29 | - Purpose: Real User Monitoring business logic without UI-specific features |
27 | 30 | - Location: `packages/rum-core/src` |
28 | 31 | - Contains: Event collection (views, actions, errors, resources, long tasks, vitals), RUM assembly, contexts, tracing |
29 | 32 | - Depends on: @datadog/browser-core |
30 | 33 | - Used by: rum, rum-slim, rum-react packages |
31 | 34 |
|
32 | 35 | **Product Layer:** |
| 36 | + |
33 | 37 | - Purpose: User-facing SDK packages with specific feature sets |
34 | 38 | - Location: `packages/rum`, `packages/rum-slim`, `packages/logs`, `packages/rum-react` |
35 | 39 | - Contains: Public APIs, entry points, product-specific features (session replay, profiling, React integration) |
36 | 40 | - Depends on: core and/or rum-core |
37 | 41 | - Used by: End-user applications |
38 | 42 |
|
39 | 43 | **Transport Layer:** |
| 44 | + |
40 | 45 | - Purpose: Data transmission to Datadog backend |
41 | 46 | - Location: `packages/core/src/transport`, `packages/rum-core/src/transport` |
42 | 47 | - Contains: Batching, compression, HTTP requests, event bridge, flush control |
43 | 48 | - Depends on: Core utilities |
44 | 49 | - Used by: Collection modules |
45 | 50 |
|
46 | 51 | **Browser Integration Layer:** |
| 52 | + |
47 | 53 | - Purpose: Browser API observation and instrumentation |
48 | 54 | - Location: `packages/core/src/browser`, `packages/rum-core/src/browser` |
49 | 55 | - Contains: XHR/Fetch observables, performance observables, DOM mutation tracking, location change tracking |
|
73 | 79 | 4. Rate limiters and telemetry track event volumes |
74 | 80 |
|
75 | 81 | **State Management:** |
| 82 | + |
76 | 83 | - Session state persisted in cookies/localStorage |
77 | 84 | - View history maintained in memory with expiration |
78 | 85 | - Context managers use Observable pattern for updates |
|
81 | 88 | ## Key Abstractions |
82 | 89 |
|
83 | 90 | **LifeCycle:** |
| 91 | + |
84 | 92 | - Purpose: Central event bus for SDK-internal communication |
85 | 93 | - Examples: `packages/rum-core/src/domain/lifeCycle.ts` |
86 | 94 | - Pattern: Type-safe pub/sub with enum-based event types (AUTO_ACTION_COMPLETED, RAW_RUM_EVENT_COLLECTED, RUM_EVENT_COLLECTED, etc.) |
87 | 95 |
|
88 | 96 | **Observable:** |
| 97 | + |
89 | 98 | - Purpose: Reactive data streams for browser events |
90 | 99 | - Examples: `packages/core/src/tools/observable.ts`, `packages/core/src/browser/xhrObservable.ts`, `packages/core/src/browser/fetchObservable.ts` |
91 | 100 | - Pattern: Subscribe/unsubscribe with typed callbacks, buffering support |
92 | 101 |
|
93 | 102 | **Collection Modules:** |
| 103 | + |
94 | 104 | - Purpose: Domain-specific event capture and processing |
95 | 105 | - Examples: `packages/rum-core/src/domain/action/actionCollection.ts`, `packages/rum-core/src/domain/resource/resourceCollection.ts`, `packages/rum-core/src/domain/error/errorCollection.ts` |
96 | 106 | - Pattern: Subscribe to observables, emit to LifeCycle, manage domain state |
97 | 107 |
|
98 | 108 | **Assembly:** |
| 109 | + |
99 | 110 | - Purpose: Event enrichment and transformation pipeline |
100 | 111 | - Examples: `packages/rum-core/src/domain/assembly.ts` |
101 | 112 | - Pattern: Combine raw events with contexts, apply hooks, validate modifications, emit assembled events |
102 | 113 |
|
103 | 114 | **Context Managers:** |
| 115 | + |
104 | 116 | - Purpose: Stateful context tracking with customer data |
105 | 117 | - Examples: `packages/core/src/domain/contexts/userContext.ts`, `packages/rum-core/src/domain/contexts/viewHistory.ts` |
106 | 118 | - Pattern: ContextManager interface with set/get/remove, validation, storage sync |
107 | 119 |
|
108 | 120 | **Batch:** |
| 121 | + |
109 | 122 | - Purpose: Event buffering and transmission |
110 | 123 | - Examples: `packages/core/src/transport/batch.ts` |
111 | 124 | - Pattern: Add messages to buffer, upsert by key, flush on trigger, encode before send |
112 | 125 |
|
113 | 126 | ## Entry Points |
114 | 127 |
|
115 | 128 | **RUM Full (with Session Replay):** |
| 129 | + |
116 | 130 | - Location: `packages/rum/src/entries/main.ts` |
117 | 131 | - Triggers: Application calls `datadogRum.init()` |
118 | 132 | - Responsibilities: Initialize RUM core, start recorder API, start profiler API, create deflate encoder, expose DD_RUM global |
119 | 133 |
|
120 | 134 | **RUM Slim (without Session Replay):** |
| 135 | + |
121 | 136 | - Location: `packages/rum-slim/src/entries/main.ts` |
122 | 137 | - Triggers: Application calls `datadogRum.init()` |
123 | 138 | - Responsibilities: Initialize RUM core with stub recorder, lighter bundle size |
124 | 139 |
|
125 | 140 | **RUM Core Bootstrap:** |
| 141 | + |
126 | 142 | - Location: `packages/rum-core/src/boot/startRum.ts` |
127 | 143 | - Triggers: Called by product packages (rum, rum-slim) |
128 | 144 | - Responsibilities: Start all collection modules, initialize contexts, start transport, wire up LifeCycle subscriptions |
129 | 145 |
|
130 | 146 | **Logs:** |
| 147 | + |
131 | 148 | - Location: `packages/logs/src/entries/main.ts` |
132 | 149 | - Triggers: Application calls `datadogLogs.init()` |
133 | 150 | - Responsibilities: Initialize log collection, start transport, expose DD_LOGS global |
134 | 151 |
|
135 | 152 | **React Plugin:** |
| 153 | + |
136 | 154 | - Location: `packages/rum-react/src/entries/main.ts` |
137 | 155 | - Triggers: Application passes plugin to `datadogRum.init()` |
138 | 156 | - Responsibilities: React error boundary, performance tracking, React Router integration |
|
142 | 160 | **Strategy:** Monitored execution with fallback to ensure SDK never breaks host application |
143 | 161 |
|
144 | 162 | **Patterns:** |
| 163 | + |
145 | 164 | - `monitor()` and `monitored()` decorators wrap SDK functions to catch and report internal errors |
146 | 165 | - `catchUserErrors()` wraps user-provided callbacks to isolate user code failures |
147 | 166 | - `trackRuntimeError()` reports SDK errors to telemetry without throwing |
|
158 | 177 |
|
159 | 178 | --- |
160 | 179 |
|
161 | | -*Architecture analysis: 2026-01-21* |
| 180 | +_Architecture analysis: 2026-01-21_ |
0 commit comments