logback.tsx 9.1 KB

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