kotlin.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. sourcePackageRegistries,
  27. }: Partial<
  28. Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
  29. > = {}): LayoutProps['steps'] => [
  30. {
  31. type: StepType.INSTALL,
  32. description: t('Install the SDK via Gradle or Maven:'),
  33. configurations: [
  34. {
  35. language: 'groovy',
  36. description: (
  37. <p>
  38. {tct('For [strong:Gradle], add to your [code:build.gradle] file:', {
  39. strong: <strong />,
  40. code: <code />,
  41. })}
  42. </p>
  43. ),
  44. partialLoading: sourcePackageRegistries?.isLoading,
  45. code: `
  46. // Make sure mavenCentral is there.
  47. repositories {
  48. mavenCentral()
  49. }
  50. dependencies {
  51. implementation 'io.sentry:sentry:${
  52. sourcePackageRegistries?.isLoading
  53. ? t('\u2026loading')
  54. : sourcePackageRegistries?.data?.['sentry.java']?.version ?? '4.0.0'
  55. }'
  56. }
  57. `,
  58. },
  59. {
  60. language: 'xml',
  61. partialLoading: sourcePackageRegistries?.isLoading,
  62. description: (
  63. <p>
  64. {tct('For [strong:Maven], add to your [code:pom.xml] file:', {
  65. strong: <strong />,
  66. code: <code />,
  67. })}
  68. </p>
  69. ),
  70. code: `
  71. <dependency>
  72. <groupId>io.sentry</groupId>
  73. <artifactId>sentry</artifactId>
  74. <version>${
  75. sourcePackageRegistries?.isLoading
  76. ? t('\u2026loading')
  77. : sourcePackageRegistries?.data?.['sentry.java']?.version ?? '6.25.0'
  78. }</version>
  79. </dependency>
  80. `,
  81. },
  82. ],
  83. },
  84. {
  85. type: StepType.CONFIGURE,
  86. description: t(
  87. "Configure Sentry as soon as possible in your application's lifecycle:"
  88. ),
  89. configurations: [
  90. {
  91. language: 'kotlin',
  92. code: `
  93. import io.sentry.Sentry
  94. Sentry.init { options ->
  95. options.dsn = "${dsn}"
  96. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  97. // We recommend adjusting this value in production.
  98. options.tracesSampleRate = 1.0
  99. // When first trying Sentry it's good to see what the SDK is doing:
  100. options.isDebug = true
  101. }
  102. `,
  103. },
  104. ],
  105. },
  106. {
  107. type: StepType.VERIFY,
  108. description: (
  109. <p>
  110. {tct(
  111. '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:',
  112. {code: <code />}
  113. )}
  114. </p>
  115. ),
  116. configurations: [
  117. {
  118. language: 'kotlin',
  119. code: `
  120. import java.lang.Exception
  121. import io.sentry.Sentry
  122. try {
  123. throw Exception("This is a test.")
  124. } catch (e: Exception) {
  125. Sentry.captureException(e)
  126. }
  127. `,
  128. },
  129. ],
  130. additionalInfo: (
  131. <Fragment>
  132. {t(
  133. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  134. )}
  135. <p>
  136. {t(
  137. "If you're an existing user and have disabled alerts, you won't receive this email."
  138. )}
  139. </p>
  140. </Fragment>
  141. ),
  142. },
  143. {
  144. title: t('Measure Performance'),
  145. description: t('You can capture transactions using the SDK. For example:'),
  146. configurations: [
  147. {
  148. language: 'kotlin',
  149. code: `
  150. import io.sentry.Sentry
  151. import io.sentry.SpanStatus
  152. // A good name for the transaction is key, to help identify what this is about
  153. val transaction = Sentry.startTransaction("processOrderBatch()", "task")
  154. try {
  155. processOrderBatch()
  156. } catch (e: Exception) {
  157. transaction.throwable = e
  158. transaction.status = SpanStatus.INTERNAL_ERROR
  159. throw e
  160. } finally {
  161. transaction.finish();
  162. }
  163. `,
  164. },
  165. ],
  166. additionalInfo: (
  167. <p>
  168. {tct(
  169. 'For more information about the API and automatic instrumentations included in the SDK, visit the docs.',
  170. {
  171. docsLink: (
  172. <ExternalLink href="https://docs.sentry.io/platforms/java/performance/" />
  173. ),
  174. }
  175. )}
  176. </p>
  177. ),
  178. },
  179. ];
  180. // Configuration End
  181. export function GettingStartedWithKotlin({
  182. dsn,
  183. sourcePackageRegistries,
  184. ...props
  185. }: ModuleProps) {
  186. return (
  187. <Layout
  188. steps={steps({dsn, sourcePackageRegistries})}
  189. introduction={introduction}
  190. {...props}
  191. />
  192. );
  193. }
  194. export default GettingStartedWithKotlin;