rust.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 [codeSentry:sentry] or [codeSentryCore:sentry-core] crates installed. Enable the [codeFeature:UNSTABLE_metrics] feature:',
  96. {
  97. codeSentry: <code />,
  98. codeSentryCore: <code />,
  99. codeSentryFeature: <code />,
  100. }
  101. ),
  102. configurations: [
  103. {
  104. language: 'toml',
  105. partialLoading: params.sourcePackageRegistries.isLoading,
  106. code: getInstallSnippetMetrics(params),
  107. },
  108. ],
  109. },
  110. ],
  111. configure: () => [],
  112. verify: () => [
  113. {
  114. type: StepType.VERIFY,
  115. description: tct(
  116. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:Sentry.metrics] namespace. Try out this example:",
  117. {
  118. codeCounters: <code />,
  119. codeSets: <code />,
  120. codeDistribution: <code />,
  121. codeGauge: <code />,
  122. codeNamespace: <code />,
  123. }
  124. ),
  125. configurations: [
  126. {
  127. code: [
  128. {
  129. label: 'Rust',
  130. value: 'rust',
  131. language: 'rust',
  132. code: getVerifySnippetMetrics(),
  133. },
  134. ],
  135. },
  136. {
  137. description: t(
  138. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  139. ),
  140. },
  141. {
  142. description: tct(
  143. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  144. {
  145. docsLink: (
  146. <ExternalLink href="https://docs.rs/sentry/latest/sentry/metrics/index.html" />
  147. ),
  148. }
  149. ),
  150. },
  151. ],
  152. },
  153. ],
  154. };
  155. const crashReportOnboarding: OnboardingConfig = {
  156. introduction: () => getCrashReportModalIntroduction(),
  157. install: (params: Params) => getCrashReportBackendInstallStep(params),
  158. configure: () => [
  159. {
  160. type: StepType.CONFIGURE,
  161. description: getCrashReportModalConfigDescription({
  162. link: 'https://docs.sentry.io/platforms/rust/user-feedback/configuration/#crash-report-modal',
  163. }),
  164. },
  165. ],
  166. verify: () => [],
  167. nextSteps: () => [],
  168. };
  169. const docs: Docs = {
  170. onboarding,
  171. customMetricsOnboarding,
  172. crashReportOnboarding,
  173. };
  174. export default docs;