@@ -10,6 +10,7 @@ const config = require('./config'),
1010 utils = require ( './utils' ) ;
1111
1212const { AUTH_REGEX , REDACTED_AUTH , REDACTED , CLI_ARGS_REGEX , RAW_ARGS_REGEX } = require ( "./constants" ) ;
13+ const { isTurboScaleSession } = require ( '../helpers/atsHelper' ) ;
1314
1415function get_version ( package_name ) {
1516 try {
@@ -197,10 +198,58 @@ function redactKeys(str, regex, redact) {
197198 return str . replace ( regex , redact ) ;
198199}
199200
201+ function sendTurboscaleErrorLogs ( args ) {
202+ let bsConfig = JSON . parse ( JSON . stringify ( args . bstack_config ) ) ;
203+ let data = utils . isUndefined ( args . data ) ? { } : args . data ;
204+ const turboscaleErrorPayload = {
205+ kind : 'hst-cypress-cli-error' ,
206+ data : data ,
207+ error : args . message
208+ }
209+
210+ const options = {
211+ headers : {
212+ 'User-Agent' : utils . getUserAgent ( )
213+ } ,
214+ method : "POST" ,
215+ auth : {
216+ username : bsConfig . auth . username ,
217+ password : bsConfig . auth . access_key ,
218+ } ,
219+ url : `${ config . turboScaleAPIUrl } /send-instrumentation` ,
220+ body : turboscaleErrorPayload ,
221+ json : true ,
222+ maxAttempts : 10 , // (default) try 3 times
223+ retryDelay : 2000 , // (default) wait for 2s before trying again
224+ retrySrategy : request . RetryStrategies . HTTPOrNetworkError , // (default) retry on 5xx or network errors
225+ } ;
226+
227+ fileLogger . info ( `Sending ${ JSON . stringify ( turboscaleErrorPayload ) } to ${ config . turboScaleAPIUrl } /send-instrumentation` ) ;
228+ request ( options , function ( error , res , body ) {
229+ if ( error ) {
230+ //write err response to file
231+ fileLogger . error ( JSON . stringify ( error ) ) ;
232+ return ;
233+ }
234+ // write response file
235+ let response = {
236+ attempts : res . attempts ,
237+ statusCode : res . statusCode ,
238+ body : body
239+ } ;
240+ fileLogger . info ( `${ JSON . stringify ( response ) } ` ) ;
241+ } ) ;
242+ }
243+
200244function send ( args ) {
245+ let bsConfig = JSON . parse ( JSON . stringify ( args . bstack_config ) ) ;
246+
247+ if ( isTurboScaleSession ( bsConfig ) && args . message_type === 'error' ) {
248+ sendTurboscaleErrorLogs ( args ) ;
249+ }
250+
201251 if ( isUsageReportingEnabled ( ) === "true" ) return ;
202252
203- let bsConfig = JSON . parse ( JSON . stringify ( args . bstack_config ) ) ;
204253 let runSettings = "" ;
205254 let sanitizedbsConfig = "" ;
206255 let cli_details = cli_version_and_path ( bsConfig ) ;
@@ -258,6 +307,10 @@ function send(args) {
258307 } ,
259308 } ;
260309
310+ if ( isTurboScaleSession ( bsConfig ) ) {
311+ payload . event_type = 'hst_cypress_cli_stats' ;
312+ }
313+
261314 const options = {
262315 headers : {
263316 "Content-Type" : "text/json" ,
0 commit comments