spring-boot.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {t, tct} from 'sentry/locale';
  7. interface StepProps {
  8. dsn: string;
  9. organizationSlug?: string;
  10. projectSlug?: string;
  11. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  12. }
  13. // Configuration Start
  14. const introduction = (
  15. <p>
  16. {tct(
  17. "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. Sentry's integration with [springBootLink:Spring Boot] supports Spring Boot 2.1.0 and above to report unhandled exceptions as well as release and registration of beans. If you're on an older version, use [legacyIntegrationLink:our legacy integration].",
  18. {
  19. springBootStarterLink: (
  20. <ExternalLink href="https://github.com/getsentry/sentry-java/tree/master/sentry-spring-boot-starter" />
  21. ),
  22. springBootStarterJakartaLink: (
  23. <ExternalLink href="https://github.com/getsentry/sentry-java/tree/master/sentry-spring-boot-starter-jakarta" />
  24. ),
  25. springBootLink: <ExternalLink href="https://spring.io/projects/spring-boot" />,
  26. legacyIntegrationLink: (
  27. <ExternalLink href="https://docs.sentry.io/platforms/java/legacy/spring/" />
  28. ),
  29. }
  30. )}
  31. </p>
  32. );
  33. export const steps = ({
  34. dsn,
  35. sourcePackageRegistries,
  36. projectSlug,
  37. organizationSlug,
  38. }: StepProps): LayoutProps['steps'] => [
  39. {
  40. type: StepType.INSTALL,
  41. description: t('Install using either Maven or Gradle:'),
  42. configurations: [
  43. {
  44. description: <h5>{t('Maven')}</h5>,
  45. configurations: [
  46. {
  47. language: 'xml',
  48. partialLoading: sourcePackageRegistries?.isLoading,
  49. description: <strong>{t('Spring Boot 2')}</strong>,
  50. code: `
  51. <dependency>
  52. <groupId>io.sentry</groupId>
  53. <artifactId>sentry-spring-boot-starter</artifactId>
  54. <version>${
  55. sourcePackageRegistries?.isLoading
  56. ? t('\u2026loading')
  57. : sourcePackageRegistries?.data?.['sentry.java.spring-boot']?.version ?? '6.27.0'
  58. }</version>
  59. </dependency>
  60. `,
  61. },
  62. {
  63. language: 'xml',
  64. partialLoading: sourcePackageRegistries?.isLoading,
  65. description: <strong>{t('Spring Boot 3')}</strong>,
  66. code: `
  67. <dependency>
  68. <groupId>io.sentry</groupId>
  69. <artifactId>sentry-spring-boot-starter-jakarta</artifactId>
  70. <version>${
  71. sourcePackageRegistries?.isLoading
  72. ? t('\u2026loading')
  73. : sourcePackageRegistries?.data?.['sentry.java.spring-boot.jakarta']?.version ??
  74. '6.27.0'
  75. }</version>
  76. </dependency>
  77. `,
  78. },
  79. ],
  80. },
  81. {
  82. description: <h5>{t('Graddle')}</h5>,
  83. configurations: [
  84. {
  85. language: 'properties',
  86. description: <strong>{t('Spring Boot 2')}</strong>,
  87. partialLoading: sourcePackageRegistries?.isLoading,
  88. code: `implementation 'io.sentry:sentry-spring-boot-starter:${
  89. sourcePackageRegistries?.isLoading
  90. ? t('\u2026loading')
  91. : sourcePackageRegistries?.data?.['sentry.java.spring-boot']?.version ??
  92. '6.27.0'
  93. }'`,
  94. },
  95. {
  96. language: 'properties',
  97. partialLoading: sourcePackageRegistries?.isLoading,
  98. description: <strong>{t('Spring Boot 3')}</strong>,
  99. code: `implementation 'io.sentry:sentry-spring-boot-starter-jakarta:${
  100. sourcePackageRegistries?.isLoading
  101. ? t('\u2026loading')
  102. : sourcePackageRegistries?.data?.['sentry.java.spring-boot.jakarta']
  103. ?.version ?? '6.27.0'
  104. }'`,
  105. },
  106. ],
  107. },
  108. ],
  109. },
  110. {
  111. type: StepType.CONFIGURE,
  112. description: (
  113. <p>
  114. {tct(
  115. 'Open up [applicationPropertiesCode:src/main/application.properties] (or [applicationYmlCode:src/main/application.yml]) and configure the DSN, and any other settings you need:',
  116. {
  117. applicationPropertiesCode: <code />,
  118. applicationYmlCode: <code />,
  119. }
  120. )}
  121. </p>
  122. ),
  123. configurations: [
  124. {
  125. language: 'properties',
  126. description: (
  127. <p>{tct('Modify [code:src/main/application.properties]:', {code: <code />})}</p>
  128. ),
  129. code: `
  130. sentry.dsn=${dsn}
  131. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  132. # We recommend adjusting this value in production.
  133. sentry.traces-sample-rate=1.0
  134. `,
  135. },
  136. {
  137. language: 'properties',
  138. description: (
  139. <p>{tct('Or, modify [code:src/main/application.yml]:', {code: <code />})}</p>
  140. ),
  141. code: `
  142. sentry:
  143. dsn:${dsn}
  144. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  145. # We recommend adjusting this value in production.
  146. traces-sample-rate: 1.0
  147. `,
  148. additionalInfo: (
  149. <p>
  150. {tct(
  151. '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 using either Maven or Gradle. Sentry Spring Boot Starter will auto-configure [sentryAppenderCode:SentryAppender].',
  152. {sentryAppenderCode: <code />, sentryLogbackCode: <code />}
  153. )}
  154. </p>
  155. ),
  156. },
  157. {
  158. description: <h5>{t('Maven')}</h5>,
  159. configurations: [
  160. {
  161. language: 'xml',
  162. code: `
  163. <dependency>
  164. <groupId>io.sentry</groupId>
  165. <artifactId>sentry-logback</artifactId>
  166. <version>${
  167. sourcePackageRegistries?.isLoading
  168. ? t('\u2026loading')
  169. : sourcePackageRegistries?.data?.['sentry.java.logback']?.version ?? '6.27.0'
  170. }</version>
  171. </dependency>
  172. `,
  173. },
  174. {
  175. language: 'xml',
  176. description: t(
  177. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  178. ),
  179. code: `
  180. <build>
  181. <plugins>
  182. <plugin>
  183. <groupId>io.sentry</groupId>
  184. <artifactId>sentry-maven-plugin</artifactId>
  185. <version>${
  186. sourcePackageRegistries?.isLoading
  187. ? t('\u2026loading')
  188. : sourcePackageRegistries?.data?.['sentry.java.mavenplugin']?.version ?? '0.0.3'
  189. }</version>
  190. <configuration>
  191. <!-- for showing output of sentry-cli -->
  192. <debugSentryCli>true</debugSentryCli>
  193. <!-- download the latest sentry-cli and provide path to it here -->
  194. <!-- download it here: https://github.com/getsentry/sentry-cli/releases -->
  195. <!-- minimum required version is 2.17.3 -->
  196. <sentryCliExecutablePath>/path/to/sentry-cli</sentryCliExecutablePath>
  197. <org>${organizationSlug}</org>
  198. <project>${projectSlug}</project>
  199. <!-- in case you're self hosting, provide the URL here -->
  200. <!--<url>http://localhost:8000/</url>-->
  201. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  202. <!-- you can find it in Sentry UI: Settings > Account > API > Auth Tokens -->
  203. <authToken>env.SENTRY_AUTH_TOKEN}</authToken>
  204. </configuration>
  205. <executions>
  206. <execution>
  207. <phase>generate-resources</phase>
  208. <goals>
  209. <goal>uploadSourceBundle</goal>
  210. </goals>
  211. </execution>
  212. </executions>
  213. </plugin>
  214. </plugins>
  215. ...
  216. </build>
  217. `,
  218. },
  219. ],
  220. },
  221. {
  222. description: <h5>{t('Gradle')}</h5>,
  223. configurations: [
  224. {
  225. language: 'properties',
  226. partialLoading: sourcePackageRegistries?.isLoading,
  227. code: `implementation 'io.sentry:sentry-logback:${
  228. sourcePackageRegistries?.isLoading
  229. ? t('\u2026loading')
  230. : sourcePackageRegistries?.data?.['sentry.java.logback']?.version ??
  231. '6.27.0'
  232. }'`,
  233. },
  234. {
  235. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  236. description: t(
  237. 'To upload your source code to Sentry so it can be shown in stack traces, use our Gradle plugin.'
  238. ),
  239. code: `
  240. buildscript {
  241. repositories {
  242. mavenCentral()
  243. }
  244. }
  245. plugins {
  246. id "io.sentry.jvm.gradle" version "${
  247. sourcePackageRegistries?.isLoading
  248. ? t('\u2026loading')
  249. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  250. '3.11.1'
  251. }"
  252. }
  253. sentry {
  254. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  255. // This enables source context, allowing you to see your source
  256. // code as part of your stack traces in Sentry.
  257. includeSourceContext = true
  258. org = "${organizationSlug}"
  259. projectName = "${projectSlug}"
  260. authToken = "your-sentry-auth-token"
  261. }
  262. `,
  263. },
  264. ],
  265. },
  266. ],
  267. },
  268. {
  269. type: StepType.VERIFY,
  270. description: t(
  271. 'Then create an intentional error, so you can test that everything is working using either Java or Kotlin:'
  272. ),
  273. configurations: [
  274. {
  275. description: <h5>Java</h5>,
  276. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  277. code: `
  278. import java.lang.Exception;
  279. import io.sentry.Sentry;
  280. try {
  281. throw new Exception("This is a test.");
  282. } catch (Exception e) {
  283. Sentry.captureException(e);
  284. }
  285. `,
  286. },
  287. {
  288. description: <h5>Kotlin</h5>,
  289. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  290. code: `
  291. import java.lang.Exception
  292. import io.sentry.Sentry
  293. try {
  294. throw Exception("This is a test.")
  295. } catch (e: Exception) {
  296. Sentry.captureException(e)
  297. }
  298. `,
  299. },
  300. ],
  301. additionalInfo: (
  302. <Fragment>
  303. <p>
  304. {t(
  305. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  306. )}
  307. </p>
  308. <p>
  309. {t(
  310. "If you're an existing user and have disabled alerts, you won't receive this email."
  311. )}
  312. </p>
  313. </Fragment>
  314. ),
  315. },
  316. {
  317. title: t('Measure Performance'),
  318. description: (
  319. <p>
  320. {tct(
  321. 'Each incoming Spring MVC HTTP request is automatically turned into a transaction. To create spans around bean method executions, annotate bean method with [code:@SentrySpan] annotation:',
  322. {code: <code />}
  323. )}
  324. </p>
  325. ),
  326. configurations: [
  327. {
  328. description: <h5>Java</h5>,
  329. configurations: [
  330. {
  331. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  332. description: <strong>{t('Spring Boot 2')}</strong>,
  333. code: `
  334. import org.springframework.stereotype.Component;
  335. import io.sentry.spring.tracing.SentrySpan;
  336. @Component
  337. class PersonService {
  338. @SentrySpan
  339. Person findById(Long id) {
  340. ...
  341. }
  342. }
  343. `,
  344. },
  345. {
  346. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  347. description: <strong>{t('Spring Boot 3')}</strong>,
  348. code: `
  349. import org.springframework.stereotype.Component;
  350. import io.sentry.spring.jakarta.tracing.SentrySpan;
  351. @Component
  352. class PersonService {
  353. @SentrySpan
  354. Person findById(Long id) {
  355. ...
  356. }
  357. }
  358. `,
  359. },
  360. ],
  361. },
  362. {
  363. description: <h5>Kotlin</h5>,
  364. configurations: [
  365. {
  366. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  367. description: <strong>{t('Spring Boot 2')}</strong>,
  368. code: `
  369. import org.springframework.stereotype.Component
  370. import io.sentry.spring.tracing.SentrySpan
  371. @Component
  372. class PersonService {
  373. @SentrySpan(operation = "task")
  374. fun findById(id: Long): Person {
  375. ...
  376. }
  377. }
  378. `,
  379. },
  380. {
  381. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  382. description: <strong>{t('Spring Boot 3')}</strong>,
  383. code: `
  384. import org.springframework.stereotype.Component
  385. import io.sentry.spring.jakarta.tracing.SentrySpan
  386. @Component
  387. class PersonService {
  388. @SentrySpan(operation = "task")
  389. fun findById(id: Long): Person {
  390. ...
  391. }
  392. }
  393. `,
  394. },
  395. ],
  396. },
  397. ],
  398. additionalInfo: (
  399. <p>
  400. {tct(
  401. 'Check out [docLink:the documentation] to learn more about the API and integrated instrumentations.',
  402. {
  403. docLink: (
  404. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/spring-boot/performance/instrumentation/" />
  405. ),
  406. }
  407. )}
  408. </p>
  409. ),
  410. },
  411. ];
  412. // Configuration End
  413. export function GettingStartedWithSpringBoot({
  414. dsn,
  415. sourcePackageRegistries,
  416. projectSlug,
  417. organization,
  418. ...props
  419. }: ModuleProps) {
  420. return (
  421. <Layout
  422. steps={steps({
  423. dsn,
  424. sourcePackageRegistries,
  425. projectSlug: projectSlug ?? '___PROJECT_SLUG___',
  426. organizationSlug: organization?.slug ?? '___ORG_SLUG___',
  427. })}
  428. introduction={introduction}
  429. {...props}
  430. />
  431. );
  432. }
  433. export default GettingStartedWithSpringBoot;