rails.tsx 5.9 KB

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