Skip to content

GitAuto: makeBrowserOfflineTransport no longer adds types to transportOptions #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

gitauto-for-dev[bot]
Copy link

Resolves #3

Why the bug occurs

In version 8.33.1 of the Sentry SDK, the makeBrowserOfflineTransport function no longer includes the flushAtStartup property in the transportOptions type definition. This omission causes TypeScript to throw an error when flushAtStartup is specified, as it is not recognized within the Partial<BrowserTransportOptions> type. The regression from version 7.60.0 disrupts existing implementations that rely on this option for ensuring that pending events are flushed when the application starts.

How to reproduce

  1. Upgrade the Sentry SDK from version 7.60.0 to 8.33.1.
  2. Configure Sentry with makeBrowserOfflineTransport, including the flushAtStartup option in transportOptions:
    Sentry.init({
      // ...other configurations
      transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),
      transportOptions: {
        flushAtStartup: true,
      },
    });
  3. Observe the TypeScript error:
    Object literal may only specify known properties, and 'flushAtStartup' does not exist in type 'Partial<BrowserTransportOptions>'.
    

How to fix

  1. Update Type Definitions: Extend the BrowserTransportOptions interface to include the flushAtStartup property. This ensures that TypeScript recognizes flushAtStartup as a valid option.

    // In the appropriate type declaration file
    export interface BrowserOfflineTransportOptions extends BrowserTransportOptions {
      flushAtStartup?: boolean;
    }
  2. Modify Transport Creation: Ensure that makeBrowserOfflineTransport correctly utilizes the extended BrowserOfflineTransportOptions type.

    export function makeBrowserOfflineTransport(
      transport: Transport
    ): (options: BrowserOfflineTransportOptions) => Transport {
      // ...implementation
    }
  3. Validate Changes: After updating the type definitions, verify that the TypeScript error is resolved by initializing Sentry without needing to cast transportOptions.

    Sentry.init({
      // ...other configurations
      transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),
      transportOptions: {
        flushAtStartup: true,
      },
    });
  4. Add Tests: Include unit tests to ensure that flushAtStartup is correctly handled within the transport options and that no TypeScript errors occur in various configurations.

Additional Notes

  • Backward Compatibility: Since flushAtStartup was previously supported, adding it back to the type definitions restores expected functionality without breaking existing implementations.
  • Documentation Update: Update the SDK documentation to reflect the inclusion of flushAtStartup in transportOptions, providing examples and explanations for its usage.

Test these changes locally

git checkout -b gitauto-wes/issue-#3-e4e9f5b7-c00e-4d8d-a2d0-e4d4bdd112d0
git pull origin gitauto-wes/issue-#3-e4e9f5b7-c00e-4d8d-a2d0-e4d4bdd112d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

makeBrowserOfflineTransport no longer adds types to transportOptions
0 participants