Skip to content

Commit 024cd0a

Browse files
manish-bothraclaude
andcommitted
Forward the Test Observability collector URL to the remote reporter
The reporter that sends TestRunStarted/TestRunFinished runs on the BrowserStack machine from its own install of this package, which has the prod collector hard-coded. Against any other collector (staging environments) those events never arrive, so TestHub keeps nameless test cases and Accessibility collapses every test in a spec into one. Make API_URL overridable via BROWSERSTACK_TEST_OBSERVABILITY_API_URL and forward the launching cli's effective collector in system_env_vars, the same channel BS_TESTOPS_JWT already uses. Prod behaviour is unchanged. Jira: A11Y-13909 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent bf84c26 commit 024cd0a

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎bin/helpers/utils.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const usageReporting = require("./usageReporting"),
3131
pkg = require('../../package.json'),
3232
transports = require('./logger').transports,
3333
o11yHelpers = require('../testObservability/helper/helper'),
34-
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER } = require('../testObservability/helper/constants');
34+
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER, API_URL: OBSERVABILITY_API_URL } = require('../testObservability/helper/constants');
3535

3636
const { default: axios } = require("axios");
3737
const { shouldProcessEventForTesthub } = require("../testhub/utils");
@@ -614,6 +614,8 @@ exports.setSystemEnvs = (bsConfig) => {
614614
OBSERVABILITY_ENV_VARS.forEach(key => {
615615
envKeys[key] = process.env[key];
616616
});
617+
// Remote reporter must post to the collector this build was created on, not its package default
618+
envKeys['BROWSERSTACK_TEST_OBSERVABILITY_API_URL'] = OBSERVABILITY_API_URL;
617619

618620
let gitConfigPath = o11yHelpers.findGitConfig(process.cwd());
619621
if(!o11yHelpers.isBrowserstackInfra()) process.env.OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath;

‎bin/testObservability/helper/constants.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const path = require('path');
33
exports.consoleHolder = Object.assign({},console);
44
exports.BATCH_SIZE = 1000;
55
exports.BATCH_INTERVAL = 2000;
6-
exports.API_URL = 'https://collector-observability.browserstack.com';
6+
// Overridable so the remote reporter (own install of this package) can target the launching cli's collector
7+
exports.API_URL = process.env.BROWSERSTACK_TEST_OBSERVABILITY_API_URL || 'https://collector-observability.browserstack.com';
78

89
exports.IPC_EVENTS = {
910
LOG: 'testObservability:cypressLog',

‎test/unit/bin/helpers/utils.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,36 @@ describe('utils', () => {
961961
delete process.env.CYPRESS_TEST_1;
962962
delete process.env.cypress_test_2;
963963
});
964+
965+
it('forwards the observability collector url for the remote reporter', () => {
966+
let bsConfig = { run_settings: { env: null } };
967+
968+
utils.setSystemEnvs(bsConfig);
969+
expect(bsConfig.run_settings.system_env_vars)
970+
.to.be.an('array')
971+
.that.includes('BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-observability.browserstack.com');
972+
});
973+
974+
it('forwards an overridden observability collector url', () => {
975+
const constantsPath = require.resolve('../../../../bin/testObservability/helper/constants');
976+
const utilsPath = require.resolve('../../../../bin/helpers/utils');
977+
process.env.BROWSERSTACK_TEST_OBSERVABILITY_API_URL = 'https://collector-example.bsstag.com';
978+
delete require.cache[constantsPath];
979+
delete require.cache[utilsPath];
980+
try {
981+
const freshUtils = require('../../../../bin/helpers/utils');
982+
let bsConfig = { run_settings: { env: null } };
983+
freshUtils.setSystemEnvs(bsConfig);
984+
expect(require(constantsPath).API_URL).to.equal('https://collector-example.bsstag.com');
985+
expect(bsConfig.run_settings.system_env_vars)
986+
.to.be.an('array')
987+
.that.includes('BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-example.bsstag.com');
988+
} finally {
989+
delete process.env.BROWSERSTACK_TEST_OBSERVABILITY_API_URL;
990+
delete require.cache[constantsPath];
991+
delete require.cache[utilsPath];
992+
}
993+
});
964994
});
965995

966996
describe('fixCommaSeparatedString', () => {

0 commit comments

Comments
 (0)