@@ -9,6 +9,8 @@ const { promisify } = require('util');
99const gitconfig = require ( 'gitconfiglocal' ) ;
1010const { spawn, execSync } = require ( 'child_process' ) ;
1111const glob = require ( 'glob' ) ;
12+ const util = require ( 'util' ) ;
13+
1214const { runOptions } = require ( '../../helpers/runnerArgs' )
1315
1416const pGitconfig = promisify ( gitconfig ) ;
@@ -38,6 +40,13 @@ exports.pending_test_uploads = {
3840 count : 0
3941} ;
4042
43+ exports . debugOnConsole = ( text ) => {
44+ if ( ( process . env . BROWSERSTACK_OBSERVABILITY_DEBUG + '' ) === "true" ||
45+ ( process . env . BROWSERSTACK_OBSERVABILITY_DEBUG + '' ) === "1" ) {
46+ consoleHolder . log ( `[ OBSERVABILITY ] ${ text } ` ) ;
47+ }
48+ }
49+
4150exports . debug = ( text , shouldReport = false , throwable = null ) => {
4251 if ( process . env . BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process . env . BROWSERSTACK_OBSERVABILITY_DEBUG === "1" ) {
4352 logger . info ( `[ OBSERVABILITY ] ${ text } ` ) ;
@@ -475,14 +484,18 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
475484 } ;
476485
477486 try {
487+ const eventsUuids = data . map ( eventData => `${ eventData . event_type } :${ eventData . test_run ? eventData . test_run . uuid : ( eventData . hook_run ? eventData . hook_run . uuid : null ) } ` ) . join ( ', ' ) ;
488+ exports . debugOnConsole ( `[Request Batch Send] for events:uuids ${ eventsUuids } ` ) ;
478489 const response = await nodeRequest ( 'POST' , eventUrl , data , config ) ;
490+ exports . debugOnConsole ( `[Request Batch Response] for events:uuids ${ eventsUuids } ` ) ;
479491 if ( response . data . error ) {
480492 throw ( { message : response . data . error } ) ;
481493 } else {
482494 exports . debug ( `${ kind } event successfull!` )
483495 exports . pending_test_uploads . count = Math . max ( 0 , exports . pending_test_uploads . count - data . length ) ;
484496 }
485497 } catch ( error ) {
498+ exports . debugOnConsole ( `[Request Error] Error in sending request ${ util . format ( error ) } ` ) ;
486499 if ( error . response ) {
487500 exports . debug ( `EXCEPTION IN ${ kind } REQUEST TO TEST OBSERVABILITY : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
488501 } else {
@@ -522,6 +535,7 @@ exports.uploadEventData = async (eventData, run=0) => {
522535
523536 exports . requestQueueHandler . start ( ) ;
524537 const { shouldProceed, proceedWithData, proceedWithUrl } = exports . requestQueueHandler . add ( eventData ) ;
538+ exports . debugOnConsole ( `[Request Queue] ${ eventData . event_type } with uuid ${ eventData . test_run ? eventData . test_run . uuid : ( eventData . hook_run ? eventData . hook_run . uuid : null ) } is added` )
525539 if ( ! shouldProceed ) {
526540 return ;
527541 } else if ( proceedWithData ) {
@@ -538,7 +552,10 @@ exports.uploadEventData = async (eventData, run=0) => {
538552 } ;
539553
540554 try {
555+ const eventsUuids = data . map ( eventData => `${ eventData . event_type } :${ eventData . test_run ? eventData . test_run . uuid : ( eventData . hook_run ? eventData . hook_run . uuid : null ) } ` ) . join ( ', ' ) ;
556+ exports . debugOnConsole ( `[Request Send] for events:uuids ${ eventsUuids } ` ) ;
541557 const response = await nodeRequest ( 'POST' , event_api_url , data , config ) ;
558+ exports . debugOnConsole ( `[Request Repsonse] ${ util . format ( response . data ) } for events:uuids ${ eventsUuids } ` )
542559 if ( response . data . error ) {
543560 throw ( { message : response . data . error } ) ;
544561 } else {
@@ -550,6 +567,7 @@ exports.uploadEventData = async (eventData, run=0) => {
550567 } ;
551568 }
552569 } catch ( error ) {
570+ exports . debugOnConsole ( `[Request Error] Error in sending request ${ util . format ( error ) } ` ) ;
553571 if ( error . response ) {
554572 exports . debug ( `EXCEPTION IN ${ event_api_url !== exports . requestQueueHandler . eventUrl ? log_tag : 'Batch-Queue' } REQUEST TO TEST OBSERVABILITY : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
555573 } else {
0 commit comments