spring-boot.tsx 12 KB

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