Skip to content

Commit 4df303f

Browse files
committed
Add Live Debugger package
Introduce the browser debugger SDK and probe execution pipeline so browser code can evaluate conditions, capture snapshots, and render probe messages at runtime. Add Delivery API polling plus sandbox and performance tooling to support probe delivery and testing.
1 parent abcbafe commit 4df303f

61 files changed

Lines changed: 10059 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint-local-rules/disallowSideEffects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const pathsWithSideEffect = new Set([
2929
`${packagesRoot}/logs/src/entries/main.ts`,
3030
`${packagesRoot}/rum/src/entries/main.ts`,
3131
`${packagesRoot}/rum-slim/src/entries/main.ts`,
32+
`${packagesRoot}/debugger/src/entries/main.ts`,
3233
])
3334

3435
// Those packages are known to have no side effects when evaluated

packages/core/src/domain/configuration/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export interface InitConfiguration {
276276
*
277277
* @internal
278278
*/
279-
source?: 'browser' | 'flutter' | 'unity' | undefined
279+
source?: 'browser' | 'flutter' | 'unity' | 'dd_debugger' | undefined
280280

281281
/**
282282
* [Internal option] Additional configuration for the SDK.
@@ -331,7 +331,7 @@ export interface Configuration extends TransportConfiguration {
331331

332332
// internal
333333
sdkVersion: string | undefined
334-
source: 'browser' | 'flutter' | 'unity'
334+
source: 'browser' | 'flutter' | 'unity' | 'dd_debugger'
335335
variant: string | undefined
336336
}
337337

packages/core/src/domain/configuration/transportConfiguration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface TransportConfiguration {
1414
datacenter?: string | undefined
1515
replica?: ReplicaConfiguration
1616
site: Site
17-
source: 'browser' | 'flutter' | 'unity'
17+
source: 'browser' | 'flutter' | 'unity' | 'dd_debugger'
1818
}
1919

2020
export interface ReplicaConfiguration {
@@ -38,7 +38,7 @@ export function computeTransportConfiguration(initConfiguration: InitConfigurati
3838
}
3939

4040
function validateSource(source: string | undefined) {
41-
if (source === 'flutter' || source === 'unity') {
41+
if (source === 'flutter' || source === 'unity' || source === 'dd_debugger') {
4242
return source
4343
}
4444
return 'browser'

packages/core/src/domain/telemetry/telemetryEvent.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ export interface CommonTelemetryProperties {
585585
| 'kotlin-multiplatform'
586586
| 'electron'
587587
| 'rum-cpp'
588+
| 'dd_debugger'
588589
/**
589590
* The version of the SDK generating the telemetry event
590591
*/

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
isSampleRate,
88
buildEndpointHost,
99
isIntakeUrl,
10+
computeTransportConfiguration,
1011
} from './domain/configuration'
1112
export * from './domain/intakeSites'
1213
export type { TrackingConsentState } from './domain/trackingConsent'
@@ -57,7 +58,7 @@ export {
5758
SESSION_NOT_TRACKED,
5859
SessionPersistence,
5960
} from './domain/session/sessionConstants'
60-
export type { BandwidthStats, HttpRequest, HttpRequestEvent, Payload, FlushEvent, FlushReason } from './transport'
61+
export type { Batch, BandwidthStats, HttpRequest, HttpRequestEvent, Payload, FlushEvent, FlushReason } from './transport'
6162
export {
6263
createHttpRequest,
6364
canUseEventBridge,

packages/core/src/transport/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type { BandwidthStats, HttpRequest, HttpRequestEvent, Payload, RetryInfo
22
export { createHttpRequest } from './httpRequest'
33
export type { BrowserWindowWithEventBridge, DatadogEventBridge } from './eventBridge'
44
export { canUseEventBridge, bridgeSupports, getEventBridge, BridgeCapability } from './eventBridge'
5+
export type { Batch } from './batch'
56
export { createBatch } from './batch'
67
export type { FlushController, FlushEvent, FlushReason } from './flushController'
78
export { createFlushController, FLUSH_DURATION_LIMIT } from './flushController'

packages/debugger/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Live Debugger Browser Monitoring
2+
3+
Datadog Live Debugger enables you to capture function execution snapshots, evaluate conditions, and collect runtime data from your application without modifying source code.
4+
5+
## Usage
6+
7+
To start using the live debugger, add [`@datadog/browser-debugger`](https://www.npmjs.com/package/@datadog/browser-debugger) to your `package.json` file, then initialize it with:
8+
9+
```javascript
10+
import { datadogLiveDebugger } from '@datadog/browser-debugger'
11+
12+
datadogLiveDebugger.init({
13+
clientToken: '<DATADOG_CLIENT_TOKEN>',
14+
applicationId: '<DATADOG_APPLICATION_ID>',
15+
service: 'my-web-application',
16+
site: '<DATADOG_SITE>',
17+
env: 'production',
18+
version: '1.0.0',
19+
})
20+
```
21+
22+
The debugger automatically polls for probe updates from the Delivery API.
23+
24+
You can also add probes programmatically:
25+
26+
```javascript
27+
datadogLiveDebugger.addProbe({
28+
id: 'probe-1',
29+
version: 0,
30+
type: 'LOG_PROBE',
31+
where: { typeName: 'MyClass', methodName: 'myMethod' },
32+
template: 'Method executed with duration: {@duration}ms',
33+
segments: [
34+
{ str: 'Method executed with duration: ' },
35+
{ dsl: '@duration', json: { ref: '@duration' } },
36+
{ str: 'ms' },
37+
],
38+
captureSnapshot: true,
39+
capture: { maxReferenceDepth: 3 },
40+
sampling: { snapshotsPerSecond: 5000 },
41+
evaluateAt: 'EXIT',
42+
})
43+
```
44+
45+
## Integration with RUM
46+
47+
The Live Debugger integrates seamlessly with Datadog RUM to provide enhanced context and correlation:
48+
49+
```javascript
50+
import { datadogRum } from '@datadog/browser-rum'
51+
import { datadogLiveDebugger } from '@datadog/browser-debugger'
52+
53+
// Initialize RUM first
54+
datadogRum.init({
55+
applicationId: '<DATADOG_APPLICATION_ID>',
56+
clientToken: '<DATADOG_CLIENT_TOKEN>',
57+
site: '<DATADOG_SITE>',
58+
service: 'my-web-application',
59+
env: 'production',
60+
})
61+
62+
// Then initialize Live Debugger
63+
datadogLiveDebugger.init({
64+
clientToken: '<DATADOG_CLIENT_TOKEN>',
65+
applicationId: '<DATADOG_APPLICATION_ID>',
66+
service: 'my-web-application',
67+
site: '<DATADOG_SITE>',
68+
env: 'production',
69+
})
70+
71+
// Add your probe configurations
72+
// datadogLiveDebugger.addProbe({ ... })
73+
```
74+
75+
When both are initialized, debugger snapshots will automatically include RUM context (session, view, user action).
76+
77+
## Features
78+
79+
- **Dynamic Instrumentation**: Capture function entry/exit without code changes
80+
- **Conditional Breakpoints**: Evaluate conditions before capturing snapshots
81+
- **Template Expressions**: Evaluate custom messages with runtime context
82+
- **Rate Limiting**: Built-in sampling to prevent performance impact
83+
- **Stack Traces**: Automatic stack trace capture for debugging
84+
- **Variable Capture**: Deep capture of arguments, locals, and return values
85+
86+
<!-- Note: all URLs should be absolute -->
87+
88+
[1]: https://docs.datadoghq.com/dynamic_instrumentation/

packages/debugger/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@datadog/browser-debugger",
3+
"version": "6.30.1",
4+
"license": "Apache-2.0",
5+
"main": "cjs/entries/main.js",
6+
"module": "esm/entries/main.js",
7+
"types": "cjs/entries/main.d.ts",
8+
"scripts": {
9+
"build": "node ../../scripts/build/build-package.ts --modules --bundle datadog-debugger.js",
10+
"build:bundle": "node ../../scripts/build/build-package.ts --bundle datadog-debugger.js"
11+
},
12+
"dependencies": {
13+
"@datadog/browser-core": "6.30.1"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/DataDog/browser-sdk.git",
18+
"directory": "packages/debugger"
19+
},
20+
"volta": {
21+
"extends": "../../package.json"
22+
},
23+
"publishConfig": {
24+
"access": "public"
25+
}
26+
}

0 commit comments

Comments
 (0)