diff --git a/bin/testObservability/cypress/index.js b/bin/testObservability/cypress/index.js index dfdc27e2..bb898811 100644 --- a/bin/testObservability/cypress/index.js +++ b/bin/testObservability/cypress/index.js @@ -201,24 +201,30 @@ Cypress.on('command:end', (command) => { }); }); -Cypress.Commands.overwrite('log', (originalFn, ...args) => { +Cypress.on('command:enqueued', (attrs) => { + if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return; + if (!attrs || attrs.name !== 'log') return; + const args = attrs.args || []; if (args.includes('test_observability_log') || args.includes('test_observability_command')) return; const message = args.reduce((result, logItem) => { if (typeof logItem === 'object') { return [result, JSON.stringify(logItem)].join(' '); } - return [result, logItem ? logItem.toString() : ''].join(' '); }, ''); eventsQueue.push({ task: 'test_observability_log', data: { - 'level': 'info', + level: 'info', message, timestamp: new Date().toISOString() }, options: { log: false } }); +}); + +Cypress.Commands.overwrite('log', (originalFn, ...args) => { + if (args.includes('test_observability_log') || args.includes('test_observability_command')) return; originalFn(...args); }); diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 4a6c04b8..219a593c 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -631,7 +631,9 @@ class MyReporter { if(this.current_hook && ( this.current_hook.hookAnalyticsId && !this.runStatusMarkedHash[this.current_hook.hookAnalyticsId] )) { log.hook_run_uuid = this.current_hook.hookAnalyticsId; } - if(!log.hook_run_uuid && this.current_test && ( this.current_test.testAnalyticsId && !this.runStatusMarkedHash[this.current_test.testAnalyticsId] )) log.test_run_uuid = this.current_test.testAnalyticsId; + if(!log.hook_run_uuid && this.current_test && this.current_test.testAnalyticsId) { + log.test_run_uuid = this.current_test.testAnalyticsId; + } if(log.hook_run_uuid || log.test_run_uuid) { await uploadEventData({ event_type: 'LogCreated',