@@ -10,6 +10,7 @@ const config = require('./config'),
10
10
utils = require ( './utils' ) ;
11
11
12
12
const { AUTH_REGEX , REDACTED_AUTH , REDACTED , CLI_ARGS_REGEX , RAW_ARGS_REGEX } = require ( "./constants" ) ;
13
+ const { isTurboScaleSession } = require ( '../helpers/atsHelper' ) ;
13
14
14
15
function get_version ( package_name ) {
15
16
try {
@@ -197,10 +198,58 @@ function redactKeys(str, regex, redact) {
197
198
return str . replace ( regex , redact ) ;
198
199
}
199
200
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
+
200
244
function 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
+
201
251
if ( isUsageReportingEnabled ( ) === "true" ) return ;
202
252
203
- let bsConfig = JSON . parse ( JSON . stringify ( args . bstack_config ) ) ;
204
253
let runSettings = "" ;
205
254
let sanitizedbsConfig = "" ;
206
255
let cli_details = cli_version_and_path ( bsConfig ) ;
@@ -258,6 +307,10 @@ function send(args) {
258
307
} ,
259
308
} ;
260
309
310
+ if ( isTurboScaleSession ( bsConfig ) ) {
311
+ payload . event_type = 'hst_cypress_cli_stats' ;
312
+ }
313
+
261
314
const options = {
262
315
headers : {
263
316
"Content-Type" : "text/json" ,
0 commit comments