elixir.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.public}",
  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 [code:mix.exs] file to add it as a dependency and add the [code::sentry] package to your applications:',
  62. {code: <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 [code:Sentry.PlugContext] and [code:Sentry.PlugCapture]:',
  103. {
  104. code: <code />,
  105. }
  106. )}
  107. </p>
  108. </Fragment>
  109. ),
  110. configurations: [
  111. {
  112. language: 'diff',
  113. code: getPlugSnippet(),
  114. },
  115. ],
  116. additionalInfo: tct(
  117. '[code:Sentry.PlugContext] gathers the contextual information for errors, and [code:Sentry.PlugCapture] captures and sends any errors that occur in the Plug stack.',
  118. {
  119. code: <code />,
  120. }
  121. ),
  122. },
  123. {
  124. title: t('Capture Crashed Process Exceptions'),
  125. description: t(
  126. '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:'
  127. ),
  128. configurations: [
  129. {
  130. language: 'elixir',
  131. code: getLoggerHandlerSnippet(),
  132. },
  133. ],
  134. },
  135. ],
  136. verify: () => [
  137. {
  138. type: StepType.VERIFY,
  139. description: t('You can then report errors or messages to Sentry:'),
  140. configurations: [
  141. {
  142. language: 'elixir',
  143. code: getVerifySnippet(),
  144. },
  145. ],
  146. },
  147. ],
  148. };
  149. const crashReportOnboarding: OnboardingConfig = {
  150. introduction: () => getCrashReportModalIntroduction(),
  151. install: (params: Params) => getCrashReportGenericInstallStep(params),
  152. configure: () => [
  153. {
  154. type: StepType.CONFIGURE,
  155. description: getCrashReportModalConfigDescription({
  156. link: 'https://docs.sentry.io/platforms/elixir/user-feedback/configuration/#crash-report-modal',
  157. }),
  158. },
  159. ],
  160. verify: () => [],
  161. nextSteps: () => [],
  162. };
  163. const docs: Docs = {
  164. onboarding,
  165. replayOnboardingJsLoader,
  166. crashReportOnboarding,
  167. };
  168. export default docs;