spring-boot.tsx 9.4 KB

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