kotlin.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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: t(
  72. "Configure Sentry as soon as possible in your application's lifecycle:"
  73. ),
  74. configurations: [
  75. {
  76. language: 'kotlin',
  77. code: `
  78. import io.sentry.Sentry
  79. Sentry.init { options ->
  80. options.dsn = "${dsn}"
  81. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  82. // We recommend adjusting this value in production.
  83. options.tracesSampleRate = 1.0
  84. // When first trying Sentry it's good to see what the SDK is doing:
  85. options.isDebug = true
  86. }
  87. `,
  88. },
  89. ],
  90. },
  91. {
  92. type: StepType.VERIFY,
  93. description: (
  94. <p>
  95. {tct(
  96. '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:',
  97. {code: <code />}
  98. )}
  99. </p>
  100. ),
  101. configurations: [
  102. {
  103. language: 'kotlin',
  104. code: `
  105. import java.lang.Exception
  106. import io.sentry.Sentry
  107. try {
  108. throw Exception("This is a test.")
  109. } catch (e: Exception) {
  110. Sentry.captureException(e)
  111. }
  112. `,
  113. },
  114. ],
  115. additionalInfo: (
  116. <Fragment>
  117. {t(
  118. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  119. )}
  120. <p>
  121. {t(
  122. "If you're an existing user and have disabled alerts, you won't receive this email."
  123. )}
  124. </p>
  125. </Fragment>
  126. ),
  127. },
  128. {
  129. title: t('Measure Performance'),
  130. description: t('You can capture transactions using the SDK. For example:'),
  131. configurations: [
  132. {
  133. language: 'kotlin',
  134. code: `
  135. import io.sentry.Sentry
  136. import io.sentry.SpanStatus
  137. // A good name for the transaction is key, to help identify what this is about
  138. val transaction = Sentry.startTransaction("processOrderBatch()", "task")
  139. try {
  140. processOrderBatch()
  141. } catch (e: Exception) {
  142. transaction.throwable = e
  143. transaction.status = SpanStatus.INTERNAL_ERROR
  144. throw e
  145. } finally {
  146. transaction.finish();
  147. }
  148. `,
  149. },
  150. ],
  151. additionalInfo: (
  152. <p>
  153. {tct(
  154. 'For more information about the API and automatic instrumentations included in the SDK, visit the docs.',
  155. {
  156. docsLink: (
  157. <ExternalLink href="https://docs.sentry.io/platforms/java/performance/" />
  158. ),
  159. }
  160. )}
  161. </p>
  162. ),
  163. },
  164. ];
  165. // Configuration End
  166. export function GettingStartedWithKotlin({dsn, ...props}: ModuleProps) {
  167. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  168. }
  169. export default GettingStartedWithKotlin;