logback.tsx 8.0 KB

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