rails.tsx 5.9 KB

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