rust.tsx 4.4 KB

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