spring.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. If you're using Spring 5, use [sentrySpringLink:sentry-spring]. If you're using Spring 6, use [sentrySpringJakartaLink:sentry-spring-jakarta] instead. Sentry's integration with Spring supports Spring Framework 5.1.2 and above to report unhandled exceptions and optional user information. If you're on an older version, use [legacyIntegrationLink:our legacy integration].",
  12. {
  13. sentrySpringLink: (
  14. <ExternalLink href="https://github.com/getsentry/sentry-java/tree/master/sentry-spring" />
  15. ),
  16. sentrySpringJakartaLink: (
  17. <ExternalLink href="https://github.com/getsentry/sentry-java/tree/master/sentry-spring-jakarta" />
  18. ),
  19. legacyIntegrationLink: (
  20. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/spring/legacy/" />
  21. ),
  22. }
  23. )}
  24. </p>
  25. );
  26. export const steps = ({
  27. dsn,
  28. sourcePackageRegistries,
  29. }: Partial<
  30. Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
  31. > = {}): LayoutProps['steps'] => [
  32. {
  33. type: StepType.INSTALL,
  34. description: t(
  35. "Install Sentry's integration with Spring using either Maven or Gradle:"
  36. ),
  37. configurations: [
  38. {
  39. description: <h5>{t('Maven')}</h5>,
  40. configurations: [
  41. {
  42. language: 'xml',
  43. partialLoading: sourcePackageRegistries?.isLoading,
  44. description: <strong>{t('Spring 5')}</strong>,
  45. code: `
  46. <dependency>
  47. <groupId>io.sentry</groupId>
  48. <artifactId>sentry-spring</artifactId>
  49. <version>${
  50. sourcePackageRegistries?.isLoading
  51. ? t('\u2026loading')
  52. : sourcePackageRegistries?.data?.['sentry.java.spring']?.version ?? '6.27.0'
  53. }</version>
  54. </dependency>
  55. `,
  56. },
  57. {
  58. language: 'xml',
  59. partialLoading: sourcePackageRegistries?.isLoading,
  60. description: <strong>{t('Spring 6')}</strong>,
  61. code: `
  62. <dependency>
  63. <groupId>io.sentry</groupId>
  64. <artifactId>sentry-spring-jakarta</artifactId>
  65. <version>${
  66. sourcePackageRegistries?.isLoading
  67. ? t('\u2026loading')
  68. : sourcePackageRegistries?.data?.['sentry.java.spring.jakarta']?.version ?? '6.27.0'
  69. }</version>
  70. </dependency>
  71. `,
  72. },
  73. ],
  74. },
  75. ],
  76. },
  77. {
  78. type: StepType.CONFIGURE,
  79. description: (
  80. <Fragment>
  81. {t("Configure Sentry as soon as possible in your application's lifecycle:")}
  82. <p>
  83. {tct(
  84. 'The [codeSentrySpring:sentry-spring] and [codeSentrySpringJakarta:sentry-spring-jakarta] libraries provide an [codeEnableSentry:@EnableSentry] annotation that registers all required Spring beans. [codeEnableSentry:@EnableSentry] can be placed on any class annotated with [configurationLink:@Configuration] including the main entry class in Spring Boot applications annotated with [springBootApplicationLink:@SpringBootApplication].',
  85. {
  86. codeSentrySpring: <code />,
  87. codeSentrySpringJakarta: <code />,
  88. codeEnableSentry: <code />,
  89. configurationLink: (
  90. <ExternalLink href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html" />
  91. ),
  92. springBootApplicationLink: (
  93. <ExternalLink href="https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/SpringBootApplication.html" />
  94. ),
  95. }
  96. )}
  97. </p>
  98. </Fragment>
  99. ),
  100. configurations: [
  101. {
  102. description: <h5>{t('Java')}</h5>,
  103. configurations: [
  104. {
  105. language: 'java',
  106. description: <strong>{t('Spring 5')}</strong>,
  107. code: `
  108. import io.sentry.spring.EnableSentry;
  109. @EnableSentry(dsn = "${dsn}")
  110. @Configuration
  111. class SentryConfiguration {
  112. }
  113. `,
  114. },
  115. {
  116. language: 'java',
  117. description: <strong>{t('Spring 6')}</strong>,
  118. code: `
  119. import io.sentry.spring.jakarta.EnableSentry;
  120. @EnableSentry(dsn = "${dsn}")
  121. @Configuration
  122. class SentryConfiguration {
  123. }
  124. `,
  125. },
  126. ],
  127. },
  128. {
  129. description: <h5>{t('Kotlin')}</h5>,
  130. configurations: [
  131. {
  132. language: 'java',
  133. description: <strong>{t('Spring 5')}</strong>,
  134. code: `
  135. import io.sentry.spring.EnableSentry
  136. import org.springframework.core.Ordered
  137. @EnableSentry(
  138. dsn = "${dsn}",
  139. exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
  140. )
  141. `,
  142. },
  143. {
  144. language: 'java',
  145. description: <strong>{t('Spring 6')}</strong>,
  146. code: `
  147. import io.sentry.spring.jakarta.EnableSentry
  148. import org.springframework.core.Ordered
  149. @EnableSentry(
  150. dsn = "${dsn}",
  151. exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
  152. )
  153. `,
  154. },
  155. ],
  156. },
  157. {
  158. description: <h5>{t('Source Context')}</h5>,
  159. configurations: [
  160. {
  161. language: 'xml',
  162. partialLoading: sourcePackageRegistries?.isLoading,
  163. description: t(
  164. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  165. ),
  166. code: `
  167. <build>
  168. <plugins>
  169. <plugin>
  170. <groupId>io.sentry</groupId>
  171. <artifactId>sentry-maven-plugin</artifactId>
  172. <version>${
  173. sourcePackageRegistries?.isLoading
  174. ? t('\u2026loading')
  175. : sourcePackageRegistries?.data?.['sentry.java.mavenplugin']?.version ?? '0.0.3'
  176. }</version>
  177. <configuration>
  178. <!-- for showing output of sentry-cli -->
  179. <debugSentryCli>true</debugSentryCli>
  180. <!-- download the latest sentry-cli and provide path to it here -->
  181. <!-- download it here: https://github.com/getsentry/sentry-cli/releases -->
  182. <!-- minimum required version is 2.17.3 -->
  183. <sentryCliExecutablePath>/path/to/sentry-cli</sentryCliExecutablePath>
  184. <org>___ORG_SLUG___</org>
  185. <project>___PROJECT_SLUG___</project>
  186. <!-- in case you're self hosting, provide the URL here -->
  187. <!--<url>http://localhost:8000/</url>-->
  188. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  189. <!-- you can find it in Sentry UI: Settings > Account > API > Auth Tokens -->
  190. <authToken>env.SENTRY_AUTH_TOKEN</authToken>
  191. </configuration>
  192. <executions>
  193. <execution>
  194. <phase>generate-resources</phase>
  195. <goals>
  196. <goal>uploadSourceBundle</goal>
  197. </goals>
  198. </execution>
  199. </executions>
  200. </plugin>
  201. </plugins>
  202. ...
  203. `,
  204. },
  205. ],
  206. },
  207. {
  208. description: <h5>{t('Graddle')}</h5>,
  209. configurations: [
  210. {
  211. description: <strong>{t('Spring 5')}</strong>,
  212. language: 'groovy',
  213. partialLoading: sourcePackageRegistries?.isLoading,
  214. code: `implementation 'io.sentry:sentry-spring:${
  215. sourcePackageRegistries?.isLoading
  216. ? t('\u2026loading')
  217. : sourcePackageRegistries?.data?.['sentry.java.spring']?.version ??
  218. '6.27.0'
  219. }'`,
  220. },
  221. {
  222. description: <strong>{t('Spring 6')}</strong>,
  223. language: 'groovy',
  224. code: `implementation 'io.sentry:sentry-spring-jakarta:${
  225. sourcePackageRegistries?.isLoading
  226. ? t('\u2026loading')
  227. : sourcePackageRegistries?.data?.['sentry.java.spring.jakarta']
  228. ?.version ?? '6.27.0'
  229. }'`,
  230. },
  231. ],
  232. },
  233. ],
  234. },
  235. {
  236. type: StepType.VERIFY,
  237. description: t(
  238. 'Last, create an intentional error, so you can test that everything is working:'
  239. ),
  240. configurations: [
  241. {
  242. description: <h5>Java</h5>,
  243. language: 'java',
  244. code: `
  245. import java.lang.Exception;
  246. import io.sentry.Sentry;
  247. try {
  248. throw new Exception("This is a test.");
  249. } catch (Exception e) {
  250. Sentry.captureException(e);
  251. }
  252. `,
  253. },
  254. {
  255. description: <h5>Kotlin</h5>,
  256. language: 'java',
  257. code: `
  258. import java.lang.Exception
  259. import io.sentry.Sentry
  260. try {
  261. throw Exception("This is a test.")
  262. } catch (e: Exception) {
  263. Sentry.captureException(e)
  264. }
  265. `,
  266. },
  267. ],
  268. additionalInfo: (
  269. <Fragment>
  270. <p>
  271. {t(
  272. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  273. )}
  274. </p>
  275. <p>
  276. {t(
  277. "If you're an existing user and have disabled alerts, you won't receive this email."
  278. )}
  279. </p>
  280. </Fragment>
  281. ),
  282. },
  283. {
  284. title: t('Source Context'),
  285. configurations: [
  286. {
  287. language: 'groovy',
  288. partialLoading: sourcePackageRegistries?.isLoading,
  289. description: t(
  290. 'To upload your source code to Sentry so it can be shown in stack traces, use our Gradle plugin.'
  291. ),
  292. code: `
  293. buildscript {
  294. repositories {
  295. mavenCentral()
  296. }
  297. }
  298. plugins {
  299. id "io.sentry.jvm.gradle" version "${
  300. sourcePackageRegistries?.isLoading
  301. ? t('\u2026loading')
  302. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']
  303. ?.version ?? '3.11.1'
  304. }"
  305. }
  306. sentry {
  307. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  308. // This enables source context, allowing you to see your source
  309. // code as part of your stack traces in Sentry.
  310. includeSourceContext = true
  311. org = "___ORG_SLUG___"
  312. projectName = "___PROJECT_SLUG___"
  313. authToken = "your-sentry-auth-token"
  314. }
  315. `,
  316. },
  317. ],
  318. additionalInfo: (
  319. <p>
  320. {tct(
  321. 'For other dependency managers see the [mavenRepositorySpring5Link:central Maven repository (Spring 5)] and [mavenRepositorySpring6Link:central Maven repository (Spring 6)].',
  322. {
  323. mavenRepositorySpring5Link: (
  324. <ExternalLink
  325. href={`https://central.sonatype.com/artifact/io.sentry/sentry-spring/${
  326. sourcePackageRegistries?.data?.['sentry.java.spring']?.version ??
  327. '6.27.0'
  328. }`}
  329. />
  330. ),
  331. mavenRepositorySpring6Link: (
  332. <ExternalLink
  333. href={`https://central.sonatype.com/artifact/io.sentry/sentry-spring-jakarta/${
  334. sourcePackageRegistries?.data?.['sentry.java.spring.jakarta']
  335. ?.version ?? '6.27.0'
  336. }`}
  337. />
  338. ),
  339. }
  340. )}
  341. </p>
  342. ),
  343. },
  344. {
  345. title: t('Measure Performance'),
  346. description: (
  347. <p>
  348. {tct(
  349. 'Check out [link:the documentation] to learn how to configure and use Sentry Performance Monitoring with Spring.',
  350. {
  351. link: (
  352. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/spring/performance/" />
  353. ),
  354. }
  355. )}
  356. </p>
  357. ),
  358. },
  359. ];
  360. // Configuration End
  361. export function GettingStartedWithSpring({
  362. dsn,
  363. sourcePackageRegistries,
  364. ...props
  365. }: ModuleProps) {
  366. return (
  367. <Layout
  368. steps={steps({dsn, sourcePackageRegistries})}
  369. introduction={introduction}
  370. {...props}
  371. />
  372. );
  373. }
  374. export default GettingStartedWithSpring;