@@ -18,6 +18,10 @@ import { ensureStudioBundle } from './ensure_studio_bundle'
1818import chokidar from 'chokidar'
1919import { readFile } from 'fs/promises'
2020import { getCloudMetadata } from '../get_cloud_metadata'
21+ import { initializeTelemetryReporter , reportTelemetry } from './telemetry/TelemetryReporter'
22+ import { telemetryManager } from './telemetry/TelemetryManager'
23+ import { BUNDLE_LIFECYCLE_MARK_NAMES , BUNDLE_LIFECYCLE_TELEMETRY_GROUP_NAMES } from './telemetry/constants/bundle-lifecycle'
24+ import { INITIALIZATION_TELEMETRY_GROUP_NAMES } from './telemetry/constants/initialization'
2125
2226const debug = Debug ( 'cypress:server:studio-lifecycle-manager' )
2327const routes = require ( '../routes' )
@@ -98,6 +102,11 @@ export class StudioLifecycleManager {
98102 // Clean up any registered listeners
99103 this . listeners = [ ]
100104
105+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . BUNDLE_LIFECYCLE_END )
106+ reportTelemetry ( BUNDLE_LIFECYCLE_TELEMETRY_GROUP_NAMES . COMPLETE_BUNDLE_LIFECYCLE , {
107+ success : false ,
108+ } )
109+
101110 return null
102111 } )
103112
@@ -112,6 +121,12 @@ export class StudioLifecycleManager {
112121 }
113122
114123 isStudioReady ( ) : boolean {
124+ if ( ! this . studioManager ) {
125+ telemetryManager . addGroupMetadata ( INITIALIZATION_TELEMETRY_GROUP_NAMES . INITIALIZE_STUDIO , {
126+ studioRequestedBeforeReady : true ,
127+ } )
128+ }
129+
115130 return ! ! this . studioManager
116131 }
117132
@@ -143,10 +158,21 @@ export class StudioLifecycleManager {
143158 let studioPath : string
144159 let studioHash : string
145160
161+ initializeTelemetryReporter ( {
162+ projectSlug : projectId ,
163+ cloudDataSource,
164+ } )
165+
166+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . BUNDLE_LIFECYCLE_START )
167+
168+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . POST_STUDIO_SESSION_START )
146169 const studioSession = await postStudioSession ( {
147170 projectId,
148171 } )
149172
173+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . POST_STUDIO_SESSION_END )
174+
175+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . ENSURE_STUDIO_BUNDLE_START )
150176 if ( ! process . env . CYPRESS_LOCAL_STUDIO_PATH ) {
151177 // The studio hash is the last part of the studio URL, after the last slash and before the extension
152178 studioHash = studioSession . studioUrl . split ( '/' ) . pop ( ) ?. split ( '.' ) [ 0 ]
@@ -170,11 +196,15 @@ export class StudioLifecycleManager {
170196 studioHash = 'local'
171197 }
172198
199+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . ENSURE_STUDIO_BUNDLE_END )
200+
173201 const serverFilePath = path . join ( studioPath , 'server' , 'index.js' )
174202
175203 const script = await readFile ( serverFilePath , 'utf8' )
176204 const studioManager = new StudioManager ( )
177205
206+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_MANAGER_SETUP_START )
207+
178208 const { cloudUrl, cloudHeaders } = await getCloudMetadata ( cloudDataSource )
179209
180210 await studioManager . setup ( {
@@ -192,11 +222,18 @@ export class StudioLifecycleManager {
192222 shouldEnableStudio : this . cloudStudioRequested ,
193223 } )
194224
225+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_MANAGER_SETUP_END )
226+
195227 if ( studioManager . status === 'ENABLED' ) {
196228 debug ( 'Cloud studio is enabled - setting up protocol' )
197229 const protocolManager = new ProtocolManager ( )
230+
231+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_PROTOCOL_GET_START )
198232 const script = await api . getCaptureProtocolScript ( studioSession . protocolUrl )
199233
234+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_PROTOCOL_GET_END )
235+
236+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_PROTOCOL_PREPARE_START )
200237 await protocolManager . prepareProtocol ( script , {
201238 runId : 'studio' ,
202239 projectId : cfg . projectId ,
@@ -212,6 +249,8 @@ export class StudioLifecycleManager {
212249 mode : 'studio' ,
213250 } )
214251
252+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . STUDIO_PROTOCOL_PREPARE_END )
253+
215254 studioManager . protocolManager = protocolManager
216255 } else {
217256 debug ( 'Cloud studio is not enabled - skipping protocol setup' )
@@ -222,6 +261,11 @@ export class StudioLifecycleManager {
222261 this . callRegisteredListeners ( )
223262 this . updateStatus ( studioManager . status )
224263
264+ telemetryManager . mark ( BUNDLE_LIFECYCLE_MARK_NAMES . BUNDLE_LIFECYCLE_END )
265+ reportTelemetry ( BUNDLE_LIFECYCLE_TELEMETRY_GROUP_NAMES . COMPLETE_BUNDLE_LIFECYCLE , {
266+ success : true ,
267+ } )
268+
225269 return studioManager
226270 }
227271
@@ -275,8 +319,14 @@ export class StudioLifecycleManager {
275319 cloudDataSource,
276320 cfg,
277321 debugData,
322+ } ) . then ( ( studioManager ) => {
323+ // eslint-disable-next-line no-console
324+ console . log ( 'Studio manager reloaded' )
325+
326+ return studioManager
278327 } ) . catch ( ( error ) => {
279- debug ( 'Error during reload of studio manager: %o' , error )
328+ // eslint-disable-next-line no-console
329+ console . error ( 'Error during reload of studio manager: %o' , error )
280330
281331 return null
282332 } )
0 commit comments