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 = tct(
  9. "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].",
  10. {
  11. gettingStartedWithAndroidLink: (
  12. <ExternalLink href="https://docs.sentry.io/platforms/android/" />
  13. ),
  14. gettingStartedWithJavaLink: (
  15. <ExternalLink href="https://docs.sentry.io/platforms/java/" />
  16. ),
  17. strong: <strong />,
  18. }
  19. );
  20. export const steps = ({
  21. dsn,
  22. }: {
  23. dsn?: string;
  24. } = {}): LayoutProps['steps'] => [
  25. {
  26. type: StepType.INSTALL,
  27. description: t('Install the SDK via Gradle or Maven:'),
  28. configurations: [
  29. {
  30. language: 'groovy',
  31. description: (
  32. <p>
  33. {tct('For [strong:Gradle], add to your [code:build.gradle] file:', {
  34. strong: <strong />,
  35. code: <code />,
  36. })}
  37. </p>
  38. ),
  39. code: `
  40. // Make sure mavenCentral is there.
  41. repositories {
  42. mavenCentral()
  43. }
  44. dependencies {
  45. implementation 'io.sentry:sentry:{{@inject packages.version('sentry.java', '4.0.0') }}'
  46. }
  47. `,
  48. },
  49. {
  50. language: 'xml',
  51. description: (
  52. <p>
  53. {tct('For [strong:Maven], add to your [code:pom.xml] file:', {
  54. strong: <strong />,
  55. code: <code />,
  56. })}
  57. </p>
  58. ),
  59. code: `
  60. <dependency>
  61. <groupId>io.sentry</groupId>
  62. <artifactId>sentry</artifactId>
  63. <version>6.25.0</version>
  64. </dependency>
  65. `,
  66. },
  67. ],
  68. },
  69. {
  70. type: StepType.CONFIGURE,
  71. description: (
  72. <p>
  73. {tct("Configure Sentry as soon as possible in your application's lifecycle:", {
  74. code: <code />,
  75. })}
  76. </p>
  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;