Skip to content
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

GitAuto: makeBrowserOfflineTransport no longer adds types to transportOptions #16

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 within its transportOptions type definition. This change leads to TypeScript errors when developers attempt to use flushAtStartup, as it is not recognized as a valid property of Partial<BrowserTransportOptions>.

How to reproduce

  1. Upgrade Sentry SDK: Update the Sentry SDK from version 7.60.0 to 8.33.1.
  2. Initialize Sentry with Transport Options:
    import * as Sentry from '@sentry/vue';
    import { Capacitor } from '@capacitor/core';
    import type { App } from 'vue';
    
    export default function setupSentry(app: App) {
        Sentry.init({
            app,
            dsn: __SENTRY_DSN__,
            enabled: true,
            release: __APP_VERSION__,
            dist: __APP_VERSION__ + (Capacitor.isNativePlatform() ? '-native' : '-web'),
            transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),
            transportOptions: {
                flushAtStartup: true,
            },
            logErrors: true,
            tracesSampleRate: 0,
            autoSessionTracking: false,
            sendClientReports: false,
        });
    }
  3. TypeScript Compilation: Attempt to compile the project, resulting in the following error:
    Object literal may only specify known properties, and 'flushAtStartup' does not exist in type 'Partial<BrowserTransportOptions>'.
    

How to fix

To resolve this issue, update the type definitions for BrowserTransportOptions to include the flushAtStartup property. This ensures that makeBrowserOfflineTransport recognizes and accepts flushAtStartup without causing TypeScript errors.

Steps:

  1. Update Type Definitions:

    • Locate the type definition file for BrowserTransportOptions within the Sentry SDK.
    • Add the flushAtStartup property to the BrowserTransportOptions interface:
      interface BrowserTransportOptions {
          // existing properties
          flushAtStartup?: boolean;
      }
  2. Modify makeBrowserOfflineTransport Function:

    • Ensure that the makeBrowserOfflineTransport function correctly handles the flushAtStartup option.
    • Update the function implementation to utilize flushAtStartup as needed.
  3. Validate Changes:

    • Rebuild the Sentry SDK to incorporate the updated type definitions and function implementation.
    • Test the integration in a Vue project to confirm that the TypeScript error is resolved and that flushAtStartup functions as intended.

By implementing these changes, developers can continue to use the flushAtStartup option without encountering TypeScript errors, ensuring a smoother upgrade path and better type safety.

About backward compatibility

Maintaining backward compatibility is crucial to avoid breaking existing integrations. By adding the flushAtStartup property as an optional field in the BrowserTransportOptions interface, existing implementations that do not use this property will remain unaffected. This approach ensures that only code explicitly using flushAtStartup will leverage the new functionality, preserving stability for all other users.

Test these changes locally

git checkout -b gitauto-wes/issue-#3-22d7e1e7-6e7e-4ed9-aa52-3304a7620766
git pull origin gitauto-wes/issue-#3-22d7e1e7-6e7e-4ed9-aa52-3304a7620766

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