From d60345756a229b04abc1d617b863dc07eea53121 Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Thu, 7 Aug 2025 11:27:57 +0530 Subject: [PATCH 1/6] changed olly link --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 467f090c..314ca438 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -105,7 +105,7 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => { && process.env.BS_TESTOPS_BUILD_HASHED_ID != "null" && process.env.BS_TESTOPS_BUILD_HASHED_ID != "undefined") { console.log(); - logger.info(`Visit https://observability.browserstack.com/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID} to view build report, insights, and many more debugging information all at one place!\n`); + logger.info(`Visit https://automation.browserstack.com/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID} to view build report, insights, and many more debugging information all at one place!\n`); } } catch(err) { exports.debug('Build Not Found'); From d7393d6f20af02a3ba597595b3737a820517d67b Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Thu, 7 Aug 2025 16:34:33 +0530 Subject: [PATCH 2/6] added olly artifact changes + added some logs --- bin/commands/runs.js | 11 +++++- bin/helpers/helper.js | 6 ++- bin/helpers/utils.js | 41 ++++++++++++++++++-- bin/testObservability/crashReporter/index.js | 5 ++- bin/testObservability/helper/constants.js | 4 ++ bin/testObservability/helper/helper.js | 36 +++++++++++------ bin/testObservability/reporter/index.js | 5 ++- 7 files changed, 86 insertions(+), 22 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 0a439ff6..78107804 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -40,7 +40,7 @@ const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileCon module.exports = function run(args, rawArgs) { - + utils.normalizeTestReportingEnvVars(); markBlockStart('preBuild'); // set debug mode (--cli-debug) utils.setDebugMode(args); @@ -59,6 +59,9 @@ module.exports = function run(args, rawArgs) { return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) { markBlockEnd('validateBstackJson'); logger.debug('Completed browserstack.json validation'); + + console.log("bsConfig after validation",bsConfig); + markBlockStart('setConfig'); logger.debug('Started setting the configs'); @@ -112,7 +115,9 @@ module.exports = function run(args, rawArgs) { // set build tag caps utils.setBuildTags(bsConfig, args); - // Send build start to Observability + console.log(`checking if testObservability session is enabled line run() 118: ${isTestObservabilitySession}`); + + // Send build start to TEST REPORTING AND ANALYTICS if(isTestObservabilitySession) { await launchTestSession(bsConfig, bsConfigPath); utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData); @@ -314,6 +319,7 @@ module.exports = function run(args, rawArgs) { markBlockEnd('createBuild'); markBlockEnd('total'); utils.setProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData); + console.log(`checking if testObservability session is enabled line 322: ${isTestObservabilitySession}`); if(isTestObservabilitySession) { utils.setO11yProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData); } @@ -524,6 +530,7 @@ module.exports = function run(args, rawArgs) { }).catch(function (err) { logger.error(err); utils.setUsageReportingFlag(null, args.disableUsageReporting); + console.log(`now reading using readBsConfigJSON in catch block for validateBstackJson`); let bsJsonData = utils.readBsConfigJSON(bsConfigPath); utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index ecb4e279..ba0c7e6d 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -19,10 +19,12 @@ const { readCypressConfigFile } = require('./readCypressConfigUtil'); const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants') const CrashReporter = require('../testObservability/crashReporter'); const HttpsProxyAgent = require('https-proxy-agent'); +const { TEST_REPORTING_ANALYTICS } = require("../testObservability/helper/constants"); exports.debug = (text, shouldReport = false, throwable = null) => { + console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { - logger.info(`[ OBSERVABILITY ] ${text}`); + logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } if(shouldReport) { CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null); @@ -290,6 +292,8 @@ exports.getBuildDetails = (bsConfig, isO11y = false) => { projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName; /* Pick from testObservabilityOptions */ + console.log(`isTestObservabilityOptionsPresent: ${isTestObservabilityOptionsPresent}`); + console.log(`bsConfig in getBuildDetails: ${JSON.stringify(bsConfig, null, 2)}`); if(isTestObservabilityOptionsPresent) { buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"]; projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"]; diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index caaf992e..1864f8b1 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -33,6 +33,8 @@ exports.validateBstackJson = (bsConfigPath) => { try { logger.info(`Reading config from ${bsConfigPath}`); let bsConfig = require(bsConfigPath); + bsConfig = exports.normalizeTestReportingConfig(bsConfig); + console.log(`BrowserStack config loaded after normalizing: ${JSON.stringify(bsConfig, null, 2)}`); resolve(bsConfig); } catch (e) { reject( @@ -492,7 +494,7 @@ exports.setNodeVersion = (bsConfig, args) => { // specs can be passed via command line args as a string // command line args takes precedence over config exports.setUserSpecs = (bsConfig, args) => { - + console.log(`checking if testObservability session is enabled setUserSpecs line 497: ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) { bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS; return; @@ -1236,6 +1238,7 @@ exports.handleSyncExit = (exitCode, dashboard_url) => { syncCliLogger.info(Constants.userMessages.BUILD_REPORT_MESSAGE); syncCliLogger.info(dashboard_url); } + console.log(`checking if observability session is active from handleSyncExit ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isTestObservabilitySession()) { o11yHelpers.printBuildLink(true, exitCode); } else { @@ -1499,7 +1502,7 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter, // blindly send other passed configs with run_settings and handle at backend exports.setOtherConfigs = (bsConfig, args) => { - + console.log(`checking if observability session is active from setOtherConfigs ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) { bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER; return; @@ -1519,7 +1522,17 @@ exports.setOtherConfigs = (bsConfig, args) => { exports.readBsConfigJSON = (bsConfigPath) => { try { fs.accessSync(bsConfigPath, fs.constants.R_OK); - return fs.readFileSync(bsConfigPath, 'utf-8'); + const configContent = fs.readFileSync(bsConfigPath, 'utf-8'); + console.log(`configContent: ${configContent}`); + try { + const bsConfig = JSON.parse(configContent); + const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); + console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); + return JSON.stringify(normalizedBsConfig); + } catch (err) { + logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); + return configContent; + } } catch (err) { return null; } @@ -1804,3 +1817,25 @@ exports.decodeJWTToken = (token) => { return undefined; } } + +exports.normalizeTestReportingEnvVars = () => { + if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING)){ + process.env.BROWSERSTACK_TEST_OBSERVABILITY = process.env.BROWSERSTACK_TEST_REPORTING; + } + + if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING_DEBUG)){ + process.env.BROWSERSTACK_OBSERVABILITY_DEBUG = process.env.BROWSERSTACK_TEST_REPORTING_DEBUG; + } +} + +exports.normalizeTestReportingConfig = (bsConfig) => { + if (!this.isUndefined(bsConfig["testReporting"])) { + bsConfig["testObservability"] = bsConfig["testReporting"]; + } + + if (!this.isUndefined(bsConfig["testReportingOptions"])) { + bsConfig["testObservabilityOptions"] = bsConfig["testReportingOptions"]; + } + + return bsConfig; +} diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index 00ecb6bc..4e53468f 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -7,7 +7,7 @@ const HttpsProxyAgent = require('https-proxy-agent'); const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); -const { API_URL, consoleHolder } = require('../helper/constants'); +const { API_URL, consoleHolder, TEST_REPORTING_ANALYTICS } = require('../helper/constants'); /* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */ const httpsKeepAliveAgent = new https.Agent({ @@ -18,8 +18,9 @@ const httpsKeepAliveAgent = new https.Agent({ }); const debug = (text) => { + console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { - logger.info(`[ OBSERVABILITY ] ${text}`); + logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } } diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index dbf5e053..b7877247 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -16,6 +16,7 @@ exports.IPC_EVENTS = { exports.OBSERVABILITY_ENV_VARS = [ "BROWSERSTACK_TEST_OBSERVABILITY", + "BROWSERSTACK_TEST_REPORTING", "BROWSERSTACK_AUTOMATION", "BS_TESTOPS_BUILD_COMPLETED", "BS_TESTOPS_JWT", @@ -23,6 +24,7 @@ exports.OBSERVABILITY_ENV_VARS = [ "BS_TESTOPS_ALLOW_SCREENSHOTS", "OBSERVABILITY_LAUNCH_SDK_VERSION", "BROWSERSTACK_OBSERVABILITY_DEBUG", + "BROWSERSTACK_TEST_REPORTING_DEBUG", "OBS_CRASH_REPORTING_USERNAME", "OBS_CRASH_REPORTING_ACCESS_KEY", "OBS_CRASH_REPORTING_BS_CONFIG_PATH", @@ -34,3 +36,5 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter'); exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`; + +exports.TEST_REPORTING_ANALYTICS = 'TEST REPORTING AND ANALYTICS'; \ No newline at end of file diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 314ca438..a1378e53 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -27,7 +27,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim(); const { name, version } = require('../../../package.json'); const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../../helpers/constants'); -const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL } = require('./constants'); +const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL, TEST_REPORTING_ANALYTICS } = require('./constants'); const ALLOWED_MODULES = [ 'cypress/package.json', @@ -41,15 +41,17 @@ exports.pending_test_uploads = { }; exports.debugOnConsole = (text) => { + console.log(`checking if BROWSERSTACK_TEST_OBSERVABILITY_DEBUG is enabled in debugOnConsole: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if ((process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "true" || (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "1") { - consoleHolder.log(`[ OBSERVABILITY ] ${text}`); + consoleHolder.log(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } } exports.debug = (text, shouldReport = false, throwable = null) => { + console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled in debug 52: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { - logger.info(`[ OBSERVABILITY ] ${text}`); + logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } if(shouldReport) { CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null); @@ -93,6 +95,7 @@ const supportFileCleanup = () => { exports.buildStopped = false; exports.printBuildLink = async (shouldStopSession, exitCode = null) => { + console.log(`checking if testObservability session is active from printBuildLink ${this.isTestObservabilitySession()}`); if(!this.isTestObservabilitySession() || exports.buildStopped) return; exports.buildStopped = true; try { @@ -326,6 +329,8 @@ const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => { } exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cypressConfigPath) => { + console.log(`Setting Crash Reporting Config with bsConfigPath: ${bsConfigPath}`); + console.log(`Setting Crash Reporting Config with bsConfig: ${JSON.stringify(bsConfig)}`); try { const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); const cypressConfigFile = getCypressConfigFileContent(null, cypressConfigPath); @@ -513,15 +518,16 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { } catch(error) { exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { - exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); + exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { - exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error); + exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error); } exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length); } } const RequestQueueHandler = require('./requestQueueHandler'); +const constants = require('../../helpers/constants'); exports.requestQueueHandler = new RequestQueueHandler(); exports.uploadEventData = async (eventData, run=0) => { @@ -541,7 +547,7 @@ exports.uploadEventData = async (eventData, run=0) => { if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") { if(process.env.BS_TESTOPS_JWT == "null") { - exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : missing authentication token`); + exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS}: missing authentication token`); exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1); return { status: 'error', @@ -586,9 +592,9 @@ exports.uploadEventData = async (eventData, run=0) => { } catch(error) { exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { - 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); + exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { - exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error); + exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error); } exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - (event_api_url === 'api/v1/event' ? 1 : data.length)); return { @@ -598,7 +604,7 @@ exports.uploadEventData = async (eventData, run=0) => { } } } else if (run >= 5) { - exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : Build Start is not completed and ${log_tag} retry runs exceeded`); + exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS} : Build Start is not completed and ${log_tag} retry runs exceeded`); if(process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1); return { status: 'error', @@ -621,6 +627,9 @@ exports.setTestObservabilityFlags = (bsConfig) => { /* set default again but under try catch in case of wrong config */ isTestObservabilitySession = utils.nonEmptyArray(bsConfig.run_settings.downloads) ? false : true; + console.log(`bsconfig from setTestObservabilityFlags: ${JSON.stringify(bsConfig)}`); + console.log(`bs test olly enabled from env: ${process.env.BROWSERSTACK_TEST_OBSERVABILITY}`); + if(!utils.isUndefined(bsConfig["testObservability"])) isTestObservabilitySession = ( bsConfig["testObservability"] == true || bsConfig["testObservability"] == 1 ); if(!utils.isUndefined(process.env.BROWSERSTACK_TEST_OBSERVABILITY)) isTestObservabilitySession = ( process.env.BROWSERSTACK_TEST_OBSERVABILITY == "true" || process.env.BROWSERSTACK_TEST_OBSERVABILITY == "1" ); if(process.argv.includes('--disable-test-observability')) isTestObservabilitySession = false; @@ -646,6 +655,7 @@ exports.setTestObservabilityFlags = (bsConfig) => { process.env.BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession; process.env.BROWSERSTACK_AUTOMATION = isBrowserstackInfra; + console.log(`final testObservability capability is set to in setTestPObservabilityFlag ${isTestObservabilitySession}`); return [isTestObservabilitySession, isBrowserstackInfra]; } @@ -664,7 +674,7 @@ exports.shouldReRunObservabilityTests = () => { exports.stopBuildUpstream = async () => { if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") { if(process.env.BS_TESTOPS_JWT == "null" || process.env.BS_TESTOPS_BUILD_HASHED_ID == "null") { - exports.debug('EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : Missing authentication token'); + exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : Missing authentication token`); return { status: 'error', message: 'Token/buildID is undefined, build creation might have failed' @@ -694,9 +704,9 @@ exports.stopBuildUpstream = async () => { } } catch(error) { if (error.response) { - exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); + exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { - exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error); + exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error); } return { status: 'error', @@ -852,6 +862,7 @@ exports.resolveModule = (module) => { const getReRunSpecs = (rawArgs) => { let finalArgs = rawArgs; + console.log(`checking if testObservability is enabled in getRerun specs ${this.isTestObservabilitySession()}`); if (this.isTestObservabilitySession() && this.shouldReRunObservabilityTests()) { let startIdx = -1, numEle = 0; for(let idx=0; idx { } const getLocalSessionReporter = () => { + console.log(`checking if testObservability is enabled getLocalSessionReporter ${this.isTestObservabilitySession()}`); if(this.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) { return ['--reporter', TEST_OBSERVABILITY_REPORTER_LOCAL]; } else { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 396ad0e3..22b30049 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -12,7 +12,7 @@ const Mocha = requireModule('mocha'); const Runnable = require('mocha/lib/runnable'); // need to handle as this isn't present in older mocha versions const { v4: uuidv4 } = require('uuid'); -const { IPC_EVENTS } = require('../helper/constants'); +const { IPC_EVENTS, TEST_REPORTING_ANALYTICS } = require('../helper/constants'); const { startIPCServer } = require('../plugin/ipcServer'); const HOOK_TYPES_MAP = { @@ -88,6 +88,7 @@ class MyReporter { }) .on(EVENT_HOOK_BEGIN, async (hook) => { + console.log(`checking testObservability is enabled in hook begin ${this.testObservability}`); debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN`); if(this.testObservability == true) { if(!hook.hookAnalyticsId) { @@ -511,7 +512,7 @@ class MyReporter { }); } } catch(error) { - debug(`Exception in uploading log data to Observability with error : ${error}`, true, error); + debug(`Exception in uploading log data to ${TEST_REPORTING_ANALYTICS} with error : ${error}`, true, error); } } From 3bcf78509db3521dfc0936aa72e86ab8c28ecaa0 Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Thu, 7 Aug 2025 18:52:54 +0530 Subject: [PATCH 3/6] more logging --- bin/commands/runs.js | 1 + bin/helpers/utils.js | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 78107804..ba84c005 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -532,6 +532,7 @@ module.exports = function run(args, rawArgs) { utils.setUsageReportingFlag(null, args.disableUsageReporting); console.log(`now reading using readBsConfigJSON in catch block for validateBstackJson`); let bsJsonData = utils.readBsConfigJSON(bsConfigPath); + console.log(`checking the type of bsJsonData with main logic: ${typeof bsJsonData}`); utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; }).finally(function(){ diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 1864f8b1..e94c650d 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1522,17 +1522,17 @@ exports.setOtherConfigs = (bsConfig, args) => { exports.readBsConfigJSON = (bsConfigPath) => { try { fs.accessSync(bsConfigPath, fs.constants.R_OK); - const configContent = fs.readFileSync(bsConfigPath, 'utf-8'); - console.log(`configContent: ${configContent}`); - try { - const bsConfig = JSON.parse(configContent); - const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); - console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); - return JSON.stringify(normalizedBsConfig); - } catch (err) { - logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); - return configContent; - } + return fs.readFileSync(bsConfigPath, 'utf-8'); + // console.log(`configContent: ${configContent}`); + // try { + // const bsConfig = JSON.parse(configContent); + // const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); + // console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); + // return JSON.stringify(normalizedBsConfig); + // } catch (err) { + // logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); + // return configContent; + // } } catch (err) { return null; } From 80d4e1bd28e6524d0acaf5d51438d8a937c3af8e Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Thu, 7 Aug 2025 19:00:03 +0530 Subject: [PATCH 4/6] added some more logs for debugging --- bin/testObservability/helper/helper.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index a1378e53..7c0dec58 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -333,6 +333,7 @@ exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cyp console.log(`Setting Crash Reporting Config with bsConfig: ${JSON.stringify(bsConfig)}`); try { const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); + const cypressConfigFile = getCypressConfigFileContent(null, cypressConfigPath); if(!credentialsStr) { @@ -349,7 +350,10 @@ exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cyp const setCrashReportingConfig = (bsConfig, bsConfigPath) => { try { + console.log(`Setting Crash Reporting Config with bsConfigPath: ${bsConfigPath}`); const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); + console.log(`checking the type of bsConfig: ${typeof bsConfig}`); + const cypressConfigFile = getCypressConfigFileContent(bsConfig, null); const credentialsStr = JSON.stringify({ username: bsConfig["auth"]["username"], From 726a5b084eddfad1627f6780a5d1c863739e3a96 Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Thu, 7 Aug 2025 20:58:39 +0530 Subject: [PATCH 5/6] added logs --- bin/helpers/utils.js | 22 +++++++++++----------- bin/testObservability/helper/helper.js | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index e94c650d..4b1755b3 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -1522,17 +1522,17 @@ exports.setOtherConfigs = (bsConfig, args) => { exports.readBsConfigJSON = (bsConfigPath) => { try { fs.accessSync(bsConfigPath, fs.constants.R_OK); - return fs.readFileSync(bsConfigPath, 'utf-8'); - // console.log(`configContent: ${configContent}`); - // try { - // const bsConfig = JSON.parse(configContent); - // const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); - // console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); - // return JSON.stringify(normalizedBsConfig); - // } catch (err) { - // logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); - // return configContent; - // } + const configContent = fs.readFileSync(bsConfigPath, 'utf-8'); + console.log(`configContent: ${configContent}`); + try { + const bsConfig = JSON.parse(configContent); + const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); + console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); + return JSON.stringify(normalizedBsConfig); + } catch (err) { + logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); + return null; + } } catch (err) { return null; } diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 7c0dec58..420e1558 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -353,6 +353,7 @@ const setCrashReportingConfig = (bsConfig, bsConfigPath) => { console.log(`Setting Crash Reporting Config with bsConfigPath: ${bsConfigPath}`); const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); console.log(`checking the type of bsConfig: ${typeof bsConfig}`); + console.log(`printing username and acces_key from bsConfig: ${bsConfig["auth"]["username"]} : ${bsConfig["auth"]["access_key"]}`); const cypressConfigFile = getCypressConfigFileContent(bsConfig, null); const credentialsStr = JSON.stringify({ From c0c03c0cb9c5e9b94a754ad2157c71d8b2aa68cb Mon Sep 17 00:00:00 2001 From: Tanmay Lokhande Date: Fri, 8 Aug 2025 08:10:38 +0530 Subject: [PATCH 6/6] removed logs --- bin/commands/runs.js | 8 -------- bin/helpers/helper.js | 3 --- bin/helpers/utils.js | 6 ------ bin/testObservability/crashReporter/index.js | 1 - bin/testObservability/helper/constants.js | 2 +- bin/testObservability/helper/helper.js | 17 ----------------- bin/testObservability/reporter/index.js | 1 - 7 files changed, 1 insertion(+), 37 deletions(-) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index ba84c005..1e6f4944 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -59,9 +59,6 @@ module.exports = function run(args, rawArgs) { return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) { markBlockEnd('validateBstackJson'); logger.debug('Completed browserstack.json validation'); - - console.log("bsConfig after validation",bsConfig); - markBlockStart('setConfig'); logger.debug('Started setting the configs'); @@ -115,8 +112,6 @@ module.exports = function run(args, rawArgs) { // set build tag caps utils.setBuildTags(bsConfig, args); - console.log(`checking if testObservability session is enabled line run() 118: ${isTestObservabilitySession}`); - // Send build start to TEST REPORTING AND ANALYTICS if(isTestObservabilitySession) { await launchTestSession(bsConfig, bsConfigPath); @@ -319,7 +314,6 @@ module.exports = function run(args, rawArgs) { markBlockEnd('createBuild'); markBlockEnd('total'); utils.setProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData); - console.log(`checking if testObservability session is enabled line 322: ${isTestObservabilitySession}`); if(isTestObservabilitySession) { utils.setO11yProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData); } @@ -530,9 +524,7 @@ module.exports = function run(args, rawArgs) { }).catch(function (err) { logger.error(err); utils.setUsageReportingFlag(null, args.disableUsageReporting); - console.log(`now reading using readBsConfigJSON in catch block for validateBstackJson`); let bsJsonData = utils.readBsConfigJSON(bsConfigPath); - console.log(`checking the type of bsJsonData with main logic: ${typeof bsJsonData}`); utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; }).finally(function(){ diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index ba0c7e6d..b839c76b 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -22,7 +22,6 @@ const HttpsProxyAgent = require('https-proxy-agent'); const { TEST_REPORTING_ANALYTICS } = require("../testObservability/helper/constants"); exports.debug = (text, shouldReport = false, throwable = null) => { - console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } @@ -292,8 +291,6 @@ exports.getBuildDetails = (bsConfig, isO11y = false) => { projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName; /* Pick from testObservabilityOptions */ - console.log(`isTestObservabilityOptionsPresent: ${isTestObservabilityOptionsPresent}`); - console.log(`bsConfig in getBuildDetails: ${JSON.stringify(bsConfig, null, 2)}`); if(isTestObservabilityOptionsPresent) { buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"]; projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"]; diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 4b1755b3..cc644c03 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -34,7 +34,6 @@ exports.validateBstackJson = (bsConfigPath) => { logger.info(`Reading config from ${bsConfigPath}`); let bsConfig = require(bsConfigPath); bsConfig = exports.normalizeTestReportingConfig(bsConfig); - console.log(`BrowserStack config loaded after normalizing: ${JSON.stringify(bsConfig, null, 2)}`); resolve(bsConfig); } catch (e) { reject( @@ -494,7 +493,6 @@ exports.setNodeVersion = (bsConfig, args) => { // specs can be passed via command line args as a string // command line args takes precedence over config exports.setUserSpecs = (bsConfig, args) => { - console.log(`checking if testObservability session is enabled setUserSpecs line 497: ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) { bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS; return; @@ -1238,7 +1236,6 @@ exports.handleSyncExit = (exitCode, dashboard_url) => { syncCliLogger.info(Constants.userMessages.BUILD_REPORT_MESSAGE); syncCliLogger.info(dashboard_url); } - console.log(`checking if observability session is active from handleSyncExit ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isTestObservabilitySession()) { o11yHelpers.printBuildLink(true, exitCode); } else { @@ -1502,7 +1499,6 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter, // blindly send other passed configs with run_settings and handle at backend exports.setOtherConfigs = (bsConfig, args) => { - console.log(`checking if observability session is active from setOtherConfigs ${o11yHelpers.isTestObservabilitySession()}`); if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) { bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER; return; @@ -1523,11 +1519,9 @@ exports.readBsConfigJSON = (bsConfigPath) => { try { fs.accessSync(bsConfigPath, fs.constants.R_OK); const configContent = fs.readFileSync(bsConfigPath, 'utf-8'); - console.log(`configContent: ${configContent}`); try { const bsConfig = JSON.parse(configContent); const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig); - console.log(`normalizedBsConfig: ${JSON.stringify(normalizedBsConfig)}`); return JSON.stringify(normalizedBsConfig); } catch (err) { logger.error(`Error parsing JSON from ${bsConfigPath}:`, err); diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index 4e53468f..15022ce9 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -18,7 +18,6 @@ const httpsKeepAliveAgent = new https.Agent({ }); const debug = (text) => { - console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index b7877247..d3013f40 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -37,4 +37,4 @@ exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`; -exports.TEST_REPORTING_ANALYTICS = 'TEST REPORTING AND ANALYTICS'; \ No newline at end of file +exports.TEST_REPORTING_ANALYTICS = 'TEST REPORTING AND ANALYTICS'; diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 420e1558..cc504bd7 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -41,7 +41,6 @@ exports.pending_test_uploads = { }; exports.debugOnConsole = (text) => { - console.log(`checking if BROWSERSTACK_TEST_OBSERVABILITY_DEBUG is enabled in debugOnConsole: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if ((process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "true" || (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "1") { consoleHolder.log(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); @@ -49,7 +48,6 @@ exports.debugOnConsole = (text) => { } exports.debug = (text, shouldReport = false, throwable = null) => { - console.log(`checking if BROWSERSTACK_OBSERVABILITY_DEBUG is enabled in debug 52: ${process.env.BROWSERSTACK_OBSERVABILITY_DEBUG}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`); } @@ -95,7 +93,6 @@ const supportFileCleanup = () => { exports.buildStopped = false; exports.printBuildLink = async (shouldStopSession, exitCode = null) => { - console.log(`checking if testObservability session is active from printBuildLink ${this.isTestObservabilitySession()}`); if(!this.isTestObservabilitySession() || exports.buildStopped) return; exports.buildStopped = true; try { @@ -329,11 +326,8 @@ const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => { } exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cypressConfigPath) => { - console.log(`Setting Crash Reporting Config with bsConfigPath: ${bsConfigPath}`); - console.log(`Setting Crash Reporting Config with bsConfig: ${JSON.stringify(bsConfig)}`); try { const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); - const cypressConfigFile = getCypressConfigFileContent(null, cypressConfigPath); if(!credentialsStr) { @@ -350,11 +344,7 @@ exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cyp const setCrashReportingConfig = (bsConfig, bsConfigPath) => { try { - console.log(`Setting Crash Reporting Config with bsConfigPath: ${bsConfigPath}`); const browserstackConfigFile = utils.readBsConfigJSON(bsConfigPath); - console.log(`checking the type of bsConfig: ${typeof bsConfig}`); - console.log(`printing username and acces_key from bsConfig: ${bsConfig["auth"]["username"]} : ${bsConfig["auth"]["access_key"]}`); - const cypressConfigFile = getCypressConfigFileContent(bsConfig, null); const credentialsStr = JSON.stringify({ username: bsConfig["auth"]["username"], @@ -532,7 +522,6 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { } const RequestQueueHandler = require('./requestQueueHandler'); -const constants = require('../../helpers/constants'); exports.requestQueueHandler = new RequestQueueHandler(); exports.uploadEventData = async (eventData, run=0) => { @@ -632,9 +621,6 @@ exports.setTestObservabilityFlags = (bsConfig) => { /* set default again but under try catch in case of wrong config */ isTestObservabilitySession = utils.nonEmptyArray(bsConfig.run_settings.downloads) ? false : true; - console.log(`bsconfig from setTestObservabilityFlags: ${JSON.stringify(bsConfig)}`); - console.log(`bs test olly enabled from env: ${process.env.BROWSERSTACK_TEST_OBSERVABILITY}`); - if(!utils.isUndefined(bsConfig["testObservability"])) isTestObservabilitySession = ( bsConfig["testObservability"] == true || bsConfig["testObservability"] == 1 ); if(!utils.isUndefined(process.env.BROWSERSTACK_TEST_OBSERVABILITY)) isTestObservabilitySession = ( process.env.BROWSERSTACK_TEST_OBSERVABILITY == "true" || process.env.BROWSERSTACK_TEST_OBSERVABILITY == "1" ); if(process.argv.includes('--disable-test-observability')) isTestObservabilitySession = false; @@ -660,7 +646,6 @@ exports.setTestObservabilityFlags = (bsConfig) => { process.env.BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession; process.env.BROWSERSTACK_AUTOMATION = isBrowserstackInfra; - console.log(`final testObservability capability is set to in setTestPObservabilityFlag ${isTestObservabilitySession}`); return [isTestObservabilitySession, isBrowserstackInfra]; } @@ -867,7 +852,6 @@ exports.resolveModule = (module) => { const getReRunSpecs = (rawArgs) => { let finalArgs = rawArgs; - console.log(`checking if testObservability is enabled in getRerun specs ${this.isTestObservabilitySession()}`); if (this.isTestObservabilitySession() && this.shouldReRunObservabilityTests()) { let startIdx = -1, numEle = 0; for(let idx=0; idx { } const getLocalSessionReporter = () => { - console.log(`checking if testObservability is enabled getLocalSessionReporter ${this.isTestObservabilitySession()}`); if(this.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) { return ['--reporter', TEST_OBSERVABILITY_REPORTER_LOCAL]; } else { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 22b30049..5b71c55e 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -88,7 +88,6 @@ class MyReporter { }) .on(EVENT_HOOK_BEGIN, async (hook) => { - console.log(`checking testObservability is enabled in hook begin ${this.testObservability}`); debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN`); if(this.testObservability == true) { if(!hook.hookAnalyticsId) {