ruby.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. Sentry.init do |config|
  16. config.dsn = '${params.dsn.public}'${
  17. params.isPerformanceSelected
  18. ? `
  19. # Set traces_sample_rate to 1.0 to capture 100%
  20. # of transactions for tracing.
  21. # We recommend adjusting this value in production.
  22. config.traces_sample_rate = 1.0
  23. # or
  24. config.traces_sampler = lambda do |context|
  25. true
  26. end`
  27. : ''
  28. }${
  29. params.isProfilingSelected
  30. ? `
  31. # Set profiles_sample_rate to profile 100%
  32. # of sampled transactions.
  33. # We recommend adjusting this value in production.
  34. config.profiles_sample_rate = 1.0`
  35. : ''
  36. }
  37. end`;
  38. const getVerifySnippet = () => `
  39. begin
  40. 1 / 0
  41. rescue ZeroDivisionError => exception
  42. Sentry.capture_exception(exception)
  43. end
  44. Sentry.capture_message("test message")`;
  45. const onboarding: OnboardingConfig = {
  46. install: (params: Params) => [
  47. {
  48. type: StepType.INSTALL,
  49. description: tct(
  50. 'The Sentry SDK for Ruby comes as a gem that should be added to your [gemfileCode:Gemfile]:',
  51. {
  52. gemfileCode: <code />,
  53. }
  54. ),
  55. configurations: [
  56. {
  57. description: params.isProfilingSelected
  58. ? tct(
  59. '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].',
  60. {
  61. stackprofLink: (
  62. <ExternalLink href="https://github.com/tmm1/stackprof" />
  63. ),
  64. code: <code />,
  65. }
  66. )
  67. : undefined,
  68. language: 'ruby',
  69. code: getInstallSnippet(params),
  70. },
  71. {
  72. description: t('After adding the gems, run the following to install the SDK:'),
  73. language: 'ruby',
  74. code: 'bundle install',
  75. },
  76. ],
  77. },
  78. ],
  79. configure: params => [
  80. {
  81. type: StepType.CONFIGURE,
  82. description: tct(
  83. 'To use Sentry Ruby all you need is your DSN. Like most Sentry libraries it will honor the [code:SENTRY_DSN] environment variable. You can find it on the project settings page under API Keys. You can either export it as environment variable or manually configure it with [code:Sentry.init]:',
  84. {code: <code />}
  85. ),
  86. configurations: [
  87. {
  88. language: 'ruby',
  89. code: getConfigureSnippet(params),
  90. },
  91. ],
  92. },
  93. ],
  94. verify: () => [
  95. {
  96. type: StepType.VERIFY,
  97. description: t(
  98. "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."
  99. ),
  100. configurations: [
  101. {
  102. language: 'ruby',
  103. code: getVerifySnippet(),
  104. },
  105. ],
  106. },
  107. ],
  108. };
  109. const docs: Docs = {
  110. onboarding,
  111. customMetricsOnboarding: getRubyMetricsOnboarding(),
  112. crashReportOnboarding: CrashReportWebApiOnboarding,
  113. };
  114. export default docs;