ruby.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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}'${
  17. params.isPerformanceSelected
  18. ? `
  19. # Set traces_sample_rate to 1.0 to capture 100%
  20. # of transactions for performance monitoring.
  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. 'Sentry Ruby comes as a gem and is straightforward to install. If you are using Bundler just add this to your [code:Gemfile]:',
  51. {
  52. code: <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. },
  74. ],
  75. configure: params => [
  76. {
  77. type: StepType.CONFIGURE,
  78. description: tct(
  79. '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]:',
  80. {sentryDSN: <code />, sentryInit: <code />}
  81. ),
  82. configurations: [
  83. {
  84. language: 'ruby',
  85. code: getConfigureSnippet(params),
  86. },
  87. ],
  88. },
  89. ],
  90. verify: () => [
  91. {
  92. type: StepType.VERIFY,
  93. description: t('You can then report errors or messages to Sentry:'),
  94. configurations: [
  95. {
  96. language: 'ruby',
  97. code: getVerifySnippet(),
  98. },
  99. ],
  100. },
  101. ],
  102. };
  103. const docs: Docs = {
  104. onboarding,
  105. customMetricsOnboarding: getRubyMetricsOnboarding(),
  106. crashReportOnboarding: CrashReportWebApiOnboarding,
  107. };
  108. export default docs;