rack.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 {CrashReportWebApiOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getInstallSnippet = (params: Params) =>
  12. `${params.isProfilingSelected ? 'gem "stackprof"\n' : ''}gem "sentry-ruby"`;
  13. const getConfigureSnippet = (params: Params) => `
  14. require 'sentry-ruby'
  15. Sentry.init do |config|
  16. config.dsn = '${params.dsn.public}'
  17. # Add data like request headers and IP for users,
  18. # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info
  19. config.send_default_pii = true${
  20. params.isPerformanceSelected
  21. ? `
  22. # Set traces_sample_rate to 1.0 to capture 100%
  23. # of transactions for tracing.
  24. # We recommend adjusting this value in production.
  25. config.traces_sample_rate = 1.0
  26. # or
  27. config.traces_sampler = lambda do |context|
  28. true
  29. end`
  30. : ''
  31. }${
  32. params.isProfilingSelected
  33. ? `
  34. # Set profiles_sample_rate to profile 100%
  35. # of sampled transactions.
  36. # We recommend adjusting this value in production.
  37. config.profiles_sample_rate = 1.0`
  38. : ''
  39. }
  40. end
  41. use Sentry::Rack::CaptureExceptions`;
  42. const getVerifySnippet = () => `
  43. begin
  44. 1 / 0
  45. rescue ZeroDivisionError => exception
  46. Sentry.capture_exception(exception)
  47. end
  48. Sentry.capture_message("test message")`;
  49. const onboarding: OnboardingConfig = {
  50. install: params => [
  51. {
  52. type: StepType.INSTALL,
  53. description: tct(
  54. 'The Sentry SDK for Ruby comes as a gem that should be added to your [gemfileCode:Gemfile]:',
  55. {
  56. gemfileCode: <code />,
  57. }
  58. ),
  59. configurations: [
  60. {
  61. description: params.isProfilingSelected
  62. ? tct(
  63. '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].',
  64. {
  65. stackprofLink: (
  66. <ExternalLink href="https://github.com/tmm1/stackprof" />
  67. ),
  68. code: <code />,
  69. }
  70. )
  71. : undefined,
  72. language: 'ruby',
  73. code: getInstallSnippet(params),
  74. },
  75. {
  76. description: t('After adding the gems, run the following to install the SDK:'),
  77. language: 'ruby',
  78. code: 'bundle install',
  79. },
  80. ],
  81. },
  82. ],
  83. configure: params => [
  84. {
  85. type: StepType.CONFIGURE,
  86. description: tct(
  87. 'Add [code:use Sentry::Rack::CaptureExceptions] to your [code:config.ru] or other rackup file (this is automatically inserted in Rails):',
  88. {
  89. code: <code />,
  90. }
  91. ),
  92. configurations: [
  93. {
  94. language: 'ruby',
  95. code: getConfigureSnippet(params),
  96. },
  97. ],
  98. },
  99. ],
  100. verify: () => [
  101. {
  102. type: StepType.VERIFY,
  103. description: t(
  104. "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."
  105. ),
  106. configurations: [
  107. {
  108. code: [
  109. {
  110. label: 'ruby',
  111. value: 'ruby',
  112. language: 'ruby',
  113. code: getVerifySnippet(),
  114. },
  115. ],
  116. },
  117. ],
  118. },
  119. ],
  120. nextSteps: () => [],
  121. };
  122. const docs: Docs = {
  123. onboarding,
  124. crashReportOnboarding: CrashReportWebApiOnboarding,
  125. };
  126. export default docs;