spring-boot.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import Link from 'sentry/components/links/link';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {
  6. BasePlatformOptions,
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {t, tct} from 'sentry/locale';
  12. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  13. export enum SpringBootVersion {
  14. V2 = 'v2',
  15. V3 = 'v3',
  16. }
  17. export enum PackageManager {
  18. GRADLE = 'gradle',
  19. MAVEN = 'maven',
  20. }
  21. const platformOptions = {
  22. springBootVersion: {
  23. label: t('Spring Boot Version'),
  24. items: [
  25. {
  26. label: t('Spring Boot 3'),
  27. value: SpringBootVersion.V3,
  28. },
  29. {
  30. label: t('Spring Boot 2'),
  31. value: SpringBootVersion.V2,
  32. },
  33. ],
  34. },
  35. packageManager: {
  36. label: t('Package Manager'),
  37. items: [
  38. {
  39. label: t('Gradle'),
  40. value: PackageManager.GRADLE,
  41. },
  42. {
  43. label: t('Maven'),
  44. value: PackageManager.MAVEN,
  45. },
  46. ],
  47. },
  48. } satisfies BasePlatformOptions;
  49. type PlatformOptions = typeof platformOptions;
  50. type Params = DocsParams<PlatformOptions>;
  51. const getGradleInstallSnippet = (params: Params) => `
  52. buildscript {
  53. repositories {
  54. mavenCentral()
  55. }
  56. }
  57. plugins {
  58. id "io.sentry.jvm.gradle" version "${getPackageVersion(
  59. params,
  60. 'sentry.java.android.gradle-plugin',
  61. '3.12.0'
  62. )}"
  63. }
  64. sentry {
  65. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  66. // This enables source context, allowing you to see your source
  67. // code as part of your stack traces in Sentry.
  68. includeSourceContext = true
  69. org = "${params.organization.slug}"
  70. projectName = "${params.projectSlug}"
  71. authToken = System.getenv("SENTRY_AUTH_TOKEN")
  72. }`;
  73. const getMavenInstallSnippet = (params: Params) =>
  74. params.platformOptions.springBootVersion === SpringBootVersion.V3
  75. ? `
  76. <dependency>
  77. <groupId>io.sentry</groupId>
  78. <artifactId>sentry-spring-boot-starter-jakarta</artifactId>
  79. <version>${getPackageVersion(
  80. params,
  81. 'sentry.java.spring-boot.jakarta',
  82. '6.28.0'
  83. )}</version>
  84. </dependency>`
  85. : `
  86. <dependency>
  87. <groupId>io.sentry</groupId>
  88. <artifactId>sentry-spring-boot-starter</artifactId>
  89. <version>${
  90. params.sourcePackageRegistries?.isLoading
  91. ? t('\u2026loading')
  92. : params.sourcePackageRegistries?.data?.['sentry.java.spring-boot']?.version ??
  93. '6.28.0'
  94. }</version>
  95. </dependency>`;
  96. const getLogbackInstallSnippet = (params: Params) => `
  97. <dependency>
  98. <groupId>io.sentry</groupId>
  99. <artifactId>sentry-logback</artifactId>
  100. <version>${getPackageVersion(params, 'sentry.java.logback', '6.28.0')}</version>
  101. </dependency>`;
  102. const getMavenPluginSnippet = (params: Params) => `
  103. <build>
  104. <plugins>
  105. <plugin>
  106. <groupId>io.sentry</groupId>
  107. <artifactId>sentry-maven-plugin</artifactId>
  108. <version>${
  109. params.sourcePackageRegistries?.isLoading
  110. ? t('\u2026loading')
  111. : params.sourcePackageRegistries?.data?.['sentry.java.mavenplugin']?.version ??
  112. '0.0.4'
  113. }</version>
  114. <configuration>
  115. <!-- for showing output of sentry-cli -->
  116. <debugSentryCli>true</debugSentryCli>
  117. <org>${params.organization.slug}</org>
  118. <project>${params.projectSlug}</project>
  119. <!-- in case you're self hosting, provide the URL here -->
  120. <!--<url>http://localhost:8000/</url>-->
  121. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  122. <authToken>\${env.SENTRY_AUTH_TOKEN}</authToken>
  123. </configuration>
  124. <executions>
  125. <execution>
  126. <phase>generate-resources</phase>
  127. <goals>
  128. <goal>uploadSourceBundle</goal>
  129. </goals>
  130. </execution>
  131. </executions>
  132. </plugin>
  133. </plugins>
  134. ...
  135. </build>`;
  136. const getConfigurationPropertiesSnippet = (params: Params) => `
  137. sentry.dsn=${params.dsn}${
  138. params.isPerformanceSelected
  139. ? `
  140. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  141. # We recommend adjusting this value in production.
  142. sentry.traces-sample-rate=1.0`
  143. : ''
  144. }`;
  145. const getConfigurationYamlSnippet = (params: Params) => `
  146. sentry:
  147. dsn: ${params.dsn}${
  148. params.isPerformanceSelected
  149. ? `
  150. # Set traces-sample-rate to 1.0 to capture 100% of transactions for performance monitoring.
  151. # We recommend adjusting this value in production.
  152. sentry.traces-sample-rate: 1.0`
  153. : ''
  154. }`;
  155. const getVerifyJavaSnippet = () => `
  156. import java.lang.Exception;
  157. import io.sentry.Sentry;
  158. try {
  159. throw new Exception("This is a test.");
  160. } catch (Exception e) {
  161. Sentry.captureException(e);
  162. }`;
  163. const getVerifyKotlinSnippet = () => `
  164. import java.lang.Exception
  165. import io.sentry.Sentry
  166. try {
  167. throw Exception("This is a test.")
  168. } catch (e: Exception) {
  169. Sentry.captureException(e)
  170. }`;
  171. const onboarding: OnboardingConfig<PlatformOptions> = {
  172. introduction: () =>
  173. tct(
  174. "Sentry's integration with [springBootLink:Spring Boot] supports Spring Boot 2.1.0 and above. If you're on an older version, use [legacyIntegrationLink:our legacy integration].",
  175. {
  176. springBootLink: <ExternalLink href="https://spring.io/projects/spring-boot" />,
  177. legacyIntegrationLink: (
  178. <ExternalLink href="https://docs.sentry.io/platforms/java/legacy/spring/" />
  179. ),
  180. }
  181. ),
  182. install: (params: Params) => [
  183. {
  184. type: StepType.INSTALL,
  185. configurations: [
  186. {
  187. description: tct(
  188. 'To see source context in Sentry, you have to generate an auth token by visiting the [link:Organization Auth Tokens] settings. You can then set the token as an environment variable that is used by the build plugins.',
  189. {
  190. link: <Link to="/settings/auth-tokens/" />,
  191. }
  192. ),
  193. language: 'bash',
  194. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  195. },
  196. params.platformOptions.packageManager === PackageManager.GRADLE
  197. ? {
  198. description: tct(
  199. 'The [link:Sentry Gradle Plugin] automatically installs the Sentry SDK as well as available integrations for your dependencies. Add the following to your [code:build.gradle] file:',
  200. {
  201. code: <code />,
  202. link: (
  203. <ExternalLink href="https://github.com/getsentry/sentry-android-gradle-plugin" />
  204. ),
  205. }
  206. ),
  207. language: 'groovy',
  208. code: getGradleInstallSnippet(params),
  209. }
  210. : {
  211. description: t('Install using Maven:'),
  212. configurations: [
  213. {
  214. language: 'xml',
  215. partialLoading: params.sourcePackageRegistries?.isLoading,
  216. code: getMavenInstallSnippet(params),
  217. additionalInfo: tct(
  218. '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. Sentry Spring Boot Starter will auto-configure [sentryAppenderCode:SentryAppender].',
  219. {sentryAppenderCode: <code />, sentryLogbackCode: <code />}
  220. ),
  221. },
  222. {
  223. language: 'xml',
  224. code: getLogbackInstallSnippet(params),
  225. },
  226. {
  227. language: 'xml',
  228. description: t(
  229. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  230. ),
  231. code: getMavenPluginSnippet(params),
  232. },
  233. ],
  234. },
  235. ],
  236. },
  237. ],
  238. configure: (params: Params) => [
  239. {
  240. type: StepType.CONFIGURE,
  241. description: tct(
  242. 'Open up [applicationPropertiesCode:src/main/application.properties] (or [applicationYmlCode:src/main/application.yml]) and configure the DSN, and any other settings you need:',
  243. {
  244. applicationPropertiesCode: <code />,
  245. applicationYmlCode: <code />,
  246. }
  247. ),
  248. configurations: [
  249. {
  250. code: [
  251. {
  252. label: 'Properties',
  253. value: 'properties',
  254. language: 'properties',
  255. code: getConfigurationPropertiesSnippet(params),
  256. },
  257. {
  258. label: 'YAML',
  259. value: 'yaml',
  260. language: 'properties',
  261. code: getConfigurationYamlSnippet(params),
  262. },
  263. ],
  264. },
  265. ],
  266. },
  267. ],
  268. verify: () => [
  269. {
  270. type: StepType.VERIFY,
  271. description: t(
  272. 'Then create an intentional error, so you can test that everything is working using either Java or Kotlin:'
  273. ),
  274. configurations: [
  275. {
  276. code: [
  277. {
  278. label: 'Java',
  279. value: 'java',
  280. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  281. code: getVerifyJavaSnippet(),
  282. },
  283. {
  284. label: 'Kotlin',
  285. value: 'kotlin',
  286. language: 'javascript', // TODO: This shouldn't be javascript but because of better formatting we use it for now
  287. code: getVerifyKotlinSnippet(),
  288. },
  289. ],
  290. },
  291. ],
  292. additionalInfo: (
  293. <Fragment>
  294. <p>
  295. {t(
  296. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  297. )}
  298. </p>
  299. <p>
  300. {t(
  301. "If you're an existing user and have disabled alerts, you won't receive this email."
  302. )}
  303. </p>
  304. </Fragment>
  305. ),
  306. },
  307. ],
  308. nextSteps: () => [
  309. {
  310. id: 'examples',
  311. name: t('Examples'),
  312. description: t('Check out our sample applications.'),
  313. link: 'https://github.com/getsentry/sentry-java/tree/main/sentry-samples',
  314. },
  315. {
  316. id: 'performance-monitoring',
  317. name: t('Performance Monitoring'),
  318. description: t(
  319. 'Stay ahead of latency issues and trace every slow transaction to a poor-performing API call or database query.'
  320. ),
  321. link: 'https://docs.sentry.io/platforms/java/guides/spring-boot/performance/',
  322. },
  323. ],
  324. };
  325. const docs: Docs<PlatformOptions> = {
  326. onboarding,
  327. platformOptions,
  328. };
  329. export default docs;