rails.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import ExternalLink from 'sentry/components/links/externalLink';
  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. getCrashReportModalConfigDescription,
  10. getCrashReportModalIntroduction,
  11. getCrashReportSDKInstallFirstStepRails,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import {getRubyMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  14. import {
  15. feedbackOnboardingJsLoader,
  16. replayOnboardingJsLoader,
  17. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  18. import {t, tct} from 'sentry/locale';
  19. type Params = DocsParams;
  20. const getInstallSnippet = (
  21. params: Params
  22. ) => `${params.isProfilingSelected ? 'gem "stackprof"\n' : ''}gem "sentry-ruby"
  23. gem "sentry-rails"`;
  24. const generatorSnippet = 'bin/rails generate sentry';
  25. const getConfigureSnippet = (params: Params) => `
  26. Sentry.init do |config|
  27. config.dsn = '${params.dsn.public}'
  28. config.breadcrumbs_logger = [:active_support_logger, :http_logger]${
  29. params.isPerformanceSelected
  30. ? `
  31. # Set traces_sample_rate to 1.0 to capture 100%
  32. # of transactions for tracing.
  33. # We recommend adjusting this value in production.
  34. config.traces_sample_rate = 1.0
  35. # or
  36. config.traces_sampler = lambda do |context|
  37. true
  38. end`
  39. : ''
  40. }${
  41. params.isProfilingSelected
  42. ? `
  43. # Set profiles_sample_rate to profile 100%
  44. # of sampled transactions.
  45. # We recommend adjusting this value in production.
  46. config.profiles_sample_rate = 1.0`
  47. : ''
  48. }
  49. end`;
  50. const getVerifySnippet = () => `
  51. begin
  52. 1 / 0
  53. rescue ZeroDivisionError => exception
  54. Sentry.capture_exception(exception)
  55. end
  56. Sentry.capture_message("test message")`;
  57. const onboarding: OnboardingConfig = {
  58. introduction: () =>
  59. t(
  60. 'In Rails, all uncaught exceptions will be automatically reported. We support Rails 5 and newer.'
  61. ),
  62. install: (params: Params) => [
  63. {
  64. type: StepType.INSTALL,
  65. description: tct(
  66. 'The Sentry SDK for Rails comes as two gems that should be added to your [gemfileCode:Gemfile]:',
  67. {
  68. gemfileCode: <code />,
  69. }
  70. ),
  71. configurations: [
  72. {
  73. language: 'ruby',
  74. code: getInstallSnippet(params),
  75. additionalInfo: params.isProfilingSelected
  76. ? tct(
  77. 'Ruby Profiling beta is available since SDK version 5.9.0. We use the [stackprofLink:stackprof gem] to collect profiles for Ruby. Make sure [code:stackprof] is loaded before [code:sentry-ruby].',
  78. {
  79. stackprofLink: (
  80. <ExternalLink href="https://github.com/tmm1/stackprof" />
  81. ),
  82. code: <code />,
  83. }
  84. )
  85. : undefined,
  86. },
  87. {
  88. description: t('After adding the gems, run the following to install the SDK:'),
  89. language: 'ruby',
  90. code: 'bundle install',
  91. },
  92. ],
  93. },
  94. ],
  95. configure: (params: Params) => [
  96. {
  97. type: StepType.CONFIGURE,
  98. description: tct(
  99. 'Run the following Rails generator to create the initializer file [code:config/initializers/sentry.rb].',
  100. {
  101. code: <code />,
  102. }
  103. ),
  104. configurations: [
  105. {
  106. language: 'ruby',
  107. code: generatorSnippet,
  108. },
  109. {
  110. description: t('You can then change the Sentry configuration as follows:'),
  111. },
  112. {
  113. language: 'ruby',
  114. code: getConfigureSnippet(params),
  115. },
  116. ],
  117. },
  118. ],
  119. verify: () => [
  120. {
  121. type: StepType.VERIFY,
  122. description: t(
  123. "This snippet contains a deliberate error and message sent to Sentry and can be used as a test to make sure that everything's working as expected."
  124. ),
  125. configurations: [
  126. {
  127. code: [
  128. {
  129. label: 'ruby',
  130. value: 'ruby',
  131. language: 'ruby',
  132. code: getVerifySnippet(),
  133. },
  134. ],
  135. },
  136. ],
  137. },
  138. ],
  139. nextSteps: () => [],
  140. };
  141. const crashReportOnboarding: OnboardingConfig = {
  142. introduction: () => getCrashReportModalIntroduction(),
  143. install: (params: Params) => [
  144. {
  145. type: StepType.INSTALL,
  146. description: tct(
  147. "In Rails, being able to serve dynamic pages in response to errors is required to pass the needed [codeEvent:event_id] to the JavaScript SDK. [link:Read our docs] to learn more. Once you're able to serve dynamic exception pages, you can support user feedback.",
  148. {
  149. codeEvent: <code />,
  150. link: (
  151. <ExternalLink href="https://docs.sentry.io/platforms/ruby/guides/rails/user-feedback/#integration" />
  152. ),
  153. }
  154. ),
  155. configurations: [
  156. getCrashReportSDKInstallFirstStepRails(params),
  157. {
  158. description: t(
  159. 'Additionally, you need the template that brings up the dialog:'
  160. ),
  161. code: [
  162. {
  163. label: 'ERB',
  164. value: 'erb',
  165. language: 'erb',
  166. code: `<% sentry_id = request.env["sentry.error_event_id"] %>
  167. <% if sentry_id.present? %>
  168. <script>
  169. Sentry.init({ dsn: "${params.dsn.public}" });
  170. Sentry.showReportDialog({ eventId: "<%= sentry_id %>" });
  171. </script>
  172. <% end %>`,
  173. },
  174. ],
  175. },
  176. ],
  177. },
  178. ],
  179. configure: () => [
  180. {
  181. type: StepType.CONFIGURE,
  182. description: getCrashReportModalConfigDescription({
  183. link: 'https://docs.sentry.io/platforms/ruby/guides/rails/user-feedback/configuration/#crash-report-modal',
  184. }),
  185. },
  186. ],
  187. verify: () => [],
  188. nextSteps: () => [],
  189. };
  190. const docs: Docs = {
  191. onboarding,
  192. customMetricsOnboarding: getRubyMetricsOnboarding(),
  193. replayOnboardingJsLoader,
  194. crashReportOnboarding,
  195. feedbackOnboardingJsLoader,
  196. };
  197. export default docs;