ruby.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 [stackprofCode:stackprof] is loaded before [sentryRubyCode:sentry-ruby].',
  60. {
  61. stackprofLink: (
  62. <ExternalLink href="https://github.com/tmm1/stackprof" />
  63. ),
  64. stackprofCode: <code />,
  65. sentryRubyCode: <code />,
  66. }
  67. )
  68. : undefined,
  69. language: 'ruby',
  70. code: getInstallSnippet(params),
  71. },
  72. {
  73. description: t('After adding the gems, run the following to install the SDK:'),
  74. language: 'ruby',
  75. code: 'bundle install',
  76. },
  77. ],
  78. },
  79. ],
  80. configure: params => [
  81. {
  82. type: StepType.CONFIGURE,
  83. description: tct(
  84. 'To use Sentry Ruby all you need is your DSN. Like most Sentry libraries it will honor the [sentryDSN: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 [sentryInit:Sentry.init]:',
  85. {sentryDSN: <code />, sentryInit: <code />}
  86. ),
  87. configurations: [
  88. {
  89. language: 'ruby',
  90. code: getConfigureSnippet(params),
  91. },
  92. ],
  93. },
  94. ],
  95. verify: () => [
  96. {
  97. type: StepType.VERIFY,
  98. description: t(
  99. "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."
  100. ),
  101. configurations: [
  102. {
  103. language: 'ruby',
  104. code: getVerifySnippet(),
  105. },
  106. ],
  107. },
  108. ],
  109. };
  110. const docs: Docs = {
  111. onboarding,
  112. customMetricsOnboarding: getRubyMetricsOnboarding(),
  113. crashReportOnboarding: CrashReportWebApiOnboarding,
  114. };
  115. export default docs;