ruby.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getInstallSnippet = (params: Params) =>
  12. `${params.isProfilingSelected ? 'gem "stackprof"\n' : ''}gem "sentry-ruby"`;
  13. const getConfigureSnippet = (params: Params) => `
  14. Sentry.init do |config|
  15. config.dsn = '${params.dsn.public}'
  16. # Add data like request headers and IP for users,
  17. # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info
  18. config.send_default_pii = true${
  19. params.isPerformanceSelected
  20. ? `
  21. # Set traces_sample_rate to 1.0 to capture 100%
  22. # of transactions for tracing.
  23. # We recommend adjusting this value in production.
  24. config.traces_sample_rate = 1.0
  25. # or
  26. config.traces_sampler = lambda do |context|
  27. true
  28. end`
  29. : ''
  30. }${
  31. params.isProfilingSelected
  32. ? `
  33. # Set profiles_sample_rate to profile 100%
  34. # of sampled transactions.
  35. # We recommend adjusting this value in production.
  36. config.profiles_sample_rate = 1.0`
  37. : ''
  38. }
  39. end`;
  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: 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. '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]:',
  86. {code: <code />}
  87. ),
  88. configurations: [
  89. {
  90. language: 'ruby',
  91. code: getConfigureSnippet(params),
  92. },
  93. ],
  94. },
  95. ],
  96. verify: () => [
  97. {
  98. type: StepType.VERIFY,
  99. description: t(
  100. "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."
  101. ),
  102. configurations: [
  103. {
  104. language: 'ruby',
  105. code: getVerifySnippet(),
  106. },
  107. ],
  108. },
  109. ],
  110. };
  111. const docs: Docs = {
  112. onboarding,
  113. crashReportOnboarding: CrashReportWebApiOnboarding,
  114. };
  115. export default docs;