Skip to content

Commit 6712cee

Browse files
authored
Merge pull request #863 from 07souravkunda/improve_o11y_timeouts
add: debug logs for timeout
2 parents 69bbb5a + a0b224b commit 6712cee

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

bin/testObservability/helper/helper.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const { promisify } = require('util');
99
const gitconfig = require('gitconfiglocal');
1010
const { spawn, execSync } = require('child_process');
1111
const glob = require('glob');
12+
const util = require('util');
13+
1214
const { runOptions } = require('../../helpers/runnerArgs')
1315

1416
const 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+
4150
exports.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 {
@@ -496,6 +509,7 @@ const RequestQueueHandler = require('./requestQueueHandler');
496509
exports.requestQueueHandler = new RequestQueueHandler();
497510

498511
exports.uploadEventData = async (eventData, run=0) => {
512+
exports.debugOnConsole(`[uploadEventData] ${eventData.event_type}`);
499513
const log_tag = {
500514
['TestRunStarted']: 'Test_Start_Upload',
501515
['TestRunFinished']: 'Test_End_Upload',
@@ -522,6 +536,7 @@ exports.uploadEventData = async (eventData, run=0) => {
522536

523537
exports.requestQueueHandler.start();
524538
const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData);
539+
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`)
525540
if(!shouldProceed) {
526541
return;
527542
} else if(proceedWithData) {
@@ -538,7 +553,10 @@ exports.uploadEventData = async (eventData, run=0) => {
538553
};
539554

540555
try {
556+
const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
557+
exports.debugOnConsole(`[Request Send] for events:uuids ${eventsUuids}`);
541558
const response = await nodeRequest('POST',event_api_url,data,config);
559+
exports.debugOnConsole(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`)
542560
if(response.data.error) {
543561
throw({message: response.data.error});
544562
} else {
@@ -550,6 +568,7 @@ exports.uploadEventData = async (eventData, run=0) => {
550568
};
551569
}
552570
} catch(error) {
571+
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
553572
if (error.response) {
554573
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);
555574
} else {

bin/testObservability/reporter/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const {
5757
getOSDetailsFromSystem,
5858
findGitConfig,
5959
getFileSeparatorData,
60-
setCrashReportingConfigFromReporter
60+
setCrashReportingConfigFromReporter,
61+
debugOnConsole
6162
} = require('../helper/helper');
6263

6364
const { consoleHolder } = require('../helper/constants');
@@ -87,13 +88,15 @@ class MyReporter {
8788
})
8889

8990
.on(EVENT_HOOK_BEGIN, async (hook) => {
91+
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN`);
9092
if(this.testObservability == true) {
9193
if(!hook.hookAnalyticsId) {
9294
hook.hookAnalyticsId = uuidv4();
9395
} else if(this.runStatusMarkedHash[hook.hookAnalyticsId]) {
9496
delete this.runStatusMarkedHash[hook.hookAnalyticsId];
9597
hook.hookAnalyticsId = uuidv4();
9698
}
99+
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN for uuid: ${hook.hookAnalyticsId}`);
97100
hook.hook_started_at = (new Date()).toISOString();
98101
hook.started_at = (new Date()).toISOString();
99102
this.current_hook = hook;
@@ -102,6 +105,7 @@ class MyReporter {
102105
})
103106

104107
.on(EVENT_HOOK_END, async (hook) => {
108+
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_END`);
105109
if(this.testObservability == true) {
106110
if(!this.runStatusMarkedHash[hook.hookAnalyticsId]) {
107111
if(!hook.hookAnalyticsId) {
@@ -114,6 +118,9 @@ class MyReporter {
114118

115119
// Remove hooks added at hook start
116120
delete this.hooksStarted[hook.hookAnalyticsId];
121+
122+
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_END for uuid: ${hook.hookAnalyticsId}`);
123+
117124
await this.sendTestRunEvent(hook,undefined,false,"HookRunFinished");
118125
}
119126
}
@@ -123,7 +130,9 @@ class MyReporter {
123130
})
124131

125132
.on(EVENT_TEST_PASS, async (test) => {
133+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PASS`);
126134
if(this.testObservability == true) {
135+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`);
127136
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
128137
if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true;
129138
await this.sendTestRunEvent(test);
@@ -132,7 +141,9 @@ class MyReporter {
132141
})
133142

134143
.on(EVENT_TEST_FAIL, async (test, err) => {
144+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_FAIL`);
135145
if(this.testObservability == true) {
146+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`);
136147
if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) {
137148
if(test.testAnalyticsId) {
138149
this.runStatusMarkedHash[test.testAnalyticsId] = true;
@@ -146,8 +157,10 @@ class MyReporter {
146157
})
147158

148159
.on(EVENT_TEST_PENDING, async (test) => {
160+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PENDING`);
149161
if(this.testObservability == true) {
150162
if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4();
163+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`);
151164
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
152165
this.runStatusMarkedHash[test.testAnalyticsId] = true;
153166
await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped");
@@ -156,13 +169,17 @@ class MyReporter {
156169
})
157170

158171
.on(EVENT_TEST_BEGIN, async (test) => {
172+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN`);
173+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
159174
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
160175
if(this.testObservability == true) {
161176
await this.testStarted(test);
162177
}
163178
})
164179

165180
.on(EVENT_TEST_END, async (test) => {
181+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_END`);
182+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
166183
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
167184
if(this.testObservability == true) {
168185
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
@@ -174,10 +191,12 @@ class MyReporter {
174191

175192
.once(EVENT_RUN_END, async () => {
176193
try {
194+
debugOnConsole(`[MOCHA EVENT] EVENT_RUN_END`);
177195
if(this.testObservability == true) {
178196
const hookSkippedTests = getHookSkippedTests(this.runner.suite);
179197
for(const test of hookSkippedTests) {
180198
if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4();
199+
debugOnConsole(`[MOCHA EVENT] EVENT_RUN_END TestRunSkipped for uuid: ${test.testAnalyticsId}`);
181200
await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped");
182201
}
183202
}
@@ -318,6 +337,8 @@ class MyReporter {
318337
}
319338
};
320339

340+
debugOnConsole(`${eventType} for uuid: ${testData.uuid}`);
341+
321342
if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) {
322343
testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps));
323344
this.currentTestCucumberSteps = [];
@@ -377,6 +398,7 @@ class MyReporter {
377398
mapTestHooks(test);
378399
}
379400
} catch(e) {
401+
debugOnConsole(`Exception in processing hook data for event ${eventType} with error : ${e}`);
380402
debug(`Exception in processing hook data for event ${eventType} with error : ${e}`, true, e);
381403
}
382404

@@ -473,6 +495,7 @@ class MyReporter {
473495
this.hooksStarted = {};
474496
}
475497
} catch(error) {
498+
debugOnConsole(`Exception in populating test data for event ${eventType} with error : ${error}`);
476499
debug(`Exception in populating test data for event ${eventType} with error : ${error}`, true, error);
477500
}
478501
}

0 commit comments

Comments
 (0)