File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,10 +205,10 @@ Cypress.on('command:end', (command) => {
205205 * cy.log capture must happen at command-enqueue time, not command-execute time.
206206 * If a test body throws synchronously (e.g. a failing chai assertion) before the
207207 * Cypress queue drains, queued commands are dropped — so an execute-time wrapper
208- * never fires and pre-throw cy.log calls are lost from the timeline. Hooking
209- * command:enqueue runs synchronously at the user's cy.log() call site.
208+ * never fires and pre-throw cy.log calls are lost from the timeline. The
209+ * command:enqueued event runs synchronously at the user's cy.log() call site.
210210 */
211- Cypress . on ( 'command:enqueue ' , ( attrs ) => {
211+ Cypress . on ( 'command:enqueued ' , ( attrs ) => {
212212 if ( ! Cypress . env ( 'BROWSERSTACK_O11Y_LOGS' ) ) return ;
213213 if ( ! attrs || attrs . name !== 'log' ) return ;
214214 const args = attrs . args || [ ] ;
Original file line number Diff line number Diff line change @@ -628,10 +628,24 @@ class MyReporter {
628628
629629 appendTestItemLog = async ( log ) => {
630630 try {
631+ /*
632+ * SDK-5709: keep the hash gate on hook side (avoids attributing a log to
633+ * a stale hook pointer between hooks). Drop it on the test side. In
634+ * Cypress, EVENT_TEST_FAIL fires synchronously when a test body throws
635+ * — *before* afterEach runs. The SDK's internal afterEach flushes its
636+ * cy.log buffer via cy.task during afterEach, so by the time those logs
637+ * reach this listener, runStatusMarkedHash[testAnalyticsId] is already
638+ * set and the log gets dropped without ever attaching a test_run_uuid.
639+ * Without the gate, the log uploads with test_run_uuid even after
640+ * TestRunFinished — accepted by the analytics backend (uploadTestSteps
641+ * takes the same path with no gate).
642+ */
631643 if ( this . current_hook && ( this . current_hook . hookAnalyticsId && ! this . runStatusMarkedHash [ this . current_hook . hookAnalyticsId ] ) ) {
632644 log . hook_run_uuid = this . current_hook . hookAnalyticsId ;
633645 }
634- 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 ;
646+ if ( ! log . hook_run_uuid && this . current_test && this . current_test . testAnalyticsId ) {
647+ log . test_run_uuid = this . current_test . testAnalyticsId ;
648+ }
635649 if ( log . hook_run_uuid || log . test_run_uuid ) {
636650 await uploadEventData ( {
637651 event_type : 'LogCreated' ,
You can’t perform that action at this time.
0 commit comments