spring.tsx 9.7 KB

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