elixir.tsx 4.9 KB

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