kotlin.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const introduction = (
  9. <p>
  10. {tct(
  11. "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 [strong:Spring Boot, Spring, Logback, JUL, or Log4j2], head over to our [gettingStartedWithJavaLink:Getting Started for Sentry Java].",
  12. {
  13. gettingStartedWithAndroidLink: (
  14. <ExternalLink href="https://docs.sentry.io/platforms/android/" />
  15. ),
  16. gettingStartedWithJavaLink: (
  17. <ExternalLink href="https://docs.sentry.io/platforms/java/" />
  18. ),
  19. strong: <strong />,
  20. }
  21. )}
  22. </p>
  23. );
  24. export const steps = ({
  25. dsn,
  26. }: {
  27. dsn?: string;
  28. } = {}): LayoutProps['steps'] => [
  29. {
  30. type: StepType.INSTALL,
  31. description: t('Install the SDK via Gradle or Maven:'),
  32. configurations: [
  33. {
  34. language: 'groovy',
  35. description: (
  36. <p>
  37. {tct('For [strong:Gradle], add to your [code:build.gradle] file:', {
  38. strong: <strong />,
  39. code: <code />,
  40. })}
  41. </p>
  42. ),
  43. code: `
  44. // Make sure mavenCentral is there.
  45. repositories {
  46. mavenCentral()
  47. }
  48. dependencies {
  49. implementation 'io.sentry:sentry:{{@inject packages.version('sentry.java', '4.0.0') }}'
  50. }
  51. `,
  52. },
  53. {
  54. language: 'xml',
  55. description: (
  56. <p>
  57. {tct('For [strong:Maven], add to your [code:pom.xml] file:', {
  58. strong: <strong />,
  59. code: <code />,
  60. })}
  61. </p>
  62. ),
  63. code: `
  64. <dependency>
  65. <groupId>io.sentry</groupId>
  66. <artifactId>sentry</artifactId>
  67. <version>6.25.0</version>
  68. </dependency>
  69. `,
  70. },
  71. ],
  72. },
  73. {
  74. type: StepType.CONFIGURE,
  75. description: t(
  76. "Configure Sentry as soon as possible in your application's lifecycle:"
  77. ),
  78. configurations: [
  79. {
  80. language: 'kotlin',
  81. code: `
  82. import io.sentry.Sentry
  83. Sentry.init { options ->
  84. options.dsn = "${dsn}"
  85. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  86. // We recommend adjusting this value in production.
  87. options.tracesSampleRate = 1.0
  88. // When first trying Sentry it's good to see what the SDK is doing:
  89. options.isDebug = true
  90. }
  91. `,
  92. },
  93. ],
  94. },
  95. {
  96. type: StepType.VERIFY,
  97. description: (
  98. <p>
  99. {tct(
  100. '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:',
  101. {code: <code />}
  102. )}
  103. </p>
  104. ),
  105. configurations: [
  106. {
  107. language: 'kotlin',
  108. code: `
  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. `,
  117. },
  118. ],
  119. additionalInfo: (
  120. <Fragment>
  121. {t(
  122. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  123. )}
  124. <p>
  125. {t(
  126. "If you're an existing user and have disabled alerts, you won't receive this email."
  127. )}
  128. </p>
  129. </Fragment>
  130. ),
  131. },
  132. {
  133. title: t('Measure Performance'),
  134. description: t('You can capture transactions using the SDK. For example:'),
  135. configurations: [
  136. {
  137. language: 'kotlin',
  138. code: `
  139. import io.sentry.Sentry
  140. import io.sentry.SpanStatus
  141. // A good name for the transaction is key, to help identify what this is about
  142. val transaction = Sentry.startTransaction("processOrderBatch()", "task")
  143. try {
  144. processOrderBatch()
  145. } catch (e: Exception) {
  146. transaction.throwable = e
  147. transaction.status = SpanStatus.INTERNAL_ERROR
  148. throw e
  149. } finally {
  150. transaction.finish();
  151. }
  152. `,
  153. },
  154. ],
  155. additionalInfo: (
  156. <p>
  157. {tct(
  158. 'For more information about the API and automatic instrumentations included in the SDK, visit the docs.',
  159. {
  160. docsLink: (
  161. <ExternalLink href="https://docs.sentry.io/platforms/java/performance/" />
  162. ),
  163. }
  164. )}
  165. </p>
  166. ),
  167. },
  168. ];
  169. // Configuration End
  170. export function GettingStartedWithKotlin({dsn, ...props}: ModuleProps) {
  171. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  172. }
  173. export default GettingStartedWithKotlin;