logback.tsx 7.9 KB

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