Skip to content

🐛 tolerate Cypress.env throwing under allowCypressEnv: false#4550

Merged
bcaudan merged 1 commit intomainfrom
bcaudan/cypress
Apr 30, 2026
Merged

🐛 tolerate Cypress.env throwing under allowCypressEnv: false#4550
bcaudan merged 1 commit intomainfrom
bcaudan/cypress

Conversation

@bcaudan
Copy link
Copy Markdown
Collaborator

@bcaudan bcaudan commented Apr 30, 2026

Motivation

A telemetry error is observed in customer data:

CypressError: Cypress.env() does not work when allowCypressEnv is set to false. ... The variable being accessed was: traceId

The SDK reads window.Cypress.env('traceId') at boot in ciVisibilityContext.ts as a secondary transport for the CI Visibility test execution id (the primary is the datadog-ci-visibility-test-execution-id cookie). Under Cypress 15.10+ with allowCypressEnv: false, the call itself throws regardless of whether a value was set.

The legacy env path is still used: it serves customers on dd-trace-js < 5.88.0 (where the plugin still wrote via Cypress.env). Removing the read would silently break correlation for them.

Changes

  • Wrap the Cypress.env('traceId') read in try/catch in ciVisibilityContext.ts so the throw no longer bubbles up
  • Emit a display.warn(...) only when the env read actually throws, prompting customers to upgrade dd-trace-js >= 5.88.0 (the version that switched the writer to the cookie via dd-trace-js#7600).

Test instructions

  • yarn test:unit --spec packages/rum-core/src/domain/contexts/ciVisibilityContext.spec.ts — 9 specs pass (5 existing + 4 new).

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

Swallow the throw and warn customers to upgrade dd-trace-js to >= 5.88.0 so RUM ↔ test correlation keeps working as Cypress moves toward removing Cypress.env.
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented Apr 30, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 179.26 KiB 179.43 KiB +170 B +0.09%
Rum Profiler 6.17 KiB 6.17 KiB 0 B 0.00%
Rum Recorder 27.03 KiB 27.03 KiB 0 B 0.00%
Logs 56.67 KiB 56.67 KiB 0 B 0.00%
Rum Slim 135.13 KiB 135.29 KiB +167 B +0.12%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0077 0.0067 -12.99%
RUM - add action 0.0234 0.0196 -16.24%
RUM - add error 0.0226 0.0179 -20.80%
RUM - add timing 0.0048 0.0042 -12.50%
RUM - start view 0.0194 0.0173 -10.82%
RUM - start/stop session replay recording 0.0013 0.001 -23.08%
Logs - log message 0.0262 0.0221 -15.65%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 32.33 KiB 32.01 KiB -327 B
RUM - add action 107.66 KiB 105.51 KiB -2.15 KiB
RUM - add timing 32.27 KiB 31.84 KiB -445 B
RUM - add error 92.08 KiB 97.48 KiB +5.40 KiB
RUM - start/stop session replay recording 32.31 KiB 30.76 KiB -1.54 KiB
RUM - start view 494.14 KiB 483.60 KiB -10.54 KiB
Logs - log message 106.69 KiB 93.84 KiB -12.85 KiB

🔗 RealWorld

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 30, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 81.82%
Overall Coverage: 77.04% (+0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ac47794 | Docs | Datadog PR Page | Give us feedback!

@bcaudan bcaudan marked this pull request as ready for review April 30, 2026 10:00
@bcaudan bcaudan requested a review from a team as a code owner April 30, 2026 10:00
@bcaudan bcaudan merged commit 572debd into main Apr 30, 2026
22 checks passed
@bcaudan bcaudan deleted the bcaudan/cypress branch April 30, 2026 12:07
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants