rails.tsx 4.3 KB

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