rack.tsx 3.7 KB

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