1- import type { Duration } from '@datadog/js-core/time'
2- import { toServerDuration , relativeToClocks } from '@datadog/js-core/time'
31import {
2+ addTelemetryDebug ,
43 combine ,
5- generateUUID ,
64 createTaskQueue ,
5+ display ,
6+ generateUUID ,
7+ matchList ,
78 mockable ,
9+ RequestType ,
10+ ResourceType ,
811 runOnReadyState ,
9- matchList ,
1012 safeTruncate ,
11- display ,
12- addTelemetryDebug ,
13- RequestType ,
1413 setTimeout ,
1514} from '@datadog/browser-core'
16- import type { MatchHeader , RumConfiguration } from '../configuration'
17- import { RumPerformanceEntryType , createPerformanceObservable } from '../../browser/performanceObservable'
15+ import type { Duration } from '@datadog/js-core/time'
16+ import { elapsed , relativeToClocks , toServerDuration } from '@datadog/js-core/time'
17+ import { createPerformanceObservable , RumPerformanceEntryType } from '../../browser/performanceObservable'
18+ import { getNavigationEntry } from '../../browser/performanceUtils'
1819import type { RumResourceEventDomainContext } from '../../domainContext.types'
1920import type { NetworkHeaders , RawRumResourceEvent , ResourceRequest , ResourceResponse } from '../../rawRumEvent.types'
2021import { RumEventType } from '../../rawRumEvent.types'
21- import type { RawRumEventCollectedData , LifeCycle } from '../lifeCycle'
22+ import type { MatchHeader , RumConfiguration } from '../configuration'
23+ import { startEventTracker } from '../eventTracker'
24+ import { extractRegexMatch } from '../extractRegexMatch'
25+ import type { LifeCycle , RawRumEventCollectedData } from '../lifeCycle'
2226import { LifeCycleEventType } from '../lifeCycle'
2327import type { RequestCompleteEvent } from '../requestCollection'
24- import { createSpanIdentifier } from '../tracing/identifier'
2528import { getDocumentTraceId } from '../tracing/getDocumentTraceId'
26- import { getNavigationEntry } from '../../browser/performanceUtils'
27- import { startEventTracker } from '../eventTracker'
28- import { extractRegexMatch } from '../extractRegexMatch'
29+ import { createSpanIdentifier } from '../tracing/identifier'
30+ import type { WebSocketCompleteEvent } from '../webSocketCollection'
31+ import type { GraphQlMetadata } from './graphql'
32+ import { extractGraphQlMetadata , findGraphQlConfiguration } from './graphql'
33+ import { createRequestRegistry } from './requestRegistry'
34+ import type { ResourceLikeEntry } from './resourceUtils'
2935import {
36+ computeResourceEntryDeliveryType ,
3037 computeResourceEntryDetails ,
3138 computeResourceEntryDuration ,
32- computeResourceEntryType ,
33- computeResourceEntrySize ,
3439 computeResourceEntryProtocol ,
35- computeResourceEntryDeliveryType ,
40+ computeResourceEntrySize ,
41+ computeResourceEntryType ,
3642 isResourceEntryRequestType ,
3743 sanitizeIfLongDataUrl ,
3844} from './resourceUtils'
39- import type { ResourceLikeEntry } from './resourceUtils'
40- import { createRequestRegistry } from './requestRegistry'
41- import type { GraphQlMetadata } from './graphql'
42- import { extractGraphQlMetadata , findGraphQlConfiguration } from './graphql'
4345import type { ManualResourceData } from './trackManualResources'
4446import { trackManualResources } from './trackManualResources'
4547
@@ -51,6 +53,9 @@ export function startResourceCollection(lifeCycle: LifeCycle, configuration: Rum
5153 const taskQueue = mockable ( createTaskQueue ) ( )
5254 const requestRegistry = createRequestRegistry ( lifeCycle )
5355
56+ lifeCycle . subscribe ( LifeCycleEventType . WEBSOCKET_COMPLETED , ( event : WebSocketCompleteEvent ) => {
57+ handleResource ( ( ) => assembleWebSocketResource ( event ) )
58+ } )
5459 const performanceResourceSubscription = createPerformanceObservable ( {
5560 type : RumPerformanceEntryType . RESOURCE ,
5661 buffered : true ,
@@ -108,6 +113,55 @@ export function startResourceCollection(lifeCycle: LifeCycle, configuration: Rum
108113 }
109114}
110115
116+ function assembleWebSocketResource (
117+ event : WebSocketCompleteEvent
118+ ) : RawRumEventCollectedData < RawRumResourceEvent > | undefined {
119+ const duration = elapsed ( event . startClocks . timeStamp , event . endClocks . timeStamp )
120+
121+ const rawRumEvent : RawRumResourceEvent = {
122+ date : event . startClocks . timeStamp ,
123+ type : RumEventType . RESOURCE ,
124+ resource : {
125+ id : generateUUID ( ) ,
126+ type : ResourceType . WEBSOCKET ,
127+ url : event . url ,
128+ duration : toServerDuration ( duration ) ,
129+ websocket : {
130+ connection_id : event . connectionId ,
131+ handshake_succeeded : event . handshakeSucceeded ,
132+ start_time : event . startClocks . timeStamp ,
133+ end_time : event . endClocks . timeStamp ,
134+ start_view_id : event . startViewId ,
135+ end_view_id : event . endViewId ,
136+ tracking_end_reason : event . trackingEndReason ,
137+ close_code : event . closeCode ,
138+ close_reason : event . closeReason ,
139+ was_clean : event . wasClean ,
140+ messages_in : event . messagesIn ,
141+ messages_out : event . messagesOut ,
142+ time_to_first_message_in : event . firstMessageInOffset ,
143+ time_to_first_message_out : event . firstMessageOutOffset ,
144+ last_message_in_at : event . lastMessageInAt ,
145+ longest_inbound_silence : event . longestInboundSilence ,
146+ inbound_idle_duration_before_close : event . inboundIdleDurationBeforeClose ,
147+ buffered_amount_max : event . bufferedAmountMax ,
148+ protocol : event . protocol ,
149+ setup_duration : event . setupDuration ,
150+ } ,
151+ } ,
152+ _dd : {
153+ discarded : false ,
154+ } ,
155+ }
156+
157+ return {
158+ startClocks : event . startClocks ,
159+ duration,
160+ rawRumEvent,
161+ domainContext : { } ,
162+ }
163+ }
164+
111165function assembleResource (
112166 entry : ResourceLikeEntry ,
113167 request : RequestCompleteEvent | undefined ,
0 commit comments