spring-boot.tsx 11 KB

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