123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- import {Fragment} from 'react';
- import ExternalLink from 'sentry/components/links/externalLink';
- import List from 'sentry/components/list/';
- import ListItem from 'sentry/components/list/listItem';
- import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
- import type {
- BasePlatformOptions,
- Docs,
- DocsParams,
- OnboardingConfig,
- } from 'sentry/components/onboarding/gettingStartedDoc/types';
- import {MobileBetaBanner} from 'sentry/components/onboarding/gettingStartedDoc/utils';
- import {getAndroidMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
- import {
- getReplayMobileConfigureDescription,
- getReplayVerifyStep,
- } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
- import {feedbackOnboardingCrashApiJava} from 'sentry/gettingStartedDocs/java/java';
- import {t, tct} from 'sentry/locale';
- import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
- export enum InstallationMode {
- AUTO = 'auto',
- MANUAL = 'manual',
- }
- const platformOptions = {
- installationMode: {
- label: t('Installation Mode'),
- items: [
- {
- label: t('Auto'),
- value: InstallationMode.AUTO,
- },
- {
- label: t('Manual'),
- value: InstallationMode.MANUAL,
- },
- ],
- defaultValue:
- navigator.userAgent.indexOf('Win') !== -1
- ? InstallationMode.MANUAL
- : InstallationMode.AUTO,
- },
- } satisfies BasePlatformOptions;
- type PlatformOptions = typeof platformOptions;
- type Params = DocsParams<PlatformOptions>;
- const isAutoInstall = (params: Params) =>
- params.platformOptions.installationMode === InstallationMode.AUTO;
- const getManualInstallSnippet = (params: Params) => `
- plugins {
- id "com.android.application" // should be in the same module
- id "io.sentry.android.gradle" version "${getPackageVersion(
- params,
- 'sentry.java.android.gradle-plugin',
- '3.12.0'
- )}"
- }`;
- const getConfigurationSnippet = (params: Params) => `
- <application>
- <!-- Required: set your sentry.io project identifier (DSN) -->
- <meta-data android:name="io.sentry.dsn" android:value="${params.dsn.public}" />
- <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
- <meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
- <!-- enable screenshot for crashes -->
- <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
- <!-- enable view hierarchy for crashes -->
- <meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />${
- params.isPerformanceSelected
- ? `
- <!-- enable the performance API by setting a sample-rate, adjust in production env -->
- <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />`
- : ''
- }${
- params.isProfilingSelected
- ? `
- <!-- enable profiling when starting transactions, adjust in production env -->
- <meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />`
- : ''
- }
- </application>`;
- const getVerifySnippet = () => `
- val breakWorld = Button(this).apply {
- text = "Break the world"
- setOnClickListener {
- Sentry.captureException(RuntimeException("This app uses Sentry! :)"))
- }
- }
- addContentView(breakWorld, ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))`;
- const getReplaySetupSnippetKotlin = (params: Params) => `
- SentryAndroid.init(context) { options ->
- options.dsn = "${params.dsn.public}"
- options.isDebug = true
- // Currently under experimental options:
- options.experimental.sessionReplay.onErrorSampleRate = 1.0
- options.experimental.sessionReplay.sessionSampleRate = 1.0
- }`;
- const getReplaySetupSnippetXml = () => `
- <meta-data android:name="io.sentry.session-replay.on-error-sample-rate" android:value="1.0" />
- <meta-data android:name="io.sentry.session-replay.session-sample-rate" android:value="1.0" />`;
- const getReplayConfigurationSnippet = () => `
- options.experimental.sessionReplay.redactAllText = true
- options.experimental.sessionReplay.redactAllImages = true`;
- const onboarding: OnboardingConfig<PlatformOptions> = {
- install: params =>
- isAutoInstall(params)
- ? [
- {
- type: StepType.INSTALL,
- description: tct(
- 'Add Sentry automatically to your app with the [wizardLink:Sentry wizard] (call this inside your project directory).',
- {
- wizardLink: (
- <ExternalLink href="https://docs.sentry.io/platforms/android/#install" />
- ),
- }
- ),
- configurations: [
- {
- language: 'bash',
- code: `brew install getsentry/tools/sentry-wizard && sentry-wizard -i android`,
- },
- {
- description: (
- <Fragment>
- <p>
- {t('The Sentry wizard will automatically patch your application:')}
- </p>
- <List symbol="bullet">
- <ListItem>
- {tct(
- "Update your app's [buildGradle:build.gradle] file with the Sentry Gradle plugin and configure it.",
- {
- buildGradle: <code />,
- }
- )}
- </ListItem>
- <ListItem>
- {tct(
- 'Update your [manifest: AndroidManifest.xml] with the default Sentry configuration',
- {
- manifest: <code />,
- }
- )}
- </ListItem>
- <ListItem>
- {tct(
- 'Create [code: sentry.properties] with an auth token to upload proguard mappings (this file is automatically added to [code: .gitignore])',
- {
- code: <code />,
- }
- )}
- </ListItem>
- <ListItem>
- {t(
- "Add an example error to your app's Main Activity to verify your Sentry setup"
- )}
- </ListItem>
- </List>
- </Fragment>
- ),
- additionalInfo: tct(
- 'Alternatively, you can also [manualSetupLink:set up the SDK manually].',
- {
- manualSetupLink: (
- <ExternalLink href="https://docs.sentry.io/platforms/android/manual-setup/" />
- ),
- }
- ),
- },
- ],
- },
- ]
- : [
- {
- type: StepType.INSTALL,
- description: tct(
- 'Add the [sagpLink:Sentry Android Gradle plugin] to your [app:app] module:',
- {
- sagpLink: (
- <ExternalLink href="https://docs.sentry.io/platforms/android/configuration/gradle/" />
- ),
- app: <code />,
- }
- ),
- configurations: [
- {
- language: 'groovy',
- partialLoading: params.sourcePackageRegistries?.isLoading,
- code: getManualInstallSnippet(params),
- },
- ],
- },
- ],
- configure: params =>
- isAutoInstall(params)
- ? []
- : [
- {
- type: StepType.CONFIGURE,
- description: (
- <Fragment>
- <p>
- {tct(
- 'Configuration is done via the application [code: AndroidManifest.xml]. Under the hood Sentry uses a [code:ContentProvider] to initialize the SDK based on the values provided below. This way the SDK can capture important crashes and metrics right from the app start.',
- {
- code: <code />,
- }
- )}
- </p>
- <p>{t("Here's an example config which should get you started:")}</p>
- </Fragment>
- ),
- configurations: [
- {
- language: 'xml',
- code: getConfigurationSnippet(params),
- },
- ],
- },
- ],
- verify: params =>
- isAutoInstall(params)
- ? []
- : [
- {
- type: StepType.VERIFY,
- description: tct(
- "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected. You can add it to your app's [mainActivity: MainActivity].",
- {
- mainActivity: <code />,
- }
- ),
- configurations: [
- {
- language: 'kotlin',
- code: getVerifySnippet(),
- },
- ],
- },
- ],
- nextSteps: params =>
- isAutoInstall(params)
- ? [
- {
- id: 'advanced-configuration',
- name: t('Advanced Configuration'),
- description: t('Customize the SDK initialization behavior.'),
- link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
- },
- {
- id: 'jetpack-compose',
- name: t('Jetpack Compose'),
- description: t(
- 'Learn about our first class integration with Jetpack Compose.'
- ),
- link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
- },
- ]
- : [
- {
- id: 'advanced-configuration',
- name: t('Advanced Configuration'),
- description: t('Customize the SDK initialization behavior.'),
- link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
- },
- {
- id: 'proguard-r8',
- name: t('ProGuard/R8'),
- description: t(
- 'Deobfuscate and get readable stacktraces in your Sentry errors.'
- ),
- link: 'https://docs.sentry.io/platforms/android/configuration/gradle/#proguardr8--dexguard',
- },
- {
- id: 'jetpack-compose',
- name: t('Jetpack Compose'),
- description: t(
- 'Learn about our first class integration with Jetpack Compose.'
- ),
- link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
- },
- {
- id: 'source-context',
- name: t('Source Context'),
- description: t('See your source code as part of your stacktraces in Sentry.'),
- link: 'https://docs.sentry.io/platforms/android/enhance-errors/source-context/',
- },
- ],
- };
- const replayOnboarding: OnboardingConfig<PlatformOptions> = {
- introduction: () => (
- <MobileBetaBanner link="https://docs.sentry.io/platforms/android/session-replay/" />
- ),
- install: (params: Params) => [
- {
- type: StepType.INSTALL,
- description: tct(
- "Make sure your Sentry Android SDK version is at least 7.12.0. The easiest way to update through the Sentry Android Gradle plugin to your app module's [code:build.gradle] file.",
- {code: <code />}
- ),
- configurations: [
- {
- code: [
- {
- label: 'Groovy',
- value: 'groovy',
- language: 'groovy',
- filename: 'app/build.gradle',
- code: `plugins {
- id "com.android.application"
- id "io.sentry.android.gradle" version "${getPackageVersion(
- params,
- 'sentry.java.android.gradle-plugin',
- '4.11.0'
- )}"
- }`,
- },
- {
- label: 'Kotlin',
- value: 'kotlin',
- language: 'kotlin',
- filename: 'app/build.gradle.kts',
- code: `plugins {
- id("com.android.application")
- id("io.sentry.android.gradle") version "${getPackageVersion(
- params,
- 'sentry.java.android.gradle-plugin',
- '4.11.0'
- )}"
- }`,
- },
- ],
- },
- {
- description: tct(
- 'If you have the SDK installed without the Sentry Gradle Plugin, you can update the version directly in the [code:build.gradle] through:',
- {code: <code />}
- ),
- },
- {
- code: [
- {
- label: 'Groovy',
- value: 'groovy',
- language: 'groovy',
- filename: 'app/build.gradle',
- code: `dependencies {
- implementation 'io.sentry:sentry-android:${getPackageVersion(
- params,
- 'sentry.java.android',
- '7.14.0'
- )}'
- }`,
- },
- {
- label: 'Kotlin',
- value: 'kotlin',
- language: 'kotlin',
- filename: 'app/build.gradle.kts',
- code: `dependencies {
- implementation("io.sentry:sentry-android:${getPackageVersion(
- params,
- 'sentry.java.android',
- '7.14.0'
- )}")
- }`,
- },
- ],
- },
- {
- description: t(
- 'To set up the integration, add the following to your Sentry initialization:'
- ),
- },
- {
- code: [
- {
- label: 'Kotlin',
- value: 'kotlin',
- language: 'kotlin',
- code: getReplaySetupSnippetKotlin(params),
- },
- {
- label: 'XML',
- value: 'xml',
- language: 'xml',
- filename: 'AndroidManifest.xml',
- code: getReplaySetupSnippetXml(),
- },
- ],
- },
- ],
- },
- ],
- configure: () => [
- {
- type: StepType.CONFIGURE,
- description: getReplayMobileConfigureDescription({
- link: 'https://docs.sentry.io/platforms/android/session-replay/#privacy',
- }),
- configurations: [
- {
- description: t(
- 'The following code is the default configuration, which masks and blocks everything.'
- ),
- code: [
- {
- label: 'Kotlin',
- value: 'kotlin',
- language: 'kotlin',
- code: getReplayConfigurationSnippet(),
- },
- ],
- },
- ],
- },
- ],
- verify: getReplayVerifyStep({
- replayOnErrorSampleRateName:
- 'options\u200b.experimental\u200b.sessionReplay\u200b.onErrorSampleRate',
- replaySessionSampleRateName:
- 'options\u200b.experimental\u200b.sessionReplay\u200b.sessionSampleRate',
- }),
- nextSteps: () => [],
- };
- const docs: Docs<PlatformOptions> = {
- onboarding,
- feedbackOnboardingCrashApi: feedbackOnboardingCrashApiJava,
- crashReportOnboarding: feedbackOnboardingCrashApiJava,
- customMetricsOnboarding: getAndroidMetricsOnboarding(),
- platformOptions,
- replayOnboarding,
- };
- export default docs;
|