Conversation
feat: logs proxy using sw feat: logs proxy using sw
Changed Files
|
| try { | ||
| let bodyStr = logs->JSON.Encode.array->JSON.stringify | ||
| let response = await Fetch.fetch( | ||
| GlobalVars.logEndpoint, |
There was a problem hiding this comment.
Should we take derived endpoint in args and try to keep sw isolated?
Code Review by opencodeStatus: PR: feat: logs proxy using sw SummaryThe PR introduces a Service Worker-based log proxy so that SDK iframe logs can be sent via The architecture is sound: merchant-page logs continue via Beacon API (SW won't be registered on the merchant domain), while iframe logs go through the SW when available, with Beacon API as fallback. 🚨 Critical Issues (Must Fix)1. 2. Fire-and-forget dual sends in 3.
|
fixes: #1446
Type of Change
Description
Implements a Service Worker-based log proxy mechanism that enables reliable log transmission from the SDK iframe to the logging backend. The Service Worker acts as a middleman that can continue sending logs even when the iframe is unloaded
Problem Statement
navigator.sendBeacon()which has reliability issuesMerchant Page Logs (Hyper.res) - Always Beacon API
SDK Iframe Logs (Index.res) - Service Worker
Bug fixes
1. Race Condition in iDB Retrieve + Clear
Problem:
sendCachedLogsFromIDBused separateretrieveLogsFromIndexedDB()andclearLogsFromIndexedDB()calls. Logs added between these operations could be lost or cause duplicates.Fix: Created
retrieveAndClearLogsFromIndexedDB()- atomic operation using single readwrite transaction.File:
src/Utilities/LoggerUtils.res2. Race Condition in sendLogsToIndexedDB
Problem: Same as above - new logs added during
await saveLogsToIndexedDB()were cleared without being saved.Fix: Same pattern - snapshot + clear before async.
File:
src/hyper-log-catcher/HyperLogger.resHow did you test it?
Tested locally
Checklist
npm run re:build