rack.tsx 3.8 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 {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 [stackprofCode:stackprof] is loaded before [sentryRubyCode:sentry-ruby].',
  62. {
  63. stackprofLink: (
  64. <ExternalLink href="https://github.com/tmm1/stackprof" />
  65. ),
  66. stackprofCode: <code />,
  67. sentryRubyCode: <code />,
  68. }
  69. )
  70. : undefined,
  71. language: 'ruby',
  72. code: getInstallSnippet(params),
  73. },
  74. {
  75. description: t('After adding the gems, run the following to install the SDK:'),
  76. language: 'ruby',
  77. code: 'bundle install',
  78. },
  79. ],
  80. },
  81. ],
  82. configure: params => [
  83. {
  84. type: StepType.CONFIGURE,
  85. description: tct(
  86. 'Add [sentryRackCode:use Sentry::Rack::CaptureExceptions] to your [sentryConfigCode:config.ru] or other rackup file (this is automatically inserted in Rails):',
  87. {
  88. sentryRackCode: <code />,
  89. sentryConfigCode: <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. customMetricsOnboarding: getRubyMetricsOnboarding(),
  125. crashReportOnboarding: CrashReportWebApiOnboarding,
  126. };
  127. export default docs;