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

feat(flutter): Add Flutter support #735

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

denrase
Copy link

@denrase denrase commented Dec 3, 2024

  • Add flutter as a platform
  • Patch main.dart with import, sentry setup and sample snippet
  • Patch pubspec.yaml with sentry_flutter dependency and plugin to upload debug symbols and source maps

Closes getsentry/sentry-dart#2424
Relates to #558

@denrase denrase changed the title WIP: Flutter Support Add Flutter support Dec 9, 2024
@denrase denrase changed the title Add Flutter support feat(flutter): Add Flutter support Dec 9, 2024
@denrase denrase marked this pull request as ready for review December 9, 2024 13:57
@denrase
Copy link
Author

denrase commented Dec 9, 2024

@buenaflor Ready for the first review/feedback round :)

Copy link

@buenaflor buenaflor left a comment

Choose a reason for hiding this comment

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

I'll have another look later

src/flutter/flutter-wizzard.ts Outdated Show resolved Hide resolved
src/flutter/flutter-wizzard.ts Outdated Show resolved Hide resolved
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Hey, leaving a first pass review for general wizard recommendations. This is not technical as I have very little to no context around Flutter.

  • Ideally, we can make the SDK features selectable from the start as we've done recently with the JS-SDK wizards. See Make Sentry features selectable in wizard #558
  • Great to see some tests for this flow! :) I recommend adding an e2e test app as well as this proved quite useful for our other wizards.

Feel free to disregard my advice as I'll happily leave the final call to the mobile team. Don't want to block you, just share some recommendations :)

@denrase denrase requested a review from smeubank December 19, 2024 10:20
@denrase denrase requested a review from Lms24 December 19, 2024 10:20
@denrase
Copy link
Author

denrase commented Dec 19, 2024

@bruno-garcia We have added replay as an option, but we are not sure if we should, as it is still beta on Flutter. Do you have any guidance/thoughts?

@denrase
Copy link
Author

denrase commented Dec 30, 2024

Removed the Replay option for now, as this is still considered bet on Flutter/Mobile.

@denrase denrase requested a review from buenaflor December 30, 2024 15:40
@buenaflor
Copy link

@krystofwoldrich could you also have a quick look since you already have quite some rn wizard exp :)

@denrase
Copy link
Author

denrase commented Jan 9, 2025

Profiling is now only asked as an option in the flutter wizard if we have an ios/macos folder. Also added tests for this.

appRunner: () => runApp(${runApp}),
);
// TODO: Remove this line after sending the first sample event to sentry.
await Sentry.captureMessage('This is a sample exception.');`;

Choose a reason for hiding this comment

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

Suggested change
await Sentry.captureMessage('This is a sample exception.');`;
await Sentry.captureException(Exception('This is a sample exception.'));`;

@buenaflor
Copy link

@denrase e2e test is failing

return withTelemetry(
{
enabled: options.telemetryEnabled,
integration: 'android',
Copy link
Member

Choose a reason for hiding this comment

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

This is the integration name reported to Sentry Telemetry.

Suggested change
integration: 'android',
integration: 'flutter',

await getOrAskForProjectData(options, 'flutter');

const projectDir = process.cwd();
const pubspecFile = findFile(projectDir, 'pubspec.yaml');
Copy link
Member

@krystofwoldrich krystofwoldrich Jan 13, 2025

Choose a reason for hiding this comment

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

I believe we should not look for this file, if the user is in a directory without pubspec.yaml, likely they are not in root of the project they want to patch.

We should handle the missing pubspecFile and let user know they are not in Flutter project dir.

);
if (!pubspecPatched) {
clack.log.warn(
"Could not add Sentry to your apps pubspec.yaml file. You'll have to add it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/flutter/#install",
Copy link
Member

Choose a reason for hiding this comment

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

Let me know if it's out of scope, but the other wizards show code pastable code snippets so users don't have to leave the wizard and look online for the code.

Example from RN:

await showCopyPasteInstructions(
'App.js or _layout.tsx',
getSentryInitColoredCodeSnippet(dsn),
'This ensures the Sentry SDK is ready to capture errors.',
);

);
if (!propertiesAdded) {
clack.log.warn(
`We could not add "sentry.properties" file in your project directory in order to provide an auth token for Sentry CLI. You'll have to add it manually, or you can set the SENTRY_AUTH_TOKEN environment variable instead. See https://docs.sentry.io/cli/configuration/#auth-token for more information.`,
Copy link
Member

Choose a reason for hiding this comment

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

Usually filenames are highlighted by cyan.

Wizard Develop docs describe the use of colors.

https://develop.sentry.dev/sdk/expected-features/setup-wizards/#colors

fs.existsSync(`${projectDir}/ios`) || fs.existsSync(`${projectDir}/macos`);

const mainPatched = await traceStep('Patch main.dart', () =>
codetools.patchMain(mainFile, dsn, canEnableProfiling),
Copy link
Member

@krystofwoldrich krystofwoldrich Jan 13, 2025

Choose a reason for hiding this comment

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

If we can't patch the mainFile we should show a copy pastable code snippet.

Comment on lines +47 to +52
if (!pubspecFile || !fs.existsSync(pubspecFile)) {
clack.log.warn('No pubspec.yaml source file found in filesystem.');
Sentry.captureException('No pubspec.yaml source file');
return false;
}
let pubspecContent = fs.readFileSync(pubspecFile, 'utf8');
Copy link
Member

Choose a reason for hiding this comment

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

It's better practice to try catch the readFile instead of checking for existence. The read might still throw and this would crash the wizard.

chalk.greenBright(
`${chalk.bold(
'main.dart',
)} is already patched with test error snippet.`,
Copy link
Member

Choose a reason for hiding this comment

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

It's maybe better to call out that Sentry is already in the main.dart instead of the test error.

const { selectedProject, selfHosted, sentryUrl, authToken } =
await getOrAskForProjectData(options, 'flutter');

const projectDir = process.cwd();
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it applies (if it's common users have old outdated apps), but we could check min dart and flutter versions before the wizard starts patching.

@krystofwoldrich
Copy link
Member

Added some comments based on my experience with RN Wizard.

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

Successfully merging this pull request may close these issues.

Add sentry wizard support
5 participants