spring.tsx 12 KB

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