-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathmain.ts
More file actions
139 lines (124 loc) · 3.56 KB
/
main.ts
File metadata and controls
139 lines (124 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Datadog Browser Live Debugger SDK
* Provides live debugger capabilities for browser applications.
*
* @packageDocumentation
* @see [Live Debugger Documentation](https://docs.datadoghq.com/tracing/live_debugger/)
*/
import { defineGlobal, getGlobalObject, makePublicApi } from '@datadog/browser-core'
import type { PublicApi, Site } from '@datadog/browser-core'
import { onEntry, onReturn, onThrow, initDebuggerTransport } from '../domain/api'
import { startDeliveryApiPolling } from '../domain/deliveryApi'
import { getProbes } from '../domain/probes'
import { startDebuggerBatch } from '../transport/startDebuggerBatch'
/**
* Configuration options for initializing the Live Debugger SDK
*/
export interface DebuggerInitConfiguration {
/**
* The RUM application ID.
*
* @category Delivery API
*/
applicationId: string
/**
* The client token for Datadog. Required for authenticating your application with Datadog.
*
* @category Authentication
*/
clientToken: string
/**
* The Datadog site to send data to
*
* @category Transport
* @defaultValue 'datadoghq.com'
*/
site?: Site
/**
* The service name for your application
*
* @category Data Collection
*/
service: string
/**
* The application's environment (e.g., prod, staging)
*
* @category Data Collection
*/
env?: string
/**
* The application's version
*
* @category Data Collection
*/
version?: string
/**
* Polling interval in milliseconds for fetching probe updates
*
* @category Delivery API
* @defaultValue 60000
*/
pollInterval?: number
}
/**
* Public API for the Live Debugger browser SDK.
*
* @category Main
*/
export interface DebuggerPublicApi extends PublicApi {
/**
* Initialize the Live Debugger SDK
*
* @category Init
* @param initConfiguration - Configuration options
* @example
* ```ts
* datadogDebugger.init({
* applicationId: '<DATADOG_APPLICATION_ID>',
* clientToken: '<DATADOG_CLIENT_TOKEN>',
* service: 'my-app',
* site: 'datadoghq.com',
* env: 'production'
* version: 'my-deployed-build-version',
* })
* ```
*/
init: (initConfiguration: DebuggerInitConfiguration) => void
}
/**
* Create the public API for the Live Debugger
*/
function makeDebuggerPublicApi(): DebuggerPublicApi {
return makePublicApi<DebuggerPublicApi>({
init: (initConfiguration: DebuggerInitConfiguration) => {
// Initialize debugger's own transport
const batch = startDebuggerBatch(initConfiguration)
initDebuggerTransport(initConfiguration, batch)
// Expose internal hooks on globalThis for instrumented code
if (typeof globalThis !== 'undefined') {
;(globalThis as any).$dd_entry = onEntry
;(globalThis as any).$dd_return = onReturn
;(globalThis as any).$dd_throw = onThrow
;(globalThis as any).$dd_probes = getProbes
}
startDeliveryApiPolling({
applicationId: initConfiguration.applicationId,
env: initConfiguration.env,
version: initConfiguration.version,
pollInterval: initConfiguration.pollInterval,
})
},
})
}
/**
* The global Live Debugger instance. Use this to call Live Debugger methods.
*
* @category Main
* @see {@link DebuggerPublicApi}
* @see [Live Debugger Documentation](https://docs.datadoghq.com/tracing/live_debugger/)
*/
export const datadogDebugger = makeDebuggerPublicApi()
export interface BrowserWindow extends Window {
DD_DEBUGGER?: DebuggerPublicApi
}
defineGlobal(getGlobalObject<BrowserWindow>(), 'DD_DEBUGGER', datadogDebugger)