spring-boot.tsx 9.6 KB

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