java.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 = tct(
  9. '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.',
  10. {
  11. strong: <strong />,
  12. link: <ExternalLink href="https://docs.sentry.io/platforms/java/" />,
  13. }
  14. );
  15. export const steps = ({
  16. dsn,
  17. }: {
  18. dsn?: string;
  19. } = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: t('Install the SDK via Gradle, Maven, or SBT:'),
  23. configurations: [
  24. {
  25. description: <h5>{t('Gradle')}</h5>,
  26. configurations: [
  27. {
  28. language: 'groovy',
  29. description: (
  30. <p>
  31. {tct('For Gradle, add to your [code:build.gradle] file:', {
  32. code: <code />,
  33. })}
  34. </p>
  35. ),
  36. code: `
  37. // Make sure mavenCentral is there.
  38. repositories {
  39. mavenCentral()
  40. }
  41. // Add Sentry's SDK as a dependency.
  42. dependencies {
  43. implementation 'io.sentry:sentry:6.25.2'
  44. }
  45. `,
  46. },
  47. {
  48. language: 'groovy',
  49. description: t(
  50. 'To upload your source code to Sentry so it can be shown in stack traces, use our Gradle plugin.'
  51. ),
  52. code: `
  53. buildscript {
  54. repositories {
  55. mavenCentral()
  56. }
  57. }
  58. plugins {
  59. id "io.sentry.jvm.gradle" version "3.11.1"
  60. }
  61. sentry {
  62. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  63. // This enables source context, allowing you to see your source
  64. // code as part of your stack traces in Sentry.
  65. includeSourceContext = true
  66. org = "___ORG_SLUG___"
  67. projectName = "___PROJECT_SLUG___"
  68. authToken = "your-sentry-auth-token"
  69. }
  70. `,
  71. },
  72. ],
  73. },
  74. {
  75. description: <h5>{t('Maven')}</h5>,
  76. configurations: [
  77. {
  78. language: 'xml',
  79. description: (
  80. <p>
  81. {tct('For Maven, add to your [code:pom.xml] file:', {code: <code />})}
  82. </p>
  83. ),
  84. code: `
  85. <dependency>
  86. <groupId>io.sentry</groupId>
  87. <artifactId>sentry</artifactId>
  88. <version>6.25.2</version>
  89. </dependency>
  90. `,
  91. },
  92. {
  93. language: 'xml',
  94. description: t(
  95. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  96. ),
  97. code: `
  98. <build>
  99. <plugins>
  100. <plugin>
  101. <groupId>io.sentry</groupId>
  102. <artifactId>sentry-maven-plugin</artifactId>
  103. <version>0.0.2</version>
  104. <configuration>
  105. <!-- for showing output of sentry-cli -->
  106. <debugSentryCli>true</debugSentryCli>
  107. <!-- download the latest sentry-cli and provide path to it here -->
  108. <!-- download it here: https://github.com/getsentry/sentry-cli/releases -->
  109. <!-- minimum required version is 2.17.3 -->
  110. <sentryCliExecutablePath>/path/to/sentry-cli</sentryCliExecutablePath>
  111. <org>___ORG_SLUG___</org>
  112. <project>___PROJECT_SLUG___</project>
  113. <!-- in case you're self hosting, provide the URL here -->
  114. <!--<url>http://localhost:8000/</url>-->
  115. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  116. <!-- you can find it in Sentry UI: Settings > Account > API > Auth Tokens -->
  117. <authToken>env.SENTRY_AUTH_TOKEN</authToken>
  118. </configuration>
  119. <executions>
  120. <execution>
  121. <phase>generate-resources</phase>
  122. <goals>
  123. <goal>uploadSourceBundle</goal>
  124. </goals>
  125. </execution>
  126. </executions>
  127. </plugin>
  128. </plugins>
  129. ...
  130. </build>
  131. `,
  132. },
  133. ],
  134. },
  135. {
  136. description: <h5>{t('SBT')}</h5>,
  137. configurations: [
  138. {
  139. description: <p>{tct('For [strong:SBT]:', {strong: <strong />})}</p>,
  140. language: 'scala',
  141. code: `libraryDependencies += "io.sentry" % "sentry" % "6.25.2"`,
  142. },
  143. ],
  144. },
  145. ],
  146. additionalInfo: (
  147. <p>
  148. {tct(
  149. 'To upload your source code to Sentry so it can be shown in stack traces, please refer to [link:Manually Uploading Source Context].',
  150. {
  151. link: (
  152. <ExternalLink href="https://docs.sentry.io/platforms/java/source-context/" />
  153. ),
  154. }
  155. )}
  156. </p>
  157. ),
  158. },
  159. {
  160. type: StepType.CONFIGURE,
  161. description: t(
  162. "Configure Sentry as soon as possible in your application's lifecycle:"
  163. ),
  164. configurations: [
  165. {
  166. language: 'java',
  167. code: `
  168. import io.sentry.Sentry;
  169. Sentry.init(options -> {
  170. options.setDsn("${dsn}");
  171. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  172. // We recommend adjusting this value in production.
  173. options.setTracesSampleRate(1.0);
  174. // When first trying Sentry it's good to see what the SDK is doing:
  175. options.setDebug(true);
  176. });
  177. `,
  178. },
  179. ],
  180. },
  181. {
  182. type: StepType.VERIFY,
  183. description: (
  184. <p>
  185. {tct(
  186. '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:',
  187. {code: <code />}
  188. )}
  189. </p>
  190. ),
  191. configurations: [
  192. {
  193. language: 'java',
  194. code: `
  195. import java.lang.Exception;
  196. import io.sentry.Sentry;
  197. try {
  198. throw new Exception("This is a test.");
  199. } catch (Exception e) {
  200. Sentry.captureException(e);
  201. }
  202. `,
  203. },
  204. ],
  205. additionalInfo: (
  206. <Fragment>
  207. <p>
  208. {t(
  209. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  210. )}
  211. </p>
  212. <p>
  213. {t(
  214. "If you're an existing user and have disabled alerts, you won't receive this email."
  215. )}
  216. </p>
  217. </Fragment>
  218. ),
  219. },
  220. {
  221. title: t('Measure Performance'),
  222. description: t('You can capture transactions using the SDK. For example:'),
  223. configurations: [
  224. {
  225. language: 'java',
  226. code: `
  227. import io.sentry.ITransaction;
  228. import io.sentry.Sentry;
  229. import io.sentry.SpanStatus;
  230. // A good name for the transaction is key, to help identify what this is about
  231. ITransaction transaction = Sentry.startTransaction("processOrderBatch()", "task");
  232. try {
  233. processOrderBatch();
  234. } catch (Exception e) {
  235. transaction.setThrowable(e);
  236. transaction.setStatus(SpanStatus.INTERNAL_ERROR);
  237. throw e;
  238. } finally {
  239. transaction.finish();
  240. }
  241. `,
  242. },
  243. ],
  244. additionalInfo: (
  245. <p>
  246. {tct(
  247. 'For more information about the API and automatic instrumentations included in the SDK, [link:visit the docs].',
  248. {
  249. link: (
  250. <ExternalLink href="https://docs.sentry.io/platforms/java/performance/" />
  251. ),
  252. }
  253. )}
  254. </p>
  255. ),
  256. },
  257. ];
  258. // Configuration End
  259. export function GettingStartedWithJava({dsn, ...props}: ModuleProps) {
  260. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  261. }
  262. export default GettingStartedWithJava;