logback.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. 'The sentry-logback library provides Logback support for Sentry using an [link:Appender] that sends logged exceptions to Sentry.',
  19. {
  20. link: (
  21. <ExternalLink href="https://logback.qos.ch/apidocs/ch/qos/logback/core/Appender.html" />
  22. ),
  23. }
  24. )}
  25. </p>
  26. );
  27. export const steps = ({
  28. dsn,
  29. sourcePackageRegistries,
  30. projectSlug,
  31. organizationSlug,
  32. }: StepsParams): LayoutProps['steps'] => [
  33. {
  34. type: StepType.INSTALL,
  35. description: t(
  36. "Install Sentry's integration with Logback using either Maven or Gradle:"
  37. ),
  38. configurations: [
  39. {
  40. description: (
  41. <p>
  42. {tct(
  43. '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.',
  44. {
  45. link: <Link to="/settings/auth-tokens/" />,
  46. }
  47. )}
  48. </p>
  49. ),
  50. language: 'bash',
  51. code: `
  52. SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
  53. `,
  54. },
  55. {
  56. description: <h5>{t('Gradle')}</h5>,
  57. configurations: [
  58. {
  59. description: (
  60. <p>
  61. {tct(
  62. '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:',
  63. {
  64. code: <code />,
  65. link: (
  66. <ExternalLink href="https://github.com/getsentry/sentry-android-gradle-plugin" />
  67. ),
  68. }
  69. )}
  70. </p>
  71. ),
  72. language: 'groovy',
  73. code: `
  74. buildscript {
  75. repositories {
  76. mavenCentral()
  77. }
  78. }
  79. plugins {
  80. id "io.sentry.jvm.gradle" version "${
  81. sourcePackageRegistries?.isLoading
  82. ? t('\u2026loading')
  83. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  84. '3.12.0'
  85. }"
  86. }
  87. sentry {
  88. // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
  89. // This enables source context, allowing you to see your source
  90. // code as part of your stack traces in Sentry.
  91. includeSourceContext = true
  92. org = "${organizationSlug}"
  93. projectName = "${projectSlug}"
  94. authToken = System.getenv("SENTRY_AUTH_TOKEN")
  95. }
  96. `,
  97. },
  98. ],
  99. },
  100. {
  101. description: <h5>{t('Maven')}</h5>,
  102. configurations: [
  103. {
  104. language: 'xml',
  105. partialLoading: sourcePackageRegistries?.isLoading,
  106. code: `
  107. <dependency>
  108. <groupId>io.sentry</groupId>
  109. <artifactId>sentry-logback</artifactId>
  110. <version>${
  111. sourcePackageRegistries?.isLoading
  112. ? t('\u2026loading')
  113. : sourcePackageRegistries?.data?.['sentry.java.logback']?.version ?? '6.27.0'
  114. }</version>
  115. </dependency>
  116. `,
  117. },
  118. {
  119. language: 'xml',
  120. partialLoading: sourcePackageRegistries?.isLoading,
  121. description: t(
  122. 'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
  123. ),
  124. code: `
  125. <build>
  126. <plugins>
  127. <plugin>
  128. <groupId>io.sentry</groupId>
  129. <artifactId>sentry-maven-plugin</artifactId>
  130. <version>${
  131. sourcePackageRegistries?.isLoading
  132. ? t('\u2026loading')
  133. : sourcePackageRegistries?.data?.['sentry.java.mavenplugin']?.version ?? '0.0.4'
  134. }</version>
  135. <configuration>
  136. <!-- for showing output of sentry-cli -->
  137. <debugSentryCli>true</debugSentryCli>
  138. <org>${organizationSlug}</org>
  139. <project>${projectSlug}</project>
  140. <!-- in case you're self hosting, provide the URL here -->
  141. <!--<url>http://localhost:8000/</url>-->
  142. <!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable -->
  143. <authToken>\${env.SENTRY_AUTH_TOKEN}</authToken>
  144. </configuration>
  145. <executions>
  146. <execution>
  147. <phase>generate-resources</phase>
  148. <goals>
  149. <goal>uploadSourceBundle</goal>
  150. </goals>
  151. </execution>
  152. </executions>
  153. </plugin>
  154. </plugins>
  155. ...
  156. </build>
  157. `,
  158. },
  159. ],
  160. },
  161. ],
  162. additionalInfo: (
  163. <p>
  164. {tct('For other dependency managers see the [link:central Maven repository].', {
  165. link: (
  166. <ExternalLink href="https://search.maven.org/artifact/io.sentry/sentry-logback" />
  167. ),
  168. })}
  169. </p>
  170. ),
  171. },
  172. {
  173. type: StepType.CONFIGURE,
  174. description: t(
  175. "Configure Sentry as soon as possible in your application's lifecycle:"
  176. ),
  177. configurations: [
  178. {
  179. language: 'xml',
  180. description: t(
  181. 'The following example configures a ConsoleAppender that logs to standard out at the INFO level, and a SentryAppender that logs to the Sentry server at the ERROR level. This only an example of a non-Sentry appender set to a different logging threshold, similar to what you may already have in your project.'
  182. ),
  183. code: `
  184. <configuration>
  185. <!-- Configure the Console appender -->
  186. <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
  187. <encoder>
  188. <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
  189. </encoder>
  190. </appender>
  191. <!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
  192. <appender name="Sentry" class="io.sentry.logback.SentryAppender">
  193. <options>
  194. <dsn>${dsn}</dsn>
  195. </options>
  196. </appender>
  197. <!-- Enable the Console and Sentry appenders, Console is provided as an example
  198. of a non-Sentry logger that is set to a different logging threshold -->
  199. <root level="INFO">
  200. <appender-ref ref="Console" />
  201. <appender-ref ref="Sentry" />
  202. </root>
  203. </configuration>
  204. `,
  205. additionalInfo: (
  206. <p>
  207. {tct(
  208. "You'll also need to configure your DSN (client key) if it's not already in the [code:logback.xml] configuration. Learn more in [link:our documentation for DSN configuration].",
  209. {
  210. code: <code />,
  211. link: (
  212. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/logback/#dsn-configuration/" />
  213. ),
  214. }
  215. )}
  216. </p>
  217. ),
  218. },
  219. {
  220. description: (
  221. <p>
  222. {tct(
  223. "Next, you'll need to set your log levels, as illustrated here. You can learn more about [link:configuring log levels] in our documentation.",
  224. {
  225. link: (
  226. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/logback/#minimum-log-level/" />
  227. ),
  228. }
  229. )}
  230. </p>
  231. ),
  232. configurations: [
  233. {
  234. language: 'xml',
  235. code: `
  236. <appender name="Sentry" class="io.sentry.logback.SentryAppender">
  237. <options>
  238. <dsn>${dsn}</dsn>
  239. </options>
  240. <!-- Optionally change minimum Event level. Default for Events is ERROR -->
  241. <minimumEventLevel>WARN</minimumEventLevel>
  242. <!-- Optionally change minimum Breadcrumbs level. Default for Breadcrumbs is INFO -->
  243. <minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
  244. </appender>
  245. `,
  246. },
  247. ],
  248. },
  249. ],
  250. },
  251. {
  252. type: StepType.VERIFY,
  253. description: t(
  254. 'Last, create an intentional error, so you can test that everything is working:'
  255. ),
  256. configurations: [
  257. {
  258. description: <h5>Java</h5>,
  259. language: 'java',
  260. code: `
  261. import java.lang.Exception;
  262. import io.sentry.Sentry;
  263. try {
  264. throw new Exception("This is a test.");
  265. } catch (Exception e) {
  266. Sentry.captureException(e);
  267. }
  268. `,
  269. },
  270. {
  271. description: <h5>Kotlin</h5>,
  272. language: 'java',
  273. code: `
  274. import java.lang.Exception
  275. import io.sentry.Sentry
  276. try {
  277. throw Exception("This is a test.")
  278. } catch (e: Exception) {
  279. Sentry.captureException(e)
  280. }
  281. `,
  282. },
  283. ],
  284. additionalInfo: (
  285. <Fragment>
  286. <p>
  287. {t(
  288. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  289. )}
  290. </p>
  291. <p>
  292. {t(
  293. "If you're an existing user and have disabled alerts, you won't receive this email."
  294. )}
  295. </p>
  296. </Fragment>
  297. ),
  298. },
  299. ];
  300. export const nextSteps = [
  301. {
  302. id: 'examples',
  303. name: t('Examples'),
  304. description: t('Check out our sample applications.'),
  305. link: 'https://github.com/getsentry/sentry-java/tree/main/sentry-samples',
  306. },
  307. ];
  308. // Configuration End
  309. export function GettingStartedWithLogBack({
  310. dsn,
  311. sourcePackageRegistries,
  312. projectSlug,
  313. organization,
  314. ...props
  315. }: ModuleProps) {
  316. const nextStepDocs = [...nextSteps];
  317. return (
  318. <Layout
  319. steps={steps({
  320. dsn,
  321. sourcePackageRegistries,
  322. projectSlug: projectSlug ?? '___PROJECT_SLUG___',
  323. organizationSlug: organization?.slug ?? '___ORG_SLUG___',
  324. })}
  325. nextSteps={nextStepDocs}
  326. introduction={introduction}
  327. {...props}
  328. />
  329. );
  330. }
  331. export default GettingStartedWithLogBack;