elixir.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import {Fragment} from 'react';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {
  9. getCrashReportGenericInstallStep,
  10. getCrashReportModalConfigDescription,
  11. getCrashReportModalIntroduction,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import {
  14. feedbackOnboardingJsLoader,
  15. replayOnboardingJsLoader,
  16. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  17. import {t, tct} from 'sentry/locale';
  18. type Params = DocsParams;
  19. const getInstallSnippet = () => `
  20. defp deps do
  21. [
  22. # ...
  23. {:sentry, "~> 10.2.0"},
  24. {:jason, "~> 1.2"},
  25. {:hackney, "~> 1.8"}
  26. ]
  27. end`;
  28. const getConfigureSnippet = (params: Params) => `
  29. config :sentry,
  30. dsn: "${params.dsn.public}",
  31. environment_name: Mix.env(),
  32. enable_source_code_context: true,
  33. root_source_code_paths: [File.cwd!()]`;
  34. const getPlugSnippet = () => `
  35. defmodule MyAppWeb.Endpoint
  36. + use Sentry.PlugCapture
  37. use Phoenix.Endpoint, otp_app: :my_app
  38. # ...
  39. plug Plug.Parsers,
  40. parsers: [:urlencoded, :multipart, :json],
  41. pass: ["*/*"],
  42. json_decoder: Phoenix.json_library()
  43. + plug Sentry.PlugContext`;
  44. const getLoggerHandlerSnippet = () => `
  45. # lib/my_app/application.ex
  46. def start(_type, _args) do
  47. :logger.add_handler(:my_sentry_handler, Sentry.LoggerHandler, %{
  48. config: %{metadata: [:file, :line]}
  49. })
  50. # ...
  51. end`;
  52. const getVerifySnippet = () => `
  53. try do
  54. ThisWillError.really()
  55. rescue
  56. my_exception ->
  57. Sentry.capture_exception(my_exception, stacktrace: __STACKTRACE__)
  58. end`;
  59. const onboarding: OnboardingConfig = {
  60. install: () => [
  61. {
  62. type: StepType.INSTALL,
  63. description: tct(
  64. 'Edit your [code:mix.exs] file to add it as a dependency and add the [code::sentry] package to your applications:',
  65. {code: <code />}
  66. ),
  67. configurations: [
  68. {
  69. language: 'elixir',
  70. description: <p>{tct('Install [code:sentry-sdk]:', {code: <code />})}</p>,
  71. code: getInstallSnippet(),
  72. },
  73. ],
  74. },
  75. ],
  76. configure: params => [
  77. {
  78. type: StepType.CONFIGURE,
  79. description: tct(
  80. 'Setup the application production environment in your [code:config/prod.exs]',
  81. {
  82. code: <code />,
  83. }
  84. ),
  85. configurations: [
  86. {
  87. language: 'elixir',
  88. code: getConfigureSnippet(params),
  89. },
  90. ],
  91. },
  92. {
  93. title: t('Package Source Code'),
  94. description: tct(
  95. 'Add a call to [code:mix sentry.package_source_code] in your release script to make sure the stacktraces you receive are complete.',
  96. {code: <code />}
  97. ),
  98. },
  99. {
  100. title: t('Setup for Plug and Phoenix Applications'),
  101. description: (
  102. <Fragment>
  103. <p>
  104. {tct(
  105. 'You can capture errors in Plug (and Phoenix) applications with [code:Sentry.PlugContext] and [code:Sentry.PlugCapture]:',
  106. {
  107. code: <code />,
  108. }
  109. )}
  110. </p>
  111. </Fragment>
  112. ),
  113. configurations: [
  114. {
  115. language: 'diff',
  116. code: getPlugSnippet(),
  117. },
  118. ],
  119. additionalInfo: tct(
  120. '[code:Sentry.PlugContext] gathers the contextual information for errors, and [code:Sentry.PlugCapture] captures and sends any errors that occur in the Plug stack.',
  121. {
  122. code: <code />,
  123. }
  124. ),
  125. },
  126. {
  127. title: t('Capture Crashed Process Exceptions'),
  128. description: t(
  129. 'This library comes with an extension to capture all error messages that the Plug handler might not. This is based on adding an erlang logger handler when your application starts:'
  130. ),
  131. configurations: [
  132. {
  133. language: 'elixir',
  134. code: getLoggerHandlerSnippet(),
  135. },
  136. ],
  137. },
  138. ],
  139. verify: () => [
  140. {
  141. type: StepType.VERIFY,
  142. description: t('You can then report errors or messages to Sentry:'),
  143. configurations: [
  144. {
  145. language: 'elixir',
  146. code: getVerifySnippet(),
  147. },
  148. ],
  149. },
  150. ],
  151. };
  152. const crashReportOnboarding: OnboardingConfig = {
  153. introduction: () => getCrashReportModalIntroduction(),
  154. install: (params: Params) => getCrashReportGenericInstallStep(params),
  155. configure: () => [
  156. {
  157. type: StepType.CONFIGURE,
  158. description: getCrashReportModalConfigDescription({
  159. link: 'https://docs.sentry.io/platforms/elixir/user-feedback/configuration/#crash-report-modal',
  160. }),
  161. },
  162. ],
  163. verify: () => [],
  164. nextSteps: () => [],
  165. };
  166. const docs: Docs = {
  167. onboarding,
  168. replayOnboardingJsLoader,
  169. crashReportOnboarding,
  170. feedbackOnboardingJsLoader,
  171. };
  172. export default docs;