spring-boot.tsx 12 KB

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