@cloudcare/browser-rum 3.3.5 → 3.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/perStartRum.js +42 -6
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +35 -10
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/rum.js +8 -0
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +36 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/domain/configuration.js +7 -0
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/contexts/urlContexts.js +11 -2
- package/cjs/domain/contexts/urlContexts.js.map +1 -1
- package/cjs/domain/contexts/viewContexts.js +2 -2
- package/cjs/domain/contexts/viewContexts.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/plugins.js +67 -0
- package/cjs/domain/plugins.js.map +1 -0
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +56 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js +196 -0
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +23 -3
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/perStartRum.js +42 -6
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +35 -10
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/rum.js +8 -0
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rumPublicApi.js +36 -3
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/domain/configuration.js +8 -1
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +12 -3
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -2
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/plugins.js +59 -0
- package/esm/domain/plugins.js.map +1 -0
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +55 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js +189 -0
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumSessionManager.js +24 -4
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/perStartRum.js +47 -7
- package/src/boot/recorderApi.js +36 -12
- package/src/boot/rum.js +11 -0
- package/src/boot/rumPublicApi.js +38 -3
- package/src/domain/configuration.js +13 -1
- package/src/domain/contexts/urlContexts.js +17 -3
- package/src/domain/contexts/viewContexts.js +2 -2
- package/src/domain/plugins.js +94 -0
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +70 -0
- package/src/domain/rumEventsCollection/resource/webSocketCollection.js +271 -0
- package/src/domain/rumEventsCollection/view/trackLoadingTime.js +12 -3
- package/src/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/src/domain/rumSessionManager.js +33 -2
- package/types/index.d.ts +85 -6
|
@@ -55,6 +55,19 @@ export function startResourceCollection(
|
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
var requestResourceEntryMatcher = createRequestResourceEntryMatcher()
|
|
58
|
+
var webSocketSubscription = lifeCycle.subscribe(
|
|
59
|
+
LifeCycleEventType.WEBSOCKET_COMPLETED,
|
|
60
|
+
function (event) {
|
|
61
|
+
try {
|
|
62
|
+
lifeCycle.notify(
|
|
63
|
+
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
64
|
+
processWebSocket(event)
|
|
65
|
+
)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
addTelemetryError(error)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
)
|
|
58
71
|
lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
|
|
59
72
|
handleResource(function () {
|
|
60
73
|
return processRequest(request, pageStateHistory, requestResourceEntryMatcher)
|
|
@@ -113,6 +126,7 @@ export function startResourceCollection(
|
|
|
113
126
|
}
|
|
114
127
|
return {
|
|
115
128
|
stop: function () {
|
|
129
|
+
webSocketSubscription.unsubscribe()
|
|
116
130
|
performanceResourceSubscription.unsubscribe()
|
|
117
131
|
},
|
|
118
132
|
addResource: (resource, savedCommonContext) => {
|
|
@@ -126,6 +140,62 @@ export function startResourceCollection(
|
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
142
|
|
|
143
|
+
export function processWebSocket(event) {
|
|
144
|
+
var duration = event.endClocks.timeStamp - event.startClocks.timeStamp
|
|
145
|
+
var urlObj = urlParse(event.url).getParse()
|
|
146
|
+
return {
|
|
147
|
+
startTime: event.startClocks.relative,
|
|
148
|
+
rawRumEvent: {
|
|
149
|
+
date: event.startClocks.timeStamp,
|
|
150
|
+
type: RumEventType.RESOURCE,
|
|
151
|
+
resource: {
|
|
152
|
+
id: UUID(),
|
|
153
|
+
type: ResourceType.WEBSOCKET,
|
|
154
|
+
url: event.url,
|
|
155
|
+
urlHost: urlObj.Host,
|
|
156
|
+
urlPath: urlObj.Path,
|
|
157
|
+
urlPathGroup: replaceNumberCharByPath(urlObj.Path),
|
|
158
|
+
urlQuery: getQueryParamsFromUrl(event.url),
|
|
159
|
+
duration: toServerDuration(duration),
|
|
160
|
+
websocket: {
|
|
161
|
+
connectionId: event.connectionId,
|
|
162
|
+
handshakeSucceeded: event.handshakeSucceeded,
|
|
163
|
+
startTime: event.startClocks.timeStamp,
|
|
164
|
+
endTime: event.endClocks.timeStamp,
|
|
165
|
+
startViewId: event.startViewId,
|
|
166
|
+
endViewId: event.endViewId,
|
|
167
|
+
trackingEndReason: event.trackingEndReason,
|
|
168
|
+
closeCode: event.closeCode,
|
|
169
|
+
closeReason: event.closeReason,
|
|
170
|
+
wasClean: event.wasClean,
|
|
171
|
+
messagesIn: event.messagesIn,
|
|
172
|
+
messagesOut: event.messagesOut,
|
|
173
|
+
timeToFirstMessageIn: toServerDuration(
|
|
174
|
+
event.firstMessageInOffset
|
|
175
|
+
),
|
|
176
|
+
timeToFirstMessageOut: toServerDuration(
|
|
177
|
+
event.firstMessageOutOffset
|
|
178
|
+
),
|
|
179
|
+
lastMessageInAt: event.lastMessageInAt,
|
|
180
|
+
longestInboundSilence: toServerDuration(
|
|
181
|
+
event.longestInboundSilence
|
|
182
|
+
),
|
|
183
|
+
inboundIdleDurationBeforeClose: toServerDuration(
|
|
184
|
+
event.inboundIdleDurationBeforeClose
|
|
185
|
+
),
|
|
186
|
+
bufferedAmountMax: event.bufferedAmountMax,
|
|
187
|
+
protocol: event.protocol,
|
|
188
|
+
setupDuration: toServerDuration(event.setupDuration)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
domainContext: {
|
|
193
|
+
isWebSocket: true,
|
|
194
|
+
webSocket: event.webSocket
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
129
199
|
function processRequest(request, pageStateHistory, requestResourceEntryMatcher) {
|
|
130
200
|
var matchingTiming = requestResourceEntryMatcher.matchRequestResourceEntry(request)
|
|
131
201
|
var startClocks = matchingTiming
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clocksNow,
|
|
3
|
+
elapsed,
|
|
4
|
+
initWebSocketObservable,
|
|
5
|
+
LifeCycleEventType,
|
|
6
|
+
PageExitReason,
|
|
7
|
+
UUID
|
|
8
|
+
} from '@cloudcare/browser-core'
|
|
9
|
+
|
|
10
|
+
export function startWebSocketCollection(
|
|
11
|
+
lifeCycle,
|
|
12
|
+
viewContexts,
|
|
13
|
+
webSocketContextObservable
|
|
14
|
+
) {
|
|
15
|
+
var tracker = trackWebSocket(
|
|
16
|
+
lifeCycle,
|
|
17
|
+
webSocketContextObservable || initWebSocketObservable(),
|
|
18
|
+
viewContexts
|
|
19
|
+
)
|
|
20
|
+
var sessionExpiredSubscription = lifeCycle.subscribe(
|
|
21
|
+
LifeCycleEventType.SESSION_EXPIRED,
|
|
22
|
+
function () {
|
|
23
|
+
tracker.flushOpenConnections('session_end', true)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
var sessionRenewedSubscription = lifeCycle.subscribe(
|
|
27
|
+
LifeCycleEventType.SESSION_RENEWED,
|
|
28
|
+
function () {
|
|
29
|
+
tracker.resumeOpenConnections()
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
var pageExitSubscription = lifeCycle.subscribe(
|
|
33
|
+
LifeCycleEventType.PAGE_EXITED,
|
|
34
|
+
function (event) {
|
|
35
|
+
if (event.reason === PageExitReason.UNLOADING) {
|
|
36
|
+
tracker.flushOpenConnections('page_exit')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
stop: function () {
|
|
43
|
+
sessionExpiredSubscription.unsubscribe()
|
|
44
|
+
sessionRenewedSubscription.unsubscribe()
|
|
45
|
+
pageExitSubscription.unsubscribe()
|
|
46
|
+
tracker.flushOpenConnections('session_end')
|
|
47
|
+
tracker.stop()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function trackWebSocket(
|
|
53
|
+
lifeCycle,
|
|
54
|
+
webSocketContextObservable,
|
|
55
|
+
viewContexts
|
|
56
|
+
) {
|
|
57
|
+
var registry = new Map()
|
|
58
|
+
var isWaitingForSessionRenewal = false
|
|
59
|
+
var subscription = webSocketContextObservable.subscribe(function (context) {
|
|
60
|
+
var connection = registry.get(context.instance)
|
|
61
|
+
|
|
62
|
+
if (context.state === 'connecting') {
|
|
63
|
+
connection = createConnection(
|
|
64
|
+
context.instance,
|
|
65
|
+
context.url,
|
|
66
|
+
context.startClocks,
|
|
67
|
+
viewContexts
|
|
68
|
+
)
|
|
69
|
+
connection.pendingSessionRenewal = isWaitingForSessionRenewal
|
|
70
|
+
registry.set(context.instance, connection)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!connection) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (connection.pendingSessionRenewal) {
|
|
79
|
+
if (context.state === 'open') {
|
|
80
|
+
connection.openClocks = context.openClocks
|
|
81
|
+
connection.protocol = context.protocol
|
|
82
|
+
} else if (context.state === 'closed') {
|
|
83
|
+
registry.delete(context.instance)
|
|
84
|
+
}
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (context.state === 'open') {
|
|
89
|
+
connection.openClocks = context.openClocks
|
|
90
|
+
connection.protocol = context.protocol
|
|
91
|
+
connection.setupDuration = elapsed(
|
|
92
|
+
connection.startClocks.timeStamp,
|
|
93
|
+
context.openClocks.timeStamp
|
|
94
|
+
)
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (context.state === 'message-in') {
|
|
99
|
+
connection.messagesIn.count += 1
|
|
100
|
+
connection.messagesIn.size += context.size
|
|
101
|
+
recordMessageTiming(connection, context.at, 'in')
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (context.state === 'message-out') {
|
|
106
|
+
connection.messagesOut.count += 1
|
|
107
|
+
connection.messagesOut.size += context.size
|
|
108
|
+
connection.bufferedAmountMax = Math.max(
|
|
109
|
+
connection.bufferedAmountMax,
|
|
110
|
+
context.bufferedAmountPreSend
|
|
111
|
+
)
|
|
112
|
+
recordMessageTiming(connection, context.at, 'out')
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (context.state === 'closed') {
|
|
117
|
+
registry.delete(context.instance)
|
|
118
|
+
lifeCycle.notify(
|
|
119
|
+
LifeCycleEventType.WEBSOCKET_COMPLETED,
|
|
120
|
+
buildCompletedEvent(
|
|
121
|
+
connection,
|
|
122
|
+
context,
|
|
123
|
+
'close_event',
|
|
124
|
+
viewContexts
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
flushOpenConnections: function (reason, preserveConnections) {
|
|
132
|
+
var at = clocksNow()
|
|
133
|
+
isWaitingForSessionRenewal = !!preserveConnections
|
|
134
|
+
registry.forEach(function (connection) {
|
|
135
|
+
if (connection.pendingSessionRenewal) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
lifeCycle.notify(
|
|
139
|
+
LifeCycleEventType.WEBSOCKET_COMPLETED,
|
|
140
|
+
buildCompletedEvent(connection, { at: at }, reason, viewContexts)
|
|
141
|
+
)
|
|
142
|
+
if (preserveConnections) {
|
|
143
|
+
connection.pendingSessionRenewal = true
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
if (!preserveConnections) {
|
|
147
|
+
registry.clear()
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
resumeOpenConnections: function () {
|
|
151
|
+
var at = clocksNow()
|
|
152
|
+
isWaitingForSessionRenewal = false
|
|
153
|
+
registry.forEach(function (connection) {
|
|
154
|
+
if (connection.pendingSessionRenewal) {
|
|
155
|
+
resetConnectionSegment(connection, at, viewContexts)
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
},
|
|
159
|
+
stop: function () {
|
|
160
|
+
subscription.unsubscribe()
|
|
161
|
+
registry.clear()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function createConnection(webSocket, url, startClocks, viewContexts) {
|
|
167
|
+
var connection = {
|
|
168
|
+
webSocket: webSocket,
|
|
169
|
+
connectionId: UUID(),
|
|
170
|
+
url: url
|
|
171
|
+
}
|
|
172
|
+
resetConnectionSegment(connection, startClocks, viewContexts)
|
|
173
|
+
return connection
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function resetConnectionSegment(connection, startClocks, viewContexts) {
|
|
177
|
+
var wasOpen = connection.openClocks !== undefined
|
|
178
|
+
var startView = viewContexts.findView(startClocks.relative)
|
|
179
|
+
|
|
180
|
+
connection.startClocks = startClocks
|
|
181
|
+
connection.startViewId = startView && startView.id
|
|
182
|
+
connection.messagesIn = { count: 0, size: 0 }
|
|
183
|
+
connection.messagesOut = { count: 0, size: 0 }
|
|
184
|
+
connection.longestInboundSilence = 0
|
|
185
|
+
connection.bufferedAmountMax = 0
|
|
186
|
+
connection.pendingSessionRenewal = false
|
|
187
|
+
|
|
188
|
+
delete connection.firstMessageInOffset
|
|
189
|
+
delete connection.firstMessageOutOffset
|
|
190
|
+
delete connection.lastMessageInAt
|
|
191
|
+
|
|
192
|
+
if (wasOpen) {
|
|
193
|
+
connection.openClocks = startClocks
|
|
194
|
+
connection.setupDuration = 0
|
|
195
|
+
} else {
|
|
196
|
+
delete connection.openClocks
|
|
197
|
+
delete connection.setupDuration
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function recordMessageTiming(connection, at, direction) {
|
|
202
|
+
if (!connection.openClocks) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
var offset = elapsed(connection.openClocks.timeStamp, at.timeStamp)
|
|
207
|
+
if (direction === 'in' && connection.firstMessageInOffset === undefined) {
|
|
208
|
+
connection.firstMessageInOffset = offset
|
|
209
|
+
} else if (
|
|
210
|
+
direction === 'out' &&
|
|
211
|
+
connection.firstMessageOutOffset === undefined
|
|
212
|
+
) {
|
|
213
|
+
connection.firstMessageOutOffset = offset
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (direction === 'in') {
|
|
217
|
+
if (connection.lastMessageInAt !== undefined) {
|
|
218
|
+
connection.longestInboundSilence = Math.max(
|
|
219
|
+
connection.longestInboundSilence,
|
|
220
|
+
elapsed(connection.lastMessageInAt, at.timeStamp)
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
connection.lastMessageInAt = at.timeStamp
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function buildCompletedEvent(
|
|
228
|
+
connection,
|
|
229
|
+
endInfo,
|
|
230
|
+
trackingEndReason,
|
|
231
|
+
viewContexts
|
|
232
|
+
) {
|
|
233
|
+
var endClocks = endInfo.at
|
|
234
|
+
var endView = viewContexts.findView(
|
|
235
|
+
endClocks.relative,
|
|
236
|
+
trackingEndReason === 'session_end' || trackingEndReason === 'page_exit'
|
|
237
|
+
? { returnInactive: true }
|
|
238
|
+
: undefined
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
webSocket: connection.webSocket,
|
|
243
|
+
connectionId: connection.connectionId,
|
|
244
|
+
url: connection.url,
|
|
245
|
+
protocol: connection.protocol,
|
|
246
|
+
startClocks: connection.startClocks,
|
|
247
|
+
endClocks: endClocks,
|
|
248
|
+
startViewId: connection.startViewId,
|
|
249
|
+
endViewId: endView && endView.id,
|
|
250
|
+
messagesIn: connection.messagesIn,
|
|
251
|
+
messagesOut: connection.messagesOut,
|
|
252
|
+
firstMessageInOffset: connection.firstMessageInOffset,
|
|
253
|
+
firstMessageOutOffset: connection.firstMessageOutOffset,
|
|
254
|
+
lastMessageInAt: connection.lastMessageInAt,
|
|
255
|
+
longestInboundSilence: connection.longestInboundSilence,
|
|
256
|
+
bufferedAmountMax: connection.bufferedAmountMax,
|
|
257
|
+
inboundIdleDurationBeforeClose:
|
|
258
|
+
connection.lastMessageInAt === undefined
|
|
259
|
+
? undefined
|
|
260
|
+
: elapsed(connection.lastMessageInAt, endClocks.timeStamp),
|
|
261
|
+
closeCode: endInfo.code,
|
|
262
|
+
closeReason: endInfo.reason,
|
|
263
|
+
wasClean: endInfo.wasClean,
|
|
264
|
+
handshakeSucceeded: connection.openClocks !== undefined,
|
|
265
|
+
trackingEndReason: trackingEndReason,
|
|
266
|
+
setupDuration:
|
|
267
|
+
connection.setupDuration === undefined
|
|
268
|
+
? elapsed(connection.startClocks.timeStamp, endClocks.timeStamp)
|
|
269
|
+
: connection.setupDuration
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -19,10 +19,19 @@ export function trackLoadingTime(
|
|
|
19
19
|
!isWaitingForLoadEvent &&
|
|
20
20
|
loadingTimeCandidates.length > 0
|
|
21
21
|
) {
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var firstHiddenTime = firstHidden.getTimeStamp() - viewStart.relative
|
|
23
|
+
var visibleLoadingTimeCandidates = loadingTimeCandidates.filter(function (
|
|
24
|
+
loadingTime
|
|
25
|
+
) {
|
|
26
|
+
return loadingTime < firstHiddenTime
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
if (visibleLoadingTimeCandidates.length === 0) {
|
|
30
|
+
return
|
|
25
31
|
}
|
|
32
|
+
|
|
33
|
+
var loadingTime = Math.max.apply(Math, visibleLoadingTimeCandidates)
|
|
34
|
+
callback(loadingTime)
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -178,7 +178,8 @@ function newView(
|
|
|
178
178
|
name: name,
|
|
179
179
|
startClocks: startClocks,
|
|
180
180
|
service: service,
|
|
181
|
-
version: version
|
|
181
|
+
version: version,
|
|
182
|
+
url: viewOptions && viewOptions.url
|
|
182
183
|
}
|
|
183
184
|
lifeCycle.notify(LifeCycleEventType.BEFORE_VIEW_CREATED, viewCreatedEvent)
|
|
184
185
|
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, viewCreatedEvent)
|
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
timeStampNow,
|
|
8
8
|
bridgeSupports,
|
|
9
9
|
BridgeCapability,
|
|
10
|
-
SESSION_NOT_TRACKED
|
|
10
|
+
SESSION_NOT_TRACKED,
|
|
11
|
+
display,
|
|
12
|
+
isPercentage
|
|
11
13
|
} from '@cloudcare/browser-core'
|
|
12
14
|
|
|
13
15
|
export var RUM_SESSION_KEY = 'rum'
|
|
@@ -60,6 +62,7 @@ export function startRumSessionManager(configuration, lifeCycle) {
|
|
|
60
62
|
if (!previousState.forcedSession && newState.forcedSession) {
|
|
61
63
|
const sessionEntity = sessionManager.findSession()
|
|
62
64
|
if (sessionEntity) {
|
|
65
|
+
sessionEntity.id = newState.id
|
|
63
66
|
sessionEntity.isSessionForced = true
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -116,12 +119,18 @@ export function startRumSessionManager(configuration, lifeCycle) {
|
|
|
116
119
|
},
|
|
117
120
|
expire: sessionManager.expire,
|
|
118
121
|
keepSessionAlive: sessionManager.expandOrRenewSession,
|
|
122
|
+
startSession: function (options) {
|
|
123
|
+
if (!applyStartSessionOptions(configuration, options)) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
sessionManager.renewSession()
|
|
127
|
+
},
|
|
119
128
|
expireObservable: sessionManager.expireObservable,
|
|
120
129
|
sessionStateUpdateObservable: sessionManager.sessionStateUpdateObservable,
|
|
121
130
|
setErrorForSession: () =>
|
|
122
131
|
sessionManager.updateSessionState({ hasError: '1', ets: timeStampNow() }),
|
|
123
132
|
setForcedSession: () => {
|
|
124
|
-
sessionManager.
|
|
133
|
+
sessionManager.forceSession()
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
}
|
|
@@ -148,6 +157,7 @@ export function startRumSessionManagerStub() {
|
|
|
148
157
|
},
|
|
149
158
|
expire: noop,
|
|
150
159
|
keepSessionAlive: noop,
|
|
160
|
+
startSession: noop,
|
|
151
161
|
expireObservable: new Observable(),
|
|
152
162
|
setErrorForSession: function () {
|
|
153
163
|
session.sessionErrorTimestamp = timeStampNow()
|
|
@@ -159,6 +169,27 @@ export function startRumSessionManagerStub() {
|
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
|
|
172
|
+
function applyStartSessionOptions(configuration, options) {
|
|
173
|
+
if (options === undefined) {
|
|
174
|
+
return true
|
|
175
|
+
}
|
|
176
|
+
if (
|
|
177
|
+
!options ||
|
|
178
|
+
typeof options !== 'object' ||
|
|
179
|
+
(options.sessionSampleRate !== undefined &&
|
|
180
|
+
!isPercentage(options.sessionSampleRate))
|
|
181
|
+
) {
|
|
182
|
+
display.error(
|
|
183
|
+
'startSession options should contain a sessionSampleRate between 0 and 100'
|
|
184
|
+
)
|
|
185
|
+
return false
|
|
186
|
+
}
|
|
187
|
+
if (options.sessionSampleRate !== undefined) {
|
|
188
|
+
configuration.sessionSampleRate = options.sessionSampleRate
|
|
189
|
+
}
|
|
190
|
+
return true
|
|
191
|
+
}
|
|
192
|
+
|
|
162
193
|
function computeSessionState(configuration, rawTrackingType) {
|
|
163
194
|
const {
|
|
164
195
|
sessionSampleRate,
|
package/types/index.d.ts
CHANGED
|
@@ -28,6 +28,22 @@ export interface InternalContext {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export interface StartSessionOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Overrides the runtime RUM session sample rate for the new session and
|
|
34
|
+
* subsequent automatic session renewals.
|
|
35
|
+
*/
|
|
36
|
+
sessionSampleRate?: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface StartSessionReplayRecordingOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Forces the current session to be tracked, assigns a session ID when
|
|
42
|
+
* necessary, and enables Session Replay recording.
|
|
43
|
+
*/
|
|
44
|
+
force?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
export interface CanvasSnapshotResult {
|
|
32
48
|
ok: boolean
|
|
33
49
|
reason?: string
|
|
@@ -141,10 +157,71 @@ export interface ResourceTrackerSnapshot {
|
|
|
141
157
|
rawRumEvent?: object | undefined
|
|
142
158
|
}
|
|
143
159
|
|
|
144
|
-
export
|
|
145
|
-
|
|
146
|
-
|
|
160
|
+
export interface ViewOptions {
|
|
161
|
+
name?: string | undefined
|
|
162
|
+
service?: string | undefined
|
|
163
|
+
version?: string | undefined
|
|
164
|
+
url?: string | undefined
|
|
165
|
+
context?: Context | undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface RumPluginApi {
|
|
169
|
+
startView: (options?: string | ViewOptions) => void
|
|
170
|
+
setViewName: (name: string) => void
|
|
171
|
+
setViewContext: (context: Context) => void
|
|
172
|
+
setViewContextProperty: (key: string, value: any) => void
|
|
173
|
+
addAction: (name: string, context?: object | undefined) => void
|
|
174
|
+
addTypeAction: (
|
|
175
|
+
name: string,
|
|
176
|
+
type?: string,
|
|
177
|
+
context?: object | undefined
|
|
147
178
|
) => void
|
|
179
|
+
addError: (error: unknown, context?: object | undefined) => void
|
|
180
|
+
getInternalContext: (
|
|
181
|
+
startTime?: number | undefined
|
|
182
|
+
) => InternalContext | undefined
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface RumPluginContext {
|
|
186
|
+
addError: (error: RumPluginError) => void
|
|
187
|
+
publicApi: RumPluginApi
|
|
188
|
+
rum: RumPluginApi
|
|
189
|
+
initConfiguration: RumPluginInitConfiguration
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface RumPluginStartContext {
|
|
193
|
+
addError: (error: RumPluginError) => void
|
|
194
|
+
publicApi: RumPluginApi
|
|
195
|
+
rum: RumPluginApi
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface RumPluginError {
|
|
199
|
+
error: unknown
|
|
200
|
+
handlingStack?: string | undefined
|
|
201
|
+
context?: Context | undefined
|
|
202
|
+
startClocks: {
|
|
203
|
+
relative: number
|
|
204
|
+
timeStamp: number
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface RumPlugin {
|
|
209
|
+
name: string
|
|
210
|
+
onInit?: (context: RumPluginContext) => void
|
|
211
|
+
onRumStart?: (context: RumPluginStartContext) => void
|
|
212
|
+
getConfigurationTelemetry?: () => Record<string, unknown>
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export type RumPluginInitConfiguration = (
|
|
216
|
+
| RumInitConfiguration
|
|
217
|
+
| RumSiteInitConfiguration
|
|
218
|
+
) & {
|
|
219
|
+
plugins?: RumPlugin[] | undefined
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export declare const datafluxRum: {
|
|
223
|
+
init: (initConfiguration: RumPluginInitConfiguration) => void
|
|
224
|
+
startView: (options?: string | ViewOptions) => void
|
|
148
225
|
setViewName: (name: string) => void
|
|
149
226
|
setViewContext: (context: Context) => void
|
|
150
227
|
setViewContextProperty: (key: string, value: any) => void
|
|
@@ -160,8 +237,7 @@ export declare const datafluxRum: {
|
|
|
160
237
|
startTime?: number | undefined
|
|
161
238
|
) => InternalContext | undefined
|
|
162
239
|
getInitConfiguration: () =>
|
|
163
|
-
|
|
|
164
|
-
| RumSiteInitConfiguration
|
|
240
|
+
| RumPluginInitConfiguration
|
|
165
241
|
| undefined
|
|
166
242
|
getRemoteConfiguration: (
|
|
167
243
|
callback: (remoteConfiguration: object) => void
|
|
@@ -181,8 +257,11 @@ export declare const datafluxRum: {
|
|
|
181
257
|
removeUserProperty: (key: any) => void
|
|
182
258
|
clearUser: () => void
|
|
183
259
|
stopSession: () => void
|
|
260
|
+
startSession: (options?: StartSessionOptions) => void
|
|
184
261
|
setForcedSession: () => void
|
|
185
|
-
startSessionReplayRecording: (
|
|
262
|
+
startSessionReplayRecording: (
|
|
263
|
+
options?: StartSessionReplayRecordingOptions
|
|
264
|
+
) => void
|
|
186
265
|
isRecording: () => boolean
|
|
187
266
|
stopSessionReplayRecording: () => void
|
|
188
267
|
takeSubsequentFullSnapshot: () => void
|