spring-boot.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 type {
  6. BasePlatformOptions,
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {feedbackOnboardingCrashApiJava} from 'sentry/gettingStartedDocs/java/java';
  12. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  13. import {t, tct} from 'sentry/locale';
  14. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  15. export enum PackageManager {
  16. GRADLE = 'gradle',
  17. MAVEN = 'maven',
  18. }
  19. const platformOptions = {
  20. packageManager: {
  21. label: t('Package Manager'),
  22. items: [
  23. {
  24. label: t('Gradle'),
  25. value: PackageManager.GRADLE,
  26. },
  27. {
  28. label: t('Maven'),
  29. value: PackageManager.MAVEN,
  30. },
  31. ],
  32. },
  33. } satisfies BasePlatformOptions;
  34. type PlatformOptions = typeof platformOptions;
  35. type Params = DocsParams<PlatformOptions>;
  36. const getGradleInstallSnippet = (params: Params) => `
  37. buildscript {
  38. repositories {
  39. mavenCentral()
  40. }
  41. }
  42. plugins {
  43. id "io.sentry.jvm.gradle" version "${getPackageVersion(
  44. params,
  45. 'sentry.java.android.gradle-plugin',
  46. '3.12.0'
  47. )}"
  48. }
  49. sentry {
  50. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  51. // This enables source context, allowing you to see your source
  52. // code as part of your stack traces in Sentry.
  53. includeSourceContext = true
  54. org = "${params.organization.slug}"
  55. projectName = "${params.projectSlug}"
  56. authToken = System.getenv("SENTRY_AUTH_TOKEN")
  57. }`;
  58. const getMavenInstallSnippet = (params: Params) => `
  59. <build>
  60. <plugins>
  61. <plugin>
  62. <groupId>io.sentry</groupId>
  63. <artifactId>sentry-maven-plugin</artifactId>
  64. <version>${getPackageVersion(params, 'sentry.java.maven-plugin', '0.0.4')}</version>
  65. <extensions>true</extensions>
  66. <configuration>
  67. <!-- for showing output of sentry-cli -->
  68. <debugSentryCli>true</debugSentryCli>
  69. <org>${params.organization.slug}</org>
  70. <project>${params.projectSlug}</project>
  71. <!-- in case you're self hosting, provide the URL here -->
  72. <!--<url>http://localhost:8000/</url>-->
  73. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  74. <authToken>\${env.SENTRY_AUTH_TOKEN}</authToken>
  75. </configuration>
  76. <executions>
  77. <execution>
  78. <goals>
  79. <!--
  80. Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  81. This enables source context, allowing you to see your source
  82. code as part of your stack traces in Sentry.
  83. -->
  84. <goal>uploadSourceBundle</goal>
  85. </goals>
  86. </execution>
  87. </executions>
  88. </plugin>
  89. </plugins>
  90. ...
  91. </build>`;
  92. const getConfigurationPropertiesSnippet = (params: Params) => `
  93. sentry.dsn=${params.dsn}${
  94. params.isPerformanceSelected
  95. ? `
  96. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  97. # We recommend adjusting this value in production.
  98. sentry.traces-sample-rate=1.0`
  99. : ''
  100. }`;
  101. const getConfigurationYamlSnippet = (params: Params) => `
  102. sentry:
  103. dsn: ${params.dsn}${
  104. params.isPerformanceSelected
  105. ? `
  106. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  107. # We recommend adjusting this value in production.
  108. traces-sample-rate: 1.0`
  109. : ''
  110. }`;
  111. const getVerifyJavaSnippet = () => `
  112. import java.lang.Exception;
  113. import io.sentry.Sentry;
  114. try {
  115. throw new Exception("This is a test.");
  116. } catch (Exception e) {
  117. Sentry.captureException(e);
  118. }`;
  119. const getVerifyKotlinSnippet = () => `
  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. const onboarding: OnboardingConfig<PlatformOptions> = {
  128. introduction: () =>
  129. tct(
  130. "Sentry's integration with [springBootLink:Spring Boot] supports Spring Boot 2.1.0 and above. If you're on an older version, use [legacyIntegrationLink:our legacy integration].",
  131. {
  132. springBootLink: <ExternalLink href="https://spring.io/projects/spring-boot" />,
  133. legacyIntegrationLink: (
  134. <ExternalLink href="https://docs.sentry.io/platforms/java/legacy/spring/" />
  135. ),
  136. }
  137. ),
  138. install: (params: Params) => [
  139. {
  140. type: StepType.INSTALL,
  141. configurations: [
  142. {
  143. description: tct(
  144. '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.',
  145. {
  146. link: <Link to="/settings/auth-tokens/" />,
  147. }
  148. ),
  149. language: 'bash',
  150. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  151. },
  152. params.platformOptions.packageManager === PackageManager.GRADLE
  153. ? {
  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. language: 'groovy',
  164. code: getGradleInstallSnippet(params),
  165. }
  166. : {
  167. description: tct(
  168. '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:',
  169. {
  170. code: <code />,
  171. link: (
  172. <ExternalLink href="https://github.com/getsentry/sentry-maven-plugin" />
  173. ),
  174. }
  175. ),
  176. language: 'xml',
  177. code: getMavenInstallSnippet(params),
  178. },
  179. ],
  180. additionalInfo: (
  181. <p>
  182. {tct(
  183. 'If you prefer to manually upload your source code to Sentry, please refer to [link:Manually Uploading Source Context].',
  184. {
  185. link: (
  186. <ExternalLink href="https://docs.sentry.io/platforms/java/source-context/#manually-uploading-source-context" />
  187. ),
  188. }
  189. )}
  190. </p>
  191. ),
  192. },
  193. ],
  194. configure: (params: Params) => [
  195. {
  196. type: StepType.CONFIGURE,
  197. description: tct(
  198. 'Open up [applicationPropertiesCode:src/main/application.properties] (or [applicationYmlCode:src/main/application.yml]) and configure the DSN, and any other settings you need:',
  199. {
  200. applicationPropertiesCode: <code />,
  201. applicationYmlCode: <code />,
  202. }
  203. ),
  204. configurations: [
  205. {
  206. code: [
  207. {
  208. label: 'Properties',
  209. value: 'properties',
  210. language: 'properties',
  211. code: getConfigurationPropertiesSnippet(params),
  212. },
  213. {
  214. label: 'YAML',
  215. value: 'yaml',
  216. language: 'properties',
  217. code: getConfigurationYamlSnippet(params),
  218. },
  219. ],
  220. },
  221. ],
  222. },
  223. ],
  224. verify: () => [
  225. {
  226. type: StepType.VERIFY,
  227. description: t(
  228. 'Then create an intentional error, so you can test that everything is working using either Java or Kotlin:'
  229. ),
  230. configurations: [
  231. {
  232. code: [
  233. {
  234. label: 'Java',
  235. value: 'java',
  236. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  237. code: getVerifyJavaSnippet(),
  238. },
  239. {
  240. label: 'Kotlin',
  241. value: 'kotlin',
  242. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  243. code: getVerifyKotlinSnippet(),
  244. },
  245. ],
  246. },
  247. ],
  248. additionalInfo: (
  249. <Fragment>
  250. <p>
  251. {t(
  252. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  253. )}
  254. </p>
  255. <p>
  256. {t(
  257. "If you're an existing user and have disabled alerts, you won't receive this email."
  258. )}
  259. </p>
  260. </Fragment>
  261. ),
  262. },
  263. ],
  264. nextSteps: () => [
  265. {
  266. id: 'examples',
  267. name: t('Examples'),
  268. description: t('Check out our sample applications.'),
  269. link: 'https://github.com/getsentry/sentry-java/tree/main/sentry-samples',
  270. },
  271. {
  272. id: 'performance-monitoring',
  273. name: t('Performance Monitoring'),
  274. description: t(
  275. 'Stay ahead of latency issues and trace every slow transaction to a poor-performing API call or database query.'
  276. ),
  277. link: 'https://docs.sentry.io/platforms/java/guides/spring-boot/performance/',
  278. },
  279. ],
  280. };
  281. const docs: Docs<PlatformOptions> = {
  282. onboarding,
  283. platformOptions,
  284. replayOnboardingJsLoader,
  285. crashReportOnboarding: feedbackOnboardingCrashApiJava,
  286. };
  287. export default docs;