rails.tsx 4.1 KB

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