spring.tsx 9.8 KB

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