spring-boot.tsx 9.3 KB

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