android.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. interface StepProps {
  8. dsn: string;
  9. hasPerformance: boolean;
  10. hasProfiling: boolean;
  11. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  12. }
  13. // Configuration Start
  14. export const steps = ({
  15. dsn,
  16. sourcePackageRegistries,
  17. hasPerformance,
  18. hasProfiling,
  19. }: StepProps): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: (
  23. <p>
  24. {tct(
  25. 'Add the [sagpLink:Sentry Android Gradle plugin] to your [app:app] module:',
  26. {
  27. sagpLink: (
  28. <ExternalLink href="https://docs.sentry.io/platforms/android/configuration/gradle/" />
  29. ),
  30. app: <code />,
  31. }
  32. )}
  33. </p>
  34. ),
  35. configurations: [
  36. {
  37. language: 'groovy',
  38. partialLoading: sourcePackageRegistries?.isLoading,
  39. code: `
  40. plugins {
  41. id "com.android.application" // should be in the same module
  42. id "io.sentry.android.gradle" version "${
  43. sourcePackageRegistries?.isLoading
  44. ? t('\u2026loading')
  45. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  46. '3.12.0'
  47. }"
  48. }
  49. `,
  50. },
  51. {
  52. description: t(
  53. 'The plugin will automatically add the Sentry Android SDK to your app.'
  54. ),
  55. },
  56. ],
  57. },
  58. {
  59. type: StepType.CONFIGURE,
  60. description: (
  61. <p>
  62. {tct(
  63. 'Configuration is done via the application [manifest: AndroidManifest.xml]. Under the hood Sentry uses a [provider: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.',
  64. {
  65. manifest: <code />,
  66. provider: <code />,
  67. }
  68. )}
  69. </p>
  70. ),
  71. configurations: [
  72. {
  73. description: t("Here's an example config which should get you started:"),
  74. language: 'xml',
  75. code: `
  76. <application>
  77. <!-- Required: set your sentry.io project identifier (DSN) -->
  78. <meta-data android:name="io.sentry.dsn" android:value="${dsn}" />
  79. <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
  80. <meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
  81. <!-- enable screenshot for crashes -->
  82. <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
  83. <!-- enable view hierarchy for crashes -->
  84. <meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />${
  85. hasPerformance
  86. ? `
  87. <!-- enable the performance API by setting a sample-rate, adjust in production env -->
  88. <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />`
  89. : ''
  90. }${
  91. hasProfiling
  92. ? `
  93. <!-- enable profiling when starting transactions, adjust in production env -->
  94. <meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />`
  95. : ''
  96. }
  97. </application>
  98. `,
  99. },
  100. ],
  101. },
  102. {
  103. type: StepType.VERIFY,
  104. description: (
  105. <p>
  106. {tct(
  107. "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].",
  108. {
  109. mainActivity: <code />,
  110. }
  111. )}
  112. </p>
  113. ),
  114. configurations: [
  115. {
  116. language: 'kotlin',
  117. code: `
  118. val breakWorld = Button(this).apply {
  119. text = "Break the world"
  120. setOnClickListener {
  121. throw RuntimeException("Break the world")
  122. }
  123. }
  124. addContentView(breakWorld, ViewGroup.LayoutParams(
  125. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
  126. `,
  127. },
  128. ],
  129. },
  130. ];
  131. export const nextSteps = [
  132. {
  133. id: 'manual-configuration',
  134. name: t('Manual Configuration'),
  135. description: t('Customize the SDK initialization behavior.'),
  136. link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
  137. },
  138. {
  139. id: 'proguard-r8',
  140. name: t('ProGuard/R8'),
  141. description: t('Deobfuscate and get readable stacktraces in your Sentry errors.'),
  142. link: 'https://docs.sentry.io/platforms/android/configuration/gradle/#proguardr8--dexguard',
  143. },
  144. {
  145. id: 'jetpack-compose',
  146. name: t('Jetpack Compose'),
  147. description: t('Learn about our first class integration with Jetpack Compose.'),
  148. link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
  149. },
  150. {
  151. id: 'source-context',
  152. name: t('Source Context'),
  153. description: t('See your source code as part of your stacktraces in Sentry.'),
  154. link: 'https://docs.sentry.io/platforms/android/enhance-errors/source-context/',
  155. },
  156. ];
  157. // Configuration End
  158. export function GettingStartedWithAndroid({
  159. dsn,
  160. sourcePackageRegistries,
  161. activeProductSelection = [],
  162. ...props
  163. }: ModuleProps) {
  164. const hasPerformance = activeProductSelection.includes(
  165. ProductSolution.PERFORMANCE_MONITORING
  166. );
  167. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  168. return (
  169. <Layout
  170. steps={steps({dsn, sourcePackageRegistries, hasPerformance, hasProfiling})}
  171. nextSteps={nextSteps}
  172. {...props}
  173. />
  174. );
  175. }
  176. export default GettingStartedWithAndroid;