spring-boot.tsx 14 KB

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