logback.tsx 9.4 KB

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