1- import type { ClocksState , Context , ResourceType } from '@datadog/browser-core'
1+ import type { Context , ResourceType } from '@datadog/browser-core'
22import { clocksNow , elapsed , ResourceType as ResourceTypeEnum , toServerDuration } from '@datadog/browser-core'
33import type { RawRumResourceEvent } from '../../rawRumEvent.types'
44import { RumEventType } from '../../rawRumEvent.types'
@@ -42,6 +42,11 @@ export interface ResourceStopOptions {
4242 */
4343 statusCode ?: number
4444
45+ /**
46+ * Resource size in bytes
47+ */
48+ size ?: number
49+
4550 /**
4651 * Resource context
4752 */
@@ -61,38 +66,6 @@ export interface ManualResourceData {
6166}
6267
6368export function trackManualResources ( lifeCycle : LifeCycle , resourceTracker : EventTracker < ManualResourceData > ) {
64- function emitResource (
65- id : string ,
66- startClocks : ClocksState ,
67- data : ManualResourceData ,
68- statusCode ?: number ,
69- endClocks ?: ClocksState
70- ) {
71- const duration = endClocks ? elapsed ( startClocks . relative , endClocks . relative ) : undefined
72-
73- const rawRumEvent : RawRumResourceEvent = {
74- date : startClocks . timeStamp ,
75- type : RumEventType . RESOURCE ,
76- resource : {
77- id,
78- type : data . type || ResourceTypeEnum . OTHER ,
79- url : sanitizeIfLongDataUrl ( data . url ) ,
80- duration : duration !== undefined ? toServerDuration ( duration ) : undefined ,
81- method : data . method ,
82- status_code : statusCode ,
83- } ,
84- _dd : { } ,
85- context : data . context ,
86- }
87-
88- lifeCycle . notify ( LifeCycleEventType . RAW_RUM_EVENT_COLLECTED , {
89- rawRumEvent,
90- startClocks,
91- duration,
92- domainContext : { isManual : true as const } ,
93- } )
94- }
95-
9669 function startManualResource ( url : string , options : ResourceOptions = { } , startClocks = clocksNow ( ) ) {
9770 const lookupKey = options . resourceKey ?? url
9871
@@ -114,7 +87,30 @@ export function trackManualResources(lifeCycle: LifeCycle, resourceTracker: Even
11487 return
11588 }
11689
117- emitResource ( stopped . id , stopped . startClocks , stopped , options . statusCode , stopClocks )
90+ const duration = elapsed ( stopped . startClocks . relative , stopClocks . relative )
91+
92+ const rawRumEvent : RawRumResourceEvent = {
93+ date : stopped . startClocks . timeStamp ,
94+ type : RumEventType . RESOURCE ,
95+ resource : {
96+ id : stopped . id ,
97+ type : stopped . type || ResourceTypeEnum . OTHER ,
98+ url : sanitizeIfLongDataUrl ( stopped . url ) ,
99+ duration : toServerDuration ( duration ) ,
100+ method : stopped . method ,
101+ status_code : options . statusCode ,
102+ size : options . size ,
103+ } ,
104+ _dd : { } ,
105+ context : stopped . context ,
106+ }
107+
108+ lifeCycle . notify ( LifeCycleEventType . RAW_RUM_EVENT_COLLECTED , {
109+ rawRumEvent,
110+ startClocks : stopped . startClocks ,
111+ duration,
112+ domainContext : { isManual : true } ,
113+ } )
118114 }
119115
120116 return {
0 commit comments