Skip to content

♻️ Guard RUM collection when browser globals are unavailable - #5140

Merged
BeltranBulbarellaDD merged 34 commits into
mainfrom
beltran.bulbarella/shopify-regular-sdk
Nov 18, 2026
Merged

BeltranBulbarellaDD merged 34 commits into
mainfrom
beltran.bulbarella/shopify-regular-sdk

Conversation

@BeltranBulbarellaDD

@BeltranBulbarellaDD BeltranBulbarellaDD commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Shared helpers and RUM collectors assume window and document are available. In a Web Worker (e.g. the Shopify App Pixels sandbox), those globals are missing and these accesses throw, even when the underlying API exists on the global object. Read available APIs through globalObject, and skip page-only features where they start, so RUM keeps running and those features report nothing.

Changes

  • Read browser APIs through globalObject when they also exist in workers: performance, PerformanceObserver, location, requestIdleCallback, ReportingObserver, EventTarget, and the synthetics / Cypress test context.
  • addEventListener(s) and instrumentMethod still require a target. Callers check for a missing window themselves, once at the top of each page-only feature: window open, location change, page state history and display context.
  • Without a document:
    • startResourceCollection doesn't report the navigation resource.
    • the DOM mutation observable never emits.
    • the cookie watch fallback doesn't start, because getCookie() reads document.cookie.
    • readiness callbacks (runOnReadyState) run immediately.
  • New public export shopifyAppPixelPlugin on the rum-shopify bundle (DD_RUM.shopifyAppPixelPlugin()). It sets the configuration that works without a page: manual views, no user interactions, resources, long tasks, Session Replay or profiling, in-memory session persistence, and trackViewMetricsManually so no automatic view metrics (loading, navigation timings, web vitals) are collected.
  • preStartRum no longer rejects a worker environment when the shopify-app-pixel plugin is configured. Other worker setups still get the "not supported" warning.
  • E2E framework: createWorker({ dedicated: true }) runs the worker with new Worker(), withRum(config, { sdk }) picks the bundle, and withRumInit() customizes the init call. The worker setup turns on SDK debug mode so errors caught by the SDK monitor fail the test.

Test instructions

  • New e2e test Web workers Rum › dedicated web worker with worker rum: starts the rum-shopify bundle in a dedicated worker with shopifyAppPixelPlugin(), starts a view manually and expects a view event. The title avoids "shopify" because PR e2e jobs skip those tests (they only run on a schedule, against a live store).

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 192.54 KiB 192.89 KiB +354 B +0.18% ✅
Rum 192.52 KiB 192.87 KiB +354 B +0.18% ✅
Rum Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Rum Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Logs 60.26 KiB 60.23 KiB -28 B -0.05% ✅
Rum Slim 148.45 KiB 148.69 KiB +252 B +0.17% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 223.58 KiB 224.23 KiB +657 B +0.29% ✅
Rum Shopify Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 70.00%
• Overall Coverage: 77.99% (-0.11%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: edf91da | Docs | View more details | Give us feedback!

@BeltranBulbarellaDD BeltranBulbarellaDD changed the title 🐛 Allow memory-backed RUM initialization in workers 🐛 Guard browser globals in RUM worker environments Oct 14, 2026
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title 🐛 Guard browser globals in RUM worker environments ♻️ Guard browser globals in RUM worker environments Oct 14, 2026
@BeltranBulbarellaDD

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T16:52:29.039498Z edf91da New commits
🔒 Security Review ✅ Completed 2026-11-12T16:54:20.359231Z edf91da New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 51655f6a0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 51655f6a0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@BeltranBulbarellaDD BeltranBulbarellaDD changed the title ♻️ Guard browser globals in RUM worker environments ♻️ Guard RUM collection when browser globals are unavailable Oct 14, 2026
@BeltranBulbarellaDD
BeltranBulbarellaDD marked this pull request as ready for review October 14, 2026 14:37
@BeltranBulbarellaDD
BeltranBulbarellaDD requested a review from a team as a code owner October 14, 2026 14:37

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The guards preserve browser collection paths while skipping DOM-dependent work when globals are absent. Full RUM initialization in workers remains outside this change’s scope.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 51655f6

@BeltranBulbarellaDD
BeltranBulbarellaDD marked this pull request as draft October 19, 2026 15:37
@BeltranBulbarellaDD
BeltranBulbarellaDD marked this pull request as ready for review October 20, 2026 13:31

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The completed static review found no actionable regression in the missing-global guards. End-to-end RUM initialization in workers remains outside the validated scope.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7a57829

@BeltranBulbarellaDD
BeltranBulbarellaDD changed the base branch from main to beltran.bulbarella/round-clocks-origin October 30, 2026 17:56

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Worker startup requires automatic interaction tracking to be disabled. PR discussion explicitly assigns this to Web Pixels configuration, and the new worker scenario follows that constraint.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3ab1605

Base automatically changed from beltran.bulbarella/round-clocks-origin to main November 3, 2026 16:10
…opify-regular-sdk

# Conflicts:
#	packages/browser-core/src/browser/cookie.ts

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Worker support relies on disabling page-only collection, including automatic interaction tracking. This matches the Shopify configuration and the explicit scope agreed in the PR discussion.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3ab1605

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a182e9801

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

BeltranBulbarellaDD and others added 3 commits November 3, 2026 18:15
Firefox reports the `event` entry type as supported in workers, so the
check reached `window.PerformanceEventTiming` and threw, preventing any
view from being created. Use `globalObject` instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Skip the sandboxed iframe patches (they access `document`) and use memory
persistence (no cookies) when running in a worker. Also reword the worker
guard comment to say Shopify is expected to run in a worker in the future.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the internal `betaTrackViewMetrics` option (default true) and gate
initial, route change and common view metrics (scroll, CLS, INP) on it,
instead of checking for `globalObject.document`. Loading time and manual
`setViewLoadingTime()` are always kept. The Shopify plugin disables it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a85bbb4eef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…opify-regular-sdk

# Conflicts:
#	packages/browser-rum-core/src/domain/view/trackViews.ts
#	packages/browser-rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts
@BeltranBulbarellaDD
BeltranBulbarellaDD force-pushed the beltran.bulbarella/shopify-regular-sdk branch from a85bbb4 to 7bed9d8 Compare November 5, 2026 10:26
BeltranBulbarellaDD and others added 2 commits November 5, 2026 11:37
The load event is only reported by trackInitialViewMetrics, which is
skipped when `betaTrackViewMetrics` is false, so the activity-based
loading time of initial views was never reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Manually

INP support is only checked by trackInteractionToNextPaint, which is
skipped when `betaTrackViewMetrics` is false, and onBFCacheRestore only
runs when views are tracked automatically. Both files match main again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BeltranBulbarellaDD
BeltranBulbarellaDD force-pushed the beltran.bulbarella/shopify-regular-sdk branch from 5c0b019 to 130c052 Compare November 5, 2026 10:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 130c052662

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/e2e/lib/framework/createTest.ts Resolved
Skip the navigation resource in startResourceCollection when there is
no document, and restore getNavigationEntry to always return an entry.
Its other callers (LCP, navigation timings) only run with view metrics,
so they no longer need to handle a missing entry.
Add shopifyAppPixelPlugin, which forces the configuration RUM needs in
the Shopify app Web Pixel worker (manual views, memory persistence, no
view metrics, no DOM-based features), and only allow RUM to start in a
worker when this plugin is used.

Restore shopifyPlugin to its main version, so existing consumers are
not affected. The dedicated worker e2e now initializes RUM with the new
plugin, through a worker `withRumInit()` mirroring the page one.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddde5c4e44

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

refs: RUM-18788

Resolve conflicts with the view metrics opt-out by keeping main's
trackViewMetricsManually option, dropping trackAutomaticViewMetrics,
and switching the Shopify plugin to the new option.
@BeltranBulbarellaDD
BeltranBulbarellaDD merged commit 48e6567 into main Nov 18, 2026
32 checks passed
@BeltranBulbarellaDD
BeltranBulbarellaDD deleted the beltran.bulbarella/shopify-regular-sdk branch November 18, 2026 16:31
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 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