Skip to content

Commit cd26a35

Browse files
committed
prettier
1 parent e3a9142 commit cd26a35

File tree

18 files changed

+450
-422
lines changed

18 files changed

+450
-422
lines changed

packages/live-debugger/src/domain/probes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export interface InitializedProbe extends Probe {
6161
// Benchmarks show that using an object is much faster than a Map.
6262
const activeProbes: Record<string, InitializedProbe[]> = {
6363
// @ts-expect-error - Pre-populate with a dummy key to help V8 optimize property lookups.
64-
__dummy__: undefined
64+
__dummy__: undefined,
6565
}
6666
const probeIdToFunctionId: Record<string, string> = {
6767
// @ts-expect-error - Pre-populate with a dummy key to help V8 optimize property lookups.
68-
__dummy__: undefined
68+
__dummy__: undefined,
6969
}
7070

7171
/**

packages/live-debugger/src/domain/remoteConfig.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { Probe } from './probes'
55

66
/**
77
* Remote Config Client for Browser Live Debugger
8-
*
8+
*
99
* Polls the RC proxy periodically to get probe updates and synchronizes
1010
* the local probe registry.
11-
*
11+
*
1212
* NOTE: The RC proxy can operate in two modes:
1313
* - agent mode: Polls local Datadog agent (for POC/development, no CORS issues)
1414
* - backend mode: Polls Datadog RC backend directly (requires backend access)
@@ -92,11 +92,11 @@ export function stopRemoteConfigPolling(): void {
9292

9393
/**
9494
* Synchronize local probes with probes from RC proxy
95-
*
95+
*
9696
* - Adds new probes
9797
* - Removes probes no longer in the response
9898
* - Updates probes if version changed
99-
*
99+
*
100100
* @param probes - Array of probes from RC proxy
101101
*/
102102
function synchronizeProbes(probes: Probe[]): void {
@@ -111,7 +111,7 @@ function synchronizeProbes(probes: Probe[]): void {
111111

112112
const probeState: ProbeState = {
113113
id: probe.id,
114-
version: probe.version
114+
version: probe.version,
115115
}
116116
newProbeStates.set(probe.id, probeState)
117117

@@ -175,4 +175,3 @@ export function clearRemoteConfigState(): void {
175175
pollIntervalId = undefined
176176
}
177177
}
178-

sandbox/debugger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
service: 'poc-browser-live-debugger',
1111
env: 'watson-dev',
1212
version: `1.0.0-${crypto.randomUUID().slice(0, 8)}`,
13-
remoteConfigProxyUrl: 'http://localhost:3030'
13+
remoteConfigProxyUrl: 'http://localhost:3030',
1414
})
1515

1616
// TODO: Remove hardcoded probes once dynamic probe management is implemented

sandbox/live-debugger-test.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,23 @@ <h2>Configuration</h2>
141141
<form id="config-form" onsubmit="event.preventDefault(); startLiveDebugger()">
142142
<div class="form-group">
143143
<label for="service-input">Service:</label>
144-
<input
145-
type="text"
146-
id="service-input"
147-
value="my-service"
148-
placeholder="Enter service name"
149-
required
150-
/>
144+
<input type="text" id="service-input" value="my-service" placeholder="Enter service name" required />
151145
</div>
152146
<div class="form-group">
153147
<label for="env-input">Environment:</label>
154-
<input
155-
type="text"
156-
id="env-input"
157-
value="dev"
158-
placeholder="Enter environment name"
159-
required
160-
/>
148+
<input type="text" id="env-input" value="dev" placeholder="Enter environment name" required />
161149
</div>
162150
<div class="form-group">
163151
<button type="submit" class="primary" id="start-button">Start Live Debugger</button>
164152
</div>
165153
</form>
166-
<div id="config-display" style="display: none; margin-top: 15px; padding-top: 15px; border-top: 1px solid #ddd;">
154+
<div id="config-display" style="display: none; margin-top: 15px; padding-top: 15px; border-top: 1px solid #ddd">
167155
<strong>RC Proxy URL:</strong> <span id="proxy-url">http://localhost:3030</span><br />
168156
<strong>Service:</strong> <span id="service-value">-</span><br />
169157
<strong>Environment:</strong> <span id="env-value">-</span><br />
170158
<strong>Version:</strong> <span id="version-value">-</span>
171159
</div>
172-
<p id="auto-trigger-note" style="display: none; margin-top: 10px; font-size: 14px; color: #666;">
160+
<p id="auto-trigger-note" style="display: none; margin-top: 10px; font-size: 14px; color: #666">
173161
Instrumented functions in <code>probes-go-here.js</code> are automatically triggered every second.
174162
</p>
175163
</div>
@@ -222,7 +210,7 @@ <h2>Console Log</h2>
222210
const timeoutId = setTimeout(() => controller.abort(), 3000) // 3 second timeout
223211

224212
const response = await fetch(`${RC_PROXY_URL}/health`, {
225-
signal: controller.signal
213+
signal: controller.signal,
226214
})
227215
clearTimeout(timeoutId)
228216

@@ -317,7 +305,7 @@ <h2>Console Log</h2>
317305
service,
318306
env,
319307
version,
320-
remoteConfigProxyUrl: RC_PROXY_URL
308+
remoteConfigProxyUrl: RC_PROXY_URL,
321309
})
322310

323311
logToConsole('✅ Live Debugger initialized with RC proxy')

sandbox/probes-go-here.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function sometimesThrows(a, b) {
1111
if (Math.random() < 0.2) {
1212
throw new Error('Sometimes throws')
1313
}
14-
return $dd_p ? $dd_return($dd_p, (sum), this, { a, b }, { sum }) : (sum)
14+
return $dd_p ? $dd_return($dd_p, sum, this, { a, b }, { sum }) : sum
1515
} catch (e) {
1616
if ($dd_p) $dd_throw($dd_p, e, this, { a, b })
1717
throw e
@@ -31,7 +31,7 @@ function withLocals(a, b) {
3131
label = false
3232
}
3333
obj.label = label
34-
return $dd_p ? $dd_return($dd_p, (obj), this, { a, b }, { arr, obj, label }) : (obj)
34+
return $dd_p ? $dd_return($dd_p, obj, this, { a, b }, { arr, obj, label }) : obj
3535
} catch (e) {
3636
if ($dd_p) $dd_throw($dd_p, e, this, { a, b })
3737
throw e
@@ -42,7 +42,7 @@ function noLocals(a, b) {
4242
const $dd_p = $dd_probes('probes-go-here.js;noLocals')
4343
try {
4444
if ($dd_p) $dd_entry($dd_p, this, { a, b })
45-
return $dd_p ? $dd_return($dd_p, (a * b), this, { a, b }, {}) : (a * b)
45+
return $dd_p ? $dd_return($dd_p, a * b, this, { a, b }, {}) : a * b
4646
} catch (e) {
4747
if ($dd_p) $dd_throw($dd_p, e, this, { a, b })
4848
throw e

sandbox/rc-proxy/QUICKSTART.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
A complete Remote Config proxy system for browser Live Debugger consisting of:
66

77
### 1. RC Proxy Service (`sandbox/rc-proxy/`)
8+
89
- **Client Tracker**: Tracks active browser clients with 30s TTL (like Datadog Agent)
910
- **RC Client**: Communicates with Datadog RC backend using protobuf
1011
- **Express Server**: Serves probes via HTTP GET endpoints
1112
- **Background Polling**: Automatically polls RC when clients are active
1213

1314
### 2. Browser SDK Integration (`packages/live-debugger/`)
15+
1416
- **Remote Config Module**: Polls proxy and syncs probes automatically
1517
- **Init Configuration**: Added `remoteConfigProxyUrl` option
1618
- **Probe Synchronization**: Adds, removes, and updates probes dynamically
1719

1820
### 3. Test Page (`sandbox/live-debugger-test.html`)
21+
1922
- Simple UI to test the RC proxy integration
2023
- Shows active probes, proxy health, and fired probes
2124
- Test functions to trigger instrumented code
@@ -44,6 +47,7 @@ npm start
4447
The proxy will start on http://localhost:3030
4548

4649
You should see:
50+
4751
```
4852
✅ Server running on port 3030
4953
- Probes endpoint: http://localhost:3030/probes?service=my-app
@@ -74,6 +78,7 @@ This creates `packages/live-debugger/bundle/live-debugger.js`
7478
Open `sandbox/live-debugger-test.html` in your browser.
7579

7680
The page will:
81+
7782
- Initialize Live Debugger with RC proxy URL
7883
- Start polling the proxy every 5 seconds
7984
- Display active probes from Datadog
@@ -106,18 +111,22 @@ The page will:
106111
## Troubleshooting
107112

108113
### Proxy says "No active clients"
114+
109115
This is normal when no browsers are connected. Open the test page and it will start polling.
110116

111117
### Browser not receiving probes
118+
112119
1. Check browser console for errors
113120
2. Verify `remoteConfigProxyUrl` is correct
114121
3. Check proxy `/health` endpoint
115122
4. Ensure probes are configured in Datadog for service `browser-test-app`
116123

117124
### Proxy returning 401 from Datadog
125+
118126
Check your `DD_API_KEY` in `.env` file is valid and has RC scope.
119127

120128
### Probes not firing
129+
121130
1. Verify probes are loaded (check "Current Probes" section)
122131
2. Ensure probe targets match function names
123132
3. Check browser console for Live Debugger errors
@@ -143,18 +152,21 @@ Check your `DD_API_KEY` in `.env` file is valid and has RC scope.
143152
## Architecture Details
144153

145154
### RC Proxy Files
155+
146156
- `index.js` - Main Express server and endpoints
147157
- `rc-client.js` - Datadog RC protocol client (protobuf)
148158
- `client-tracker.js` - Active client tracking with TTL
149159
- `config.js` - Environment configuration
150160
- `remoteconfig.proto` - Protobuf schema
151161

152162
### Browser SDK Files
163+
153164
- `packages/live-debugger/src/entries/main.ts` - Init with RC config
154165
- `packages/live-debugger/src/domain/remoteConfig.ts` - RC polling and sync
155166
- `packages/live-debugger/src/domain/probes.ts` - Probe management
156167

157168
### Key Features
169+
158170
- ✅ Dynamic client tracking (30s TTL)
159171
- ✅ Protobuf protocol compatibility
160172
- ✅ Hardcoded to LIVE_DEBUGGING only
@@ -165,6 +177,7 @@ Check your `DD_API_KEY` in `.env` file is valid and has RC scope.
165177
## Support
166178

167179
For questions or issues:
180+
168181
1. Check the proxy logs for errors
169182
2. Check browser console for SDK errors
170183
3. Verify RC is enabled in your Datadog org
@@ -173,4 +186,3 @@ For questions or issues:
173186
## License
174187

175188
Apache-2.0
176-

sandbox/rc-proxy/README.agent-mode.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ npm start
4040
```
4141

4242
### 4. The proxy will now:
43+
4344
- Poll your local agent at `http://localhost:8126/v0.7/config`
4445
- Get the same LIVE_DEBUGGING probes your backend services see
4546
- Serve them to the browser SDK (with CORS headers)
@@ -54,7 +55,7 @@ window.DD_LIVE_DEBUGGER.init({
5455
env: 'production',
5556
version: '1.0.0',
5657
remoteConfigProxyUrl: 'http://localhost:3030',
57-
remoteConfigPollInterval: 5000
58+
remoteConfigPollInterval: 5000,
5859
})
5960
```
6061

sandbox/rc-proxy/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ The proxy will start on `http://localhost:3030`.
5757
Register a client and fetch probes for it.
5858

5959
**Query Parameters:**
60+
6061
- `service` (required): Service name
6162
- `env` (optional): Environment (e.g., `prod`, `staging`)
6263
- `version` (optional): Application version
6364

6465
**Example:**
66+
6567
```bash
6668
curl "http://localhost:3030/probes?service=my-app&env=prod&version=1.0.0"
6769
```
6870

6971
**Response:**
72+
7073
```json
7174
{
7275
"probes": [
@@ -87,11 +90,13 @@ curl "http://localhost:3030/probes?service=my-app&env=prod&version=1.0.0"
8790
Get proxy status and health information.
8891

8992
**Example:**
93+
9094
```bash
9195
curl http://localhost:3030/health
9296
```
9397

9498
**Response:**
99+
95100
```json
96101
{
97102
"ok": true,
@@ -142,19 +147,20 @@ If no clients are active, the proxy skips the RC poll to save resources.
142147
Initialize the Live Debugger with the proxy URL:
143148

144149
```javascript
145-
import { datadogLiveDebugger } from '@datadog/browser-live-debugger';
150+
import { datadogLiveDebugger } from '@datadog/browser-live-debugger'
146151

147152
datadogLiveDebugger.init({
148153
clientToken: '<DATADOG_CLIENT_TOKEN>',
149154
site: 'datadoghq.com',
150155
service: 'my-browser-app',
151156
env: 'production',
152157
version: '1.0.0',
153-
remoteConfigProxyUrl: 'http://localhost:3030'
154-
});
158+
remoteConfigProxyUrl: 'http://localhost:3030',
159+
})
155160
```
156161

157162
The SDK will automatically:
163+
158164
- Poll `/probes` every 5 seconds with service metadata
159165
- Add new probes dynamically
160166
- Remove probes that are no longer configured
@@ -226,4 +232,3 @@ sandbox/rc-proxy/
226232
## License
227233

228234
Apache-2.0
229-

0 commit comments

Comments
 (0)