rails.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 getConfigureSnippet = (params: Params) => `
  22. Sentry.init do |config|
  23. config.dsn = '${params.dsn}'
  24. config.breadcrumbs_logger = [:active_support_logger, :http_logger]${
  25. params.isPerformanceSelected
  26. ? `
  27. # Set traces_sample_rate to 1.0 to capture 100%
  28. # of transactions for performance monitoring.
  29. # We recommend adjusting this value in production.
  30. config.traces_sample_rate = 1.0
  31. # or
  32. config.traces_sampler = lambda do |context|
  33. true
  34. end`
  35. : ''
  36. }${
  37. params.isProfilingSelected
  38. ? `
  39. # Set profiles_sample_rate to profile 100%
  40. # of sampled transactions.
  41. # We recommend adjusting this value in production.
  42. config.profiles_sample_rate = 1.0`
  43. : ''
  44. }
  45. end`;
  46. const onboarding: OnboardingConfig = {
  47. introduction: () =>
  48. t(
  49. 'In Rails, all uncaught exceptions will be automatically reported. We support Rails 5 and newer.'
  50. ),
  51. install: (params: Params) => [
  52. {
  53. type: StepType.INSTALL,
  54. description: tct(
  55. 'Add [sentryRubyCode:sentry-ruby] and [sentryRailsCode:sentry-rails] to your [sentryGemfileCode:Gemfile]:',
  56. {
  57. sentryRubyCode: <code />,
  58. sentryRailsCode: <code />,
  59. sentryGemfileCode: <code />,
  60. }
  61. ),
  62. configurations: [
  63. {
  64. description: params.isProfilingSelected
  65. ? tct(
  66. '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].',
  67. {
  68. stackprofLink: (
  69. <ExternalLink href="https://github.com/tmm1/stackprof" />
  70. ),
  71. stackprofCode: <code />,
  72. sentryRubyCode: <code />,
  73. }
  74. )
  75. : undefined,
  76. language: 'ruby',
  77. code: getInstallSnippet(params),
  78. },
  79. ],
  80. },
  81. ],
  82. configure: (params: Params) => [
  83. {
  84. type: StepType.CONFIGURE,
  85. description: tct(
  86. 'Initialize the SDK within your [code:config/initializers/sentry.rb]:',
  87. {
  88. code: <code />,
  89. }
  90. ),
  91. configurations: [
  92. {
  93. language: 'ruby',
  94. code: getConfigureSnippet(params),
  95. },
  96. ],
  97. },
  98. {
  99. title: t('Caveats'),
  100. description: tct(
  101. 'Currently, custom exception applications [code:(config.exceptions_app)] are not supported. If you are using a custom exception app, you must manually integrate Sentry yourself.',
  102. {
  103. code: <code />,
  104. }
  105. ),
  106. },
  107. ],
  108. verify: () => [],
  109. nextSteps: () => [],
  110. };
  111. const crashReportOnboarding: OnboardingConfig = {
  112. introduction: () => getCrashReportModalIntroduction(),
  113. install: (params: Params) => [
  114. {
  115. type: StepType.INSTALL,
  116. description: tct(
  117. "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.",
  118. {
  119. codeEvent: <code />,
  120. link: (
  121. <ExternalLink href="https://docs.sentry.io/platforms/ruby/guides/rails/user-feedback/#integration" />
  122. ),
  123. }
  124. ),
  125. configurations: [
  126. getCrashReportSDKInstallFirstStepRails(params),
  127. {
  128. description: t(
  129. 'Additionally, you need the template that brings up the dialog:'
  130. ),
  131. code: [
  132. {
  133. label: 'ERB',
  134. value: 'erb',
  135. language: 'erb',
  136. code: `<% sentry_id = request.env["sentry.error_event_id"] %>
  137. <% if sentry_id.present? %>
  138. <script>
  139. Sentry.init({ dsn: "${params.dsn}" });
  140. Sentry.showReportDialog({ eventId: "<%= sentry_id %>" });
  141. </script>
  142. <% end %>`,
  143. },
  144. ],
  145. },
  146. ],
  147. },
  148. ],
  149. configure: () => [
  150. {
  151. type: StepType.CONFIGURE,
  152. description: getCrashReportModalConfigDescription({
  153. link: 'https://docs.sentry.io/platforms/ruby/guides/rails/user-feedback/configuration/#crash-report-modal',
  154. }),
  155. },
  156. ],
  157. verify: () => [],
  158. nextSteps: () => [],
  159. };
  160. const docs: Docs = {
  161. onboarding,
  162. customMetricsOnboarding: getRubyMetricsOnboarding(),
  163. replayOnboardingJsLoader,
  164. crashReportOnboarding,
  165. };
  166. export default docs;