spring-boot.tsx 9.3 KB

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