rust.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {t, tct} from 'sentry/locale';
  5. // Configuration Start
  6. export const steps = ({
  7. dsn,
  8. sourcePackageRegistries,
  9. }: Partial<
  10. Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
  11. > = {}): LayoutProps['steps'] => [
  12. {
  13. type: StepType.INSTALL,
  14. description: (
  15. <p>
  16. {tct(
  17. 'To add Sentry to your Rust project you just need to add a new dependency to your [code:Cargo.toml]:',
  18. {code: <code />}
  19. )}
  20. </p>
  21. ),
  22. configurations: [
  23. {
  24. language: 'toml',
  25. partialLoading: sourcePackageRegistries?.isLoading,
  26. code: `
  27. [dependencies]
  28. sentry = "${
  29. sourcePackageRegistries?.isLoading
  30. ? t('\u2026loading')
  31. : sourcePackageRegistries?.data?.['sentry.rust']?.version ?? '0.31.5'
  32. }"
  33. `,
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: (
  40. <p>
  41. {tct(
  42. '[code:Sentry.init()] will return you a guard that when freed, will prevent process exit until all events have been sent (within a timeout):',
  43. {code: <code />}
  44. )}
  45. </p>
  46. ),
  47. configurations: [
  48. {
  49. language: 'rust',
  50. code: `
  51. let _guard = sentry::init(("${dsn}", sentry::ClientOptions {
  52. release: sentry::release_name!(),
  53. ..Default::default()
  54. }));
  55. `,
  56. },
  57. ],
  58. },
  59. {
  60. type: StepType.VERIFY,
  61. description: t(
  62. 'The quickest way to verify Sentry in your Rust application is to cause a panic:'
  63. ),
  64. configurations: [
  65. {
  66. language: 'rust',
  67. code: `
  68. fn main() {
  69. let _guard = sentry::init(("${dsn}", sentry::ClientOptions {
  70. release: sentry::release_name!(),
  71. ..Default::default()
  72. }));
  73. // Sentry will capture this
  74. panic!("Everything is on fire!");
  75. }
  76. `,
  77. },
  78. ],
  79. },
  80. ];
  81. // Configuration End
  82. export function GettingStartedWithRust({
  83. dsn,
  84. sourcePackageRegistries,
  85. ...props
  86. }: ModuleProps) {
  87. return <Layout steps={steps({dsn, sourcePackageRegistries})} {...props} />;
  88. }
  89. export default GettingStartedWithRust;