Skip to content

Commit

Permalink
options in setup, dont upload sources, upload debug symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Dec 16, 2024
1 parent d3ae482 commit fce1ddd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
41 changes: 32 additions & 9 deletions src/flutter/code-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
initSnippet,
} from './templates';
import { fetchSdkVersion } from '../utils/release-registry';
import { featureSelectionPrompt } from '../utils/clack-utils';

/**
* Recursively finds a file per name in subfolders.
Expand Down Expand Up @@ -149,7 +150,9 @@ export function addProperties(pubspecFile: string | null, authToken: string) {
}
}

export function patchMain(mainFile: string | null, dsn: string): boolean {


export async function patchMain(mainFile: string | null, dsn: string): Promise<boolean> {
if (!mainFile || !fs.existsSync(mainFile)) {
clack.log.warn('No main.dart source file found in filesystem.');
Sentry.captureException('No main.dart source file');
Expand All @@ -169,8 +172,8 @@ export function patchMain(mainFile: string | null, dsn: string): boolean {
);
return true;
}

mainContent = patchMainContent(dsn, mainContent);
mainContent = await patchMainContent(dsn, mainContent);

fs.writeFileSync(mainFile, mainContent, 'utf8');

Expand All @@ -185,23 +188,43 @@ export function patchMain(mainFile: string | null, dsn: string): boolean {
return true;
}

export function patchMainContent(dsn: string, mainContent: string): string {
export async function patchMainContent(dsn: string, mainContent: string): Promise<string> {

const importIndex = getLastImportLineLocation(mainContent);
mainContent = mainContent.slice(0, importIndex) +
sentryImport +
mainContent.slice(importIndex);

const selectedFeatures = await featureSelectionPrompt([
{
id: 'tracing',
prompt: `Do you want to enable ${chalk.bold(
'Tracing',
)} to track the performance of your application?`,
enabledHint: 'recommended',
},
{
id: 'profiling',
prompt: `Do you want to enable ${chalk.bold(
'Profiling',
)} to analyze CPU usage and optimize performance-critical code?`,
enabledHint: 'recommended, tracing must be enabled',
},
{
id: 'replay',
prompt: `Do you want to enable ${chalk.bold(
'Sentry Session Replay',
)} to get reproduction of frontend errors via user sessions?`,
enabledHint: 'recommended, but increases bundle size',
},
] as const);

// Find and replace `runApp(...)`
mainContent = mainContent.replace(
/runApp\(([\s\S]*?)\);/g, // Match the `runApp(...)` invocation
(_, runAppArgs) => initSnippet(
dsn,
{
tracing: true,
profiling: true,
replay: true,
},
selectedFeatures,
runAppArgs as string
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/flutter/flutter-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function runFlutterWizardWithTelemetry(
const mainFile = findFile(projectDir, 'main.dart');
const dsn = selectedProject.keys[0].dsn.public;

const mainPatched = traceStep('Patch main.dart', () =>
const mainPatched = await traceStep('Patch main.dart', () =>
codetools.patchMain(mainFile, dsn),
);
if (!mainPatched) {
Expand Down
2 changes: 1 addition & 1 deletion src/flutter/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const sentryImport = `import 'package:sentry_flutter/sentry_flutter.dart'

export function pubspecOptions(project: string, org: string): string {
return `sentry:
upload_debug_symbols: true
upload_source_maps: true
upload_sources: true
project: ${project}
org: ${org}
`
Expand Down
2 changes: 1 addition & 1 deletion test/flutter/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('Flutter code templates', () => {
);
expect(template).toMatchInlineSnapshot(`
"sentry:
upload_debug_symbols: true
upload_source_maps: true
upload_sources: true
project: fixture-project
org: fixture-org
"
Expand Down

0 comments on commit fce1ddd

Please sign in to comment.