From 280cf04c35382260e6fa3b94708badb6b57cf53e Mon Sep 17 00:00:00 2001 From: Anish Sinha Date: Tue, 5 May 2026 13:25:44 +0530 Subject: [PATCH 1/3] capture cy.log at enqueue time so logs survive --- bin/testObservability/cypress/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/cypress/index.js b/bin/testObservability/cypress/index.js index dfdc27e2..e9cdf398 100644 --- a/bin/testObservability/cypress/index.js +++ b/bin/testObservability/cypress/index.js @@ -201,7 +201,10 @@ 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') { @@ -213,12 +216,16 @@ Cypress.Commands.overwrite('log', (originalFn, ...args) => { 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); }); From a2c87e6e7451c07367005a3b52adce65519c37ae Mon Sep 17 00:00:00 2001 From: Anish Sinha Date: Tue, 5 May 2026 13:54:32 +0530 Subject: [PATCH 2/3] updated code --- bin/testObservability/cypress/index.js | 10 ++-------- bin/testObservability/reporter/index.js | 4 +++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/testObservability/cypress/index.js b/bin/testObservability/cypress/index.js index e9cdf398..b4c760cd 100644 --- a/bin/testObservability/cypress/index.js +++ b/bin/testObservability/cypress/index.js @@ -201,10 +201,7 @@ Cypress.on('command:end', (command) => { }); }); -Cypress.on('command:enqueued', (attrs) => { - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return; - if (!attrs || attrs.name !== 'log') return; - const args = attrs.args || []; +Cypress.Commands.overwrite('log', (originalFn, ...args) => { if (args.includes('test_observability_log') || args.includes('test_observability_command')) return; const message = args.reduce((result, logItem) => { if (typeof logItem === 'object') { @@ -216,16 +213,13 @@ Cypress.on('command:enqueued', (attrs) => { 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', From 30db980d6f9699196c5afdb2ebabf421a287a4e3 Mon Sep 17 00:00:00 2001 From: Anish Sinha Date: Tue, 5 May 2026 15:39:59 +0530 Subject: [PATCH 3/3] updated code --- bin/testObservability/cypress/index.js | 10 ++++++++-- bin/testObservability/reporter/index.js | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/testObservability/cypress/index.js b/bin/testObservability/cypress/index.js index b4c760cd..e9cdf398 100644 --- a/bin/testObservability/cypress/index.js +++ b/bin/testObservability/cypress/index.js @@ -201,7 +201,10 @@ 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') { @@ -213,13 +216,16 @@ Cypress.Commands.overwrite('log', (originalFn, ...args) => { 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 219a593c..4a6c04b8 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -631,9 +631,7 @@ 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) { - log.test_run_uuid = this.current_test.testAnalyticsId; - } + 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 || log.test_run_uuid) { await uploadEventData({ event_type: 'LogCreated',