You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sendLogs() and sendOnClose() in sendLogs.ts construct HTTP headers independently with diverging logic. This causes bugs and makes adding new headers error-prone.
Function-type authHeader broken in sendOnClose — if authHeader is a callback (e.g., for token refresh), sendOnClose calls .toString() which sends the function source code as the Authorization header value
Custom headers missing from pagehide flush — headers registered via registerHeadersCallback() are never applied to the final sendOnClose flush
Authorization header works with function-type authHeader
Custom headers from registerHeadersCallback() are included
Headers from config.headers are included
Context
Pre-existing issue, exposed during review of #124. The sendOnClose path is the pagehide event handler — it fires when users close tabs or navigate away. Logs sent via this path are currently missing custom headers and have broken auth callback support.
Summary
sendLogs()andsendOnClose()insendLogs.tsconstruct HTTP headers independently with diverging logic. This causes bugs and makes adding new headers error-prone.Current Divergence
sendLogs()sendOnClose()Content-TypeAuthorization(string)Authorization(function callback).toString()→ sends function source codex-api-key(#124)config.headers(custom)updateAuthHeader()updateCustomHeaders()Three bugs from this divergence
authHeaderbroken insendOnClose— ifauthHeaderis a callback (e.g., for token refresh),sendOnClosecalls.toString()which sends the function source code as theAuthorizationheader valueregisterHeadersCallback()are never applied to the finalsendOnCloseflushapiKeyin feat(auth): add support for api keys #124) requires changes to both functionsProposed Fix
Extract a shared
buildHeaders(config): Headershelper:Both
sendLogs()andsendOnClose()callbuildHeaders(config).Testing
Add tests for
sendOnClosethat verify:x-api-keyheader is present (test exists after feat(auth): add support for api keys #124)Authorizationheader works with function-typeauthHeaderregisterHeadersCallback()are includedconfig.headersare includedContext
Pre-existing issue, exposed during review of #124. The
sendOnClosepath is thepagehideevent handler — it fires when users close tabs or navigate away. Logs sent via this path are currently missing custom headers and have broken auth callback support.