java.tsx 8.8 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 {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  5. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  6. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  7. import {t, tct} from 'sentry/locale';
  8. interface StepsParams {
  9. dsn: string;
  10. organizationSlug?: string;
  11. projectSlug?: string;
  12. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  13. }
  14. // Configuration Start
  15. const introduction = (
  16. <p>
  17. {tct(
  18. 'Sentry for Java is a collection of modules provided by Sentry; it supports Java 1.8 and above. At its core, Sentry for Java provides a raw client for sending events to Sentry. If you use [strong:Spring Boot, Spring, Logback, or Log4j2], we recommend visiting our Sentry Java documentation for installation instructions.',
  19. {
  20. strong: <strong />,
  21. link: <ExternalLink href="https://docs.sentry.io/platforms/java/" />,
  22. }
  23. )}
  24. </p>
  25. );
  26. export const steps = ({
  27. dsn,
  28. sourcePackageRegistries,
  29. projectSlug,
  30. organizationSlug,
  31. }: StepsParams): LayoutProps['steps'] => [
  32. {
  33. type: StepType.INSTALL,
  34. description: t('Install the SDK via Gradle, Maven, or SBT:'),
  35. configurations: [
  36. {
  37. description: (
  38. <p>
  39. {tct(
  40. '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.',
  41. {
  42. link: <Link to="/settings/auth-tokens/" />,
  43. }
  44. )}
  45. </p>
  46. ),
  47. language: 'bash',
  48. code: `
  49. SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
  50. `,
  51. },
  52. {
  53. description: <h5>{t('Gradle')}</h5>,
  54. configurations: [
  55. {
  56. language: 'groovy',
  57. partialLoading: sourcePackageRegistries?.isLoading,
  58. description: (
  59. <p>
  60. {tct(
  61. '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:',
  62. {
  63. code: <code />,
  64. link: (
  65. <ExternalLink href="https://github.com/getsentry/sentry-android-gradle-plugin" />
  66. ),
  67. }
  68. )}
  69. </p>
  70. ),
  71. code: `
  72. buildscript {
  73. repositories {
  74. mavenCentral()
  75. }
  76. }
  77. plugins {
  78. id "io.sentry.jvm.gradle" version "${
  79. sourcePackageRegistries?.isLoading
  80. ? t('\u2026loading')
  81. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  82. '3.12.0'
  83. }"
  84. }
  85. sentry {
  86. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  87. // This enables source context, allowing you to see your source
  88. // code as part of your stack traces in Sentry.
  89. includeSourceContext = true
  90. org = "${organizationSlug}"
  91. projectName = "${projectSlug}"
  92. authToken = System.getenv("SENTRY_AUTH_TOKEN")
  93. }
  94. `,
  95. },
  96. ],
  97. },
  98. {
  99. description: <h5>{t('Maven')}</h5>,
  100. configurations: [
  101. {
  102. language: 'xml',
  103. partialLoading: sourcePackageRegistries?.isLoading,
  104. description: (
  105. <p>
  106. {tct('For Maven, add to your [code:pom.xml] file:', {code: <code />})}
  107. </p>
  108. ),
  109. code: `
  110. <dependency>
  111. <groupId>io.sentry</groupId>
  112. <artifactId>sentry</artifactId>
  113. <version>${
  114. sourcePackageRegistries?.isLoading
  115. ? t('\u2026loading')
  116. : sourcePackageRegistries?.data?.['sentry.java']?.version ?? '6.27.0'
  117. }</version>
  118. </dependency>
  119. `,
  120. },
  121. {
  122. language: 'xml',
  123. partialLoading: sourcePackageRegistries?.isLoading,
  124. description: t(
  125. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  126. ),
  127. code: `
  128. <build>
  129. <plugins>
  130. <plugin>
  131. <groupId>io.sentry</groupId>
  132. <artifactId>sentry-maven-plugin</artifactId>
  133. <version>${
  134. sourcePackageRegistries?.isLoading
  135. ? t('\u2026loading')
  136. : sourcePackageRegistries?.data?.['sentry.java.mavenplugin']?.version ?? '0.0.4'
  137. }</version>
  138. <configuration>
  139. <!-- for showing output of sentry-cli -->
  140. <debugSentryCli>true</debugSentryCli>
  141. <org>${organizationSlug}</org>
  142. <project>${projectSlug}</project>
  143. <!-- in case you're self hosting, provide the URL here -->
  144. <!--<url>http://localhost:8000/</url>-->
  145. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  146. <authToken>\${env.SENTRY_AUTH_TOKEN}</authToken>
  147. </configuration>
  148. <executions>
  149. <execution>
  150. <phase>generate-resources</phase>
  151. <goals>
  152. <goal>uploadSourceBundle</goal>
  153. </goals>
  154. </execution>
  155. </executions>
  156. </plugin>
  157. </plugins>
  158. ...
  159. </build>
  160. `,
  161. },
  162. ],
  163. },
  164. {
  165. description: <h5>{t('SBT')}</h5>,
  166. configurations: [
  167. {
  168. description: <p>{tct('For [strong:SBT]:', {strong: <strong />})}</p>,
  169. language: 'scala',
  170. partialLoading: sourcePackageRegistries?.isLoading,
  171. code: `libraryDependencies += "io.sentry" % "sentry" % "${
  172. sourcePackageRegistries?.isLoading
  173. ? t('\u2026loading')
  174. : sourcePackageRegistries?.data?.['sentry.java']?.version ?? '6.27.0'
  175. }"`,
  176. },
  177. ],
  178. },
  179. ],
  180. additionalInfo: (
  181. <p>
  182. {tct(
  183. 'To upload your source code to Sentry so it can be shown in stack traces, please refer to [link:Manually Uploading Source Context].',
  184. {
  185. link: (
  186. <ExternalLink href="https://docs.sentry.io/platforms/java/source-context/" />
  187. ),
  188. }
  189. )}
  190. </p>
  191. ),
  192. },
  193. {
  194. type: StepType.CONFIGURE,
  195. description: t(
  196. "Configure Sentry as soon as possible in your application's lifecycle:"
  197. ),
  198. configurations: [
  199. {
  200. language: 'java',
  201. code: `
  202. import io.sentry.Sentry;
  203. Sentry.init(options -> {
  204. options.setDsn("${dsn}");
  205. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  206. // We recommend adjusting this value in production.
  207. options.setTracesSampleRate(1.0);
  208. // When first trying Sentry it's good to see what the SDK is doing:
  209. options.setDebug(true);
  210. });
  211. `,
  212. },
  213. ],
  214. },
  215. {
  216. type: StepType.VERIFY,
  217. description: (
  218. <p>
  219. {tct(
  220. 'Trigger your first event from your development environment by intentionally creating an error with the [code:Sentry#captureException] method, to test that everything is working:',
  221. {code: <code />}
  222. )}
  223. </p>
  224. ),
  225. configurations: [
  226. {
  227. language: 'java',
  228. code: `
  229. import java.lang.Exception;
  230. import io.sentry.Sentry;
  231. try {
  232. throw new Exception("This is a test.");
  233. } catch (Exception e) {
  234. Sentry.captureException(e);
  235. }
  236. `,
  237. },
  238. ],
  239. additionalInfo: (
  240. <Fragment>
  241. <p>
  242. {t(
  243. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  244. )}
  245. </p>
  246. <p>
  247. {t(
  248. "If you're an existing user and have disabled alerts, you won't receive this email."
  249. )}
  250. </p>
  251. </Fragment>
  252. ),
  253. },
  254. ];
  255. export const nextSteps = [
  256. {
  257. id: 'examples',
  258. name: t('Examples'),
  259. description: t('Check out our sample applications.'),
  260. link: 'https://github.com/getsentry/sentry-java/tree/main/sentry-samples',
  261. },
  262. {
  263. id: 'performance-monitoring',
  264. name: t('Performance Monitoring'),
  265. description: t(
  266. 'Stay ahead of latency issues and trace every slow transaction to a poor-performing API call or database query.'
  267. ),
  268. link: 'https://docs.sentry.io/platforms/java/performance/',
  269. },
  270. ];
  271. // Configuration End
  272. export function GettingStartedWithJava({
  273. dsn,
  274. sourcePackageRegistries,
  275. projectSlug,
  276. organization,
  277. ...props
  278. }: ModuleProps) {
  279. const nextStepDocs = [...nextSteps];
  280. return (
  281. <Layout
  282. steps={steps({
  283. dsn,
  284. sourcePackageRegistries,
  285. projectSlug: projectSlug ?? '___PROJECT_SLUG___',
  286. organizationSlug: organization?.slug ?? '___ORG_SLUG___',
  287. })}
  288. nextSteps={nextStepDocs}
  289. introduction={introduction}
  290. projectSlug={projectSlug}
  291. {...props}
  292. />
  293. );
  294. }
  295. export default GettingStartedWithJava;