kotlin.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import Link from 'sentry/components/links/link';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {
  6. BasePlatformOptions,
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {t, tct} from 'sentry/locale';
  12. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  13. export enum PackageManager {
  14. GRADLE = 'gradle',
  15. MAVEN = 'maven',
  16. }
  17. const packageManagerName: Record<PackageManager, string> = {
  18. [PackageManager.GRADLE]: 'Gradle',
  19. [PackageManager.MAVEN]: 'Maven',
  20. };
  21. const platformOptions = {
  22. packageManager: {
  23. label: t('Package Manager'),
  24. items: [
  25. {
  26. label: t('Gradle'),
  27. value: PackageManager.GRADLE,
  28. },
  29. {
  30. label: t('Maven'),
  31. value: PackageManager.MAVEN,
  32. },
  33. ],
  34. },
  35. } satisfies BasePlatformOptions;
  36. type PlatformOptions = typeof platformOptions;
  37. type Params = DocsParams<PlatformOptions>;
  38. const getGradleInstallSnippet = (params: Params) => `
  39. buildscript {
  40. repositories {
  41. mavenCentral()
  42. }
  43. }
  44. plugins {
  45. id "io.sentry.jvm.gradle" version "${getPackageVersion(
  46. params,
  47. 'sentry.java.android.gradle-plugin',
  48. '3.12.0'
  49. )}"
  50. }
  51. sentry {
  52. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  53. // This enables source context, allowing you to see your source
  54. // code as part of your stack traces in Sentry.
  55. includeSourceContext = true
  56. org = "${params.organization.slug}"
  57. projectName = "${params.projectSlug}"
  58. authToken = System.getenv("SENTRY_AUTH_TOKEN")
  59. }`;
  60. const getMavenInstallSnippet = (params: Params) => `
  61. <build>
  62. <plugins>
  63. <plugin>
  64. <groupId>io.sentry</groupId>
  65. <artifactId>sentry-maven-plugin</artifactId>
  66. <version>${getPackageVersion(params, 'sentry.java.maven-plugin', '0.0.4')}</version>
  67. <extensions>true</extensions>
  68. <configuration>
  69. <!-- for showing output of sentry-cli -->
  70. <debugSentryCli>true</debugSentryCli>
  71. <org>${params.organization.slug}</org>
  72. <project>${params.projectSlug}</project>
  73. <!-- in case you're self hosting, provide the URL here -->
  74. <!--<url>http://localhost:8000/</url>-->
  75. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  76. <authToken>\${env.SENTRY_AUTH_TOKEN}</authToken>
  77. </configuration>
  78. <executions>
  79. <execution>
  80. <goals>
  81. <!--
  82. Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  83. This enables source context, allowing you to see your source
  84. code as part of your stack traces in Sentry.
  85. -->
  86. <goal>uploadSourceBundle</goal>
  87. </goals>
  88. </execution>
  89. </executions>
  90. </plugin>
  91. </plugins>
  92. ...
  93. </build>`;
  94. const getConfigureSnippet = (params: Params) => `
  95. import io.sentry.Sentry
  96. Sentry.init { options ->
  97. options.dsn = "${params.dsn}"${
  98. params.isPerformanceSelected
  99. ? `
  100. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  101. // We recommend adjusting this value in production.
  102. options.tracesSampleRate = 1.0`
  103. : ''
  104. }
  105. // When first trying Sentry it's good to see what the SDK is doing:
  106. options.isDebug = true
  107. }`;
  108. const getVerifySnippet = () => `
  109. import java.lang.Exception
  110. import io.sentry.Sentry
  111. try {
  112. throw Exception("This is a test.")
  113. } catch (e: Exception) {
  114. Sentry.captureException(e)
  115. }`;
  116. const onboarding: OnboardingConfig<PlatformOptions> = {
  117. introduction: () =>
  118. tct(
  119. "Sentry supports Kotlin for both JVM and Android. This wizard guides you through set up in the JVM scenario. If you're interested in [strong:Android], head over to the [gettingStartedWithAndroidLink:Getting Started] for that SDK instead. At its core, Sentry for Java provides a raw client for sending events to Sentry. If you use [strong2:Spring Boot, Spring, Logback, JUL, or Log4j2], head over to our [gettingStartedWithJavaLink:Getting Started for Sentry Java].",
  120. {
  121. gettingStartedWithAndroidLink: (
  122. <ExternalLink href="https://docs.sentry.io/platforms/android/" />
  123. ),
  124. gettingStartedWithJavaLink: (
  125. <ExternalLink href="https://docs.sentry.io/platforms/java/" />
  126. ),
  127. strong: <strong />,
  128. strong2: <strong />,
  129. }
  130. ),
  131. install: params => [
  132. {
  133. type: StepType.INSTALL,
  134. description: t(
  135. `Install the SDK via %s:`,
  136. packageManagerName[params.platformOptions.packageManager]
  137. ),
  138. configurations: [
  139. {
  140. description: tct(
  141. 'To see source context in Sentry, you have to generate an auth token by visiting the [link:Organization Auth Tokens] settings. You can then set the token as an environment variable that is used by the build plugins.',
  142. {
  143. link: <Link to="/settings/auth-tokens/" />,
  144. }
  145. ),
  146. language: 'bash',
  147. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  148. },
  149. ...(params.platformOptions.packageManager === PackageManager.GRADLE
  150. ? [
  151. {
  152. language: 'groovy',
  153. partialLoading: params.sourcePackageRegistries.isLoading,
  154. description: tct(
  155. 'The [link:Sentry Gradle Plugin] automatically installs the Sentry SDK as well as available integrations for your dependencies. Add the following to your [code:build.gradle] file:',
  156. {
  157. code: <code />,
  158. link: (
  159. <ExternalLink href="https://github.com/getsentry/sentry-android-gradle-plugin" />
  160. ),
  161. }
  162. ),
  163. code: getGradleInstallSnippet(params),
  164. },
  165. ]
  166. : []),
  167. ...(params.platformOptions.packageManager === PackageManager.MAVEN
  168. ? [
  169. {
  170. language: 'xml',
  171. partialLoading: params.sourcePackageRegistries.isLoading,
  172. description: tct(
  173. 'The [link:Sentry Maven Plugin] automatically installs the Sentry SDK as well as available integrations for your dependencies. Add the following to your [code:pom.xml] file:',
  174. {
  175. code: <code />,
  176. link: (
  177. <ExternalLink href="https://github.com/getsentry/sentry-maven-plugin" />
  178. ),
  179. }
  180. ),
  181. code: getMavenInstallSnippet(params),
  182. },
  183. ]
  184. : []),
  185. ],
  186. additionalInfo: tct(
  187. 'If you prefer to manually upload your source code to Sentry, please refer to [link:Manually Uploading Source Context].',
  188. {
  189. link: (
  190. <ExternalLink href="https://docs.sentry.io/platforms/java/source-context/#manually-uploading-source-context" />
  191. ),
  192. }
  193. ),
  194. },
  195. ],
  196. configure: params => [
  197. {
  198. type: StepType.CONFIGURE,
  199. description: t(
  200. "Configure Sentry as soon as possible in your application's lifecycle:"
  201. ),
  202. configurations: [
  203. {
  204. language: 'kotlin',
  205. code: getConfigureSnippet(params),
  206. },
  207. ],
  208. },
  209. ],
  210. verify: () => [
  211. {
  212. type: StepType.VERIFY,
  213. description: tct(
  214. 'Trigger your first event from your development environment by intentionally creating an error with the [code:Sentry#captureException] method, to test that everything is working:',
  215. {code: <code />}
  216. ),
  217. configurations: [
  218. {
  219. language: 'kotlin',
  220. code: getVerifySnippet(),
  221. additionalInfo: (
  222. <Fragment>
  223. {t(
  224. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  225. )}
  226. <p>
  227. {t(
  228. "If you're an existing user and have disabled alerts, you won't receive this email."
  229. )}
  230. </p>
  231. </Fragment>
  232. ),
  233. },
  234. ],
  235. },
  236. ],
  237. nextSteps: () => [
  238. {
  239. id: 'examples',
  240. name: t('Examples'),
  241. description: t('Check out our sample applications.'),
  242. link: 'https://github.com/getsentry/sentry-java/tree/main/sentry-samples',
  243. },
  244. {
  245. id: 'performance-monitoring',
  246. name: t('Performance Monitoring'),
  247. description: t(
  248. 'Stay ahead of latency issues and trace every slow transaction to a poor-performing API call or database query.'
  249. ),
  250. link: 'https://docs.sentry.io/platforms/java/performance/',
  251. },
  252. ],
  253. };
  254. const docs: Docs<PlatformOptions> = {
  255. platformOptions,
  256. onboarding,
  257. };
  258. export default docs;