rack.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 {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}'${
  18. params.isPerformanceSelected
  19. ? `
  20. # Set traces_sample_rate to 1.0 to capture 100%
  21. # of transactions for performance monitoring.
  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 onboarding: OnboardingConfig = {
  41. install: params => [
  42. {
  43. type: StepType.INSTALL,
  44. description: tct(
  45. 'Install the SDK via Rubygems by adding it to your [code:Gemfile]:',
  46. {
  47. code: <code />,
  48. }
  49. ),
  50. configurations: [
  51. {
  52. description: params.isProfilingSelected
  53. ? tct(
  54. '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].',
  55. {
  56. stackprofLink: (
  57. <ExternalLink href="https://github.com/tmm1/stackprof" />
  58. ),
  59. stackprofCode: <code />,
  60. sentryRubyCode: <code />,
  61. }
  62. )
  63. : undefined,
  64. language: 'ruby',
  65. code: getInstallSnippet(params),
  66. },
  67. ],
  68. },
  69. ],
  70. configure: params => [
  71. {
  72. type: StepType.CONFIGURE,
  73. description: tct(
  74. 'Add use [sentryRackCode:Sentry::Rack::CaptureExceptions] to your [sentryConfigCode:config.ru] or other rackup file (this is automatically inserted in Rails):',
  75. {
  76. sentryRackCode: <code />,
  77. sentryConfigCode: <code />,
  78. }
  79. ),
  80. configurations: [
  81. {
  82. language: 'ruby',
  83. code: getConfigureSnippet(params),
  84. },
  85. ],
  86. },
  87. ],
  88. verify: () => [],
  89. };
  90. const docs: Docs = {
  91. onboarding,
  92. customMetricsOnboarding: getRubyMetricsOnboarding(),
  93. crashReportOnboarding: CrashReportWebApiOnboarding,
  94. };
  95. export default docs;