spring-boot.tsx 11 KB

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