Skip to content

Commit

Permalink
enh(android): Add more telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Sep 8, 2023
1 parent 523b7fa commit 956f396
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/android/android-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
// @ts-ignore - clack is ESM and TS complains about that. It works though
import * as clack from '@clack/prompts';
import * as path from 'path';
import * as Sentry from '@sentry/node';
import * as gradle from './gradle';
import * as manifest from './manifest';
import * as codetools from './code-tools';
Expand Down Expand Up @@ -69,6 +70,7 @@ async function runAndroidWizardWithTelemetry(
clack.log.error(
'No Gradle project found. Please run this command from the root of your project.',
);
Sentry.captureException('No Gradle project found');
await abort();
return;
}
Expand Down Expand Up @@ -100,6 +102,7 @@ async function runAndroidWizardWithTelemetry(
"Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install",
);
}
Sentry.setTag('gradle-plugin-added', pluginAdded)

// ======== STEP 2. Configure Sentry SDK via AndroidManifest ============
clack.log.step(
Expand All @@ -119,6 +122,7 @@ async function runAndroidWizardWithTelemetry(
"Could not configure the Sentry SDK. You'll have to do it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure",
);
}
Sentry.setTag('android-manifest-updated', manifestUpdated)

// ======== STEP 3. Patch Main Activity with a test error snippet ============
clack.log.step(
Expand All @@ -133,10 +137,13 @@ async function runAndroidWizardWithTelemetry(
packageName = gradle.getNamespace(appFile);
}
const activityName = mainActivity.activityName;
Sentry.setTag('has-activity-name', !!activityName)
Sentry.setTag('has-package-name', !!packageName)
if (!activityName || !packageName) {
clack.log.warn(
"Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify",
);
Sentry.captureException('Could not find Main Activity')
} else {
const packageNameStable = packageName;
const activityFile = traceStep('Find Main Activity Source File', () =>
Expand All @@ -151,6 +158,7 @@ async function runAndroidWizardWithTelemetry(
"Could not patch main activity. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify",
);
}
Sentry.setTag('main-activity-patched', activityPatched)
}

// ======== STEP 4. Add sentry-cli config file ============
Expand Down
10 changes: 9 additions & 1 deletion src/android/gradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ export async function selectAppFile(

if (appFiles.length === 0) {
Sentry.setTag('custom-build-logic', true);
const appFile = await abortIfCancelled(
let appFile = await abortIfCancelled(
clack.text({
message: `Unable to find your app's directory.
Please enter the relative path to your app's build.gradle file from the root project (e.g. "app/build.gradle.kts")`,
}),
);
while(!appFile.includes('.gradle') || !fs.existsSync(appFile)) {
appFile = await abortIfCancelled(
clack.text({
message: `Not a valid gradle file.
Please enter the relative path to your app's build.gradle file from the root project (e.g. "app/build.gradle.kts")`,
}),
);
}
return appFile;
}

Expand Down

0 comments on commit 956f396

Please sign in to comment.