rust.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 {
  9. getCrashReportBackendInstallStep,
  10. getCrashReportModalConfigDescription,
  11. getCrashReportModalIntroduction,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import {t, tct} from 'sentry/locale';
  14. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  15. type Params = DocsParams;
  16. const getInstallSnippet = (params: Params) => `
  17. [dependencies]
  18. sentry = "${getPackageVersion(params, 'sentry.rust', '0.32.1')}"`;
  19. const getInstallSnippetMetrics = (params: Params) => `
  20. sentry = { version = "${getPackageVersion(
  21. params,
  22. 'sentry.rust',
  23. '0.32.1'
  24. )}", features = ["UNSTABLE_metrics"] }`;
  25. const getConfigureSnippet = (params: Params) => `
  26. let _guard = sentry::init(("${params.dsn.public}", sentry::ClientOptions {
  27. release: sentry::release_name!(),
  28. ..Default::default()
  29. }));`;
  30. const getVerifySnippet = (params: Params) => `
  31. fn main() {
  32. let _guard = sentry::init(("${params.dsn.public}", sentry::ClientOptions {
  33. release: sentry::release_name!(),
  34. ..Default::default()
  35. }));
  36. // Sentry will capture this
  37. panic!("Everything is on fire!");
  38. }`;
  39. const getVerifySnippetMetrics = () => `
  40. use sentry::metrics::Metric;
  41. // Add 1 to a counter named 'hits'
  42. Metric::count("hits").send();`;
  43. const onboarding: OnboardingConfig = {
  44. install: params => [
  45. {
  46. type: StepType.INSTALL,
  47. description: tct(
  48. 'To add Sentry to your Rust project you just need to add a new dependency to your [code:Cargo.toml]:',
  49. {code: <code />}
  50. ),
  51. configurations: [
  52. {
  53. language: 'toml',
  54. partialLoading: params.sourcePackageRegistries.isLoading,
  55. code: getInstallSnippet(params),
  56. },
  57. ],
  58. },
  59. ],
  60. configure: params => [
  61. {
  62. type: StepType.CONFIGURE,
  63. description: tct(
  64. '[code:Sentry.init()] will return you a guard that when freed, will prevent process exit until all events have been sent (within a timeout):',
  65. {code: <code />}
  66. ),
  67. configurations: [
  68. {
  69. language: 'rust',
  70. code: getConfigureSnippet(params),
  71. },
  72. ],
  73. },
  74. ],
  75. verify: params => [
  76. {
  77. type: StepType.VERIFY,
  78. description: t(
  79. 'The quickest way to verify Sentry in your Rust application is to cause a panic:'
  80. ),
  81. configurations: [
  82. {
  83. language: 'rust',
  84. code: getVerifySnippet(params),
  85. },
  86. ],
  87. },
  88. ],
  89. };
  90. const customMetricsOnboarding: OnboardingConfig = {
  91. install: params => [
  92. {
  93. type: StepType.INSTALL,
  94. description: tct(
  95. 'You need at least version 0.32.1 of the [code:sentry] or [code:sentry-core] crates installed. Enable the [code:UNSTABLE_metrics] feature:',
  96. {
  97. code: <code />,
  98. }
  99. ),
  100. configurations: [
  101. {
  102. language: 'toml',
  103. partialLoading: params.sourcePackageRegistries.isLoading,
  104. code: getInstallSnippetMetrics(params),
  105. },
  106. ],
  107. },
  108. ],
  109. configure: () => [],
  110. verify: () => [
  111. {
  112. type: StepType.VERIFY,
  113. description: tct(
  114. "Then you'll be able to add metrics as [code:counters], [code:sets], [code:distributions], and [code:gauges]. These are available under the [code:Sentry.metrics] namespace. Try out this example:",
  115. {
  116. code: <code />,
  117. }
  118. ),
  119. configurations: [
  120. {
  121. code: [
  122. {
  123. label: 'Rust',
  124. value: 'rust',
  125. language: 'rust',
  126. code: getVerifySnippetMetrics(),
  127. },
  128. ],
  129. },
  130. {
  131. description: t(
  132. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  133. ),
  134. },
  135. {
  136. description: tct(
  137. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  138. {
  139. docsLink: (
  140. <ExternalLink href="https://docs.rs/sentry/latest/sentry/metrics/index.html" />
  141. ),
  142. }
  143. ),
  144. },
  145. ],
  146. },
  147. ],
  148. };
  149. const crashReportOnboarding: OnboardingConfig = {
  150. introduction: () => getCrashReportModalIntroduction(),
  151. install: (params: Params) => getCrashReportBackendInstallStep(params),
  152. configure: () => [
  153. {
  154. type: StepType.CONFIGURE,
  155. description: getCrashReportModalConfigDescription({
  156. link: 'https://docs.sentry.io/platforms/rust/user-feedback/configuration/#crash-report-modal',
  157. }),
  158. },
  159. ],
  160. verify: () => [],
  161. nextSteps: () => [],
  162. };
  163. const docs: Docs = {
  164. onboarding,
  165. customMetricsOnboarding,
  166. crashReportOnboarding,
  167. };
  168. export default docs;