java.tsx 7.7 KB

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