spring-boot.tsx 11 KB

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