Browse Source

ref(getting-started-docs): Migrate rust doc to sentry main repo (#52857)

Priscila Oliveira 1 year ago
parent
commit
dcdb42cc5d

+ 1 - 0
static/app/components/onboarding/gettingStartedDoc/sdkDocumentation.tsx

@@ -22,6 +22,7 @@ export const migratedDocs = [
   'react-native',
   'java-spring-boot',
   'php-laravel',
+  'rust',
 ];
 
 type SdkDocumentationProps = {

+ 20 - 0
static/app/gettingStartedDocs/rust/rust.spec.tsx

@@ -0,0 +1,20 @@
+import {render, screen} from 'sentry-test/reactTestingLibrary';
+
+import {StepTitle} from 'sentry/components/onboarding/gettingStartedDoc/step';
+
+import {GettingStartedWithRust, steps} from './rust';
+
+describe('GettingStartedWithRust', function () {
+  it('all products are selected', function () {
+    const {container} = render(<GettingStartedWithRust dsn="test-dsn" />);
+
+    // Steps
+    for (const step of steps()) {
+      expect(
+        screen.getByRole('heading', {name: step.title ?? StepTitle[step.type]})
+      ).toBeInTheDocument();
+    }
+
+    expect(container).toSnapshot();
+  });
+});

+ 83 - 0
static/app/gettingStartedDocs/rust/rust.tsx

@@ -0,0 +1,83 @@
+import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
+import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
+import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
+import {t, tct} from 'sentry/locale';
+
+// Configuration Start
+export const steps = ({
+  dsn,
+}: {
+  dsn?: string;
+} = {}): LayoutProps['steps'] => [
+  {
+    type: StepType.INSTALL,
+    description: (
+      <p>
+        {tct(
+          'To add Sentry to your Rust project you just need to add a new dependency to your [code:Cargo.toml]:',
+          {code: <code />}
+        )}
+      </p>
+    ),
+    configurations: [
+      {
+        language: 'toml',
+        code: `
+[dependencies]
+sentry = "0.31.5"
+        `,
+      },
+    ],
+  },
+  {
+    type: StepType.CONFIGURE,
+    description: (
+      <p>
+        {tct(
+          '[code:Sentry.init()] will return you a guard that when freed, will prevent process exit until all events have been sent (within a timeout):',
+          {code: <code />}
+        )}
+      </p>
+    ),
+    configurations: [
+      {
+        language: 'rust',
+        code: `
+let _guard = sentry::init(("${dsn}", sentry::ClientOptions {
+  release: sentry::release_name!(),
+  ..Default::default()
+}));
+        `,
+      },
+    ],
+  },
+  {
+    type: StepType.VERIFY,
+    description: t(
+      'The quickest way to verify Sentry in your Rust application is to cause a panic:'
+    ),
+    configurations: [
+      {
+        language: 'rust',
+        code: `
+fn main() {
+  let _guard = sentry::init(("${dsn}", sentry::ClientOptions {
+    release: sentry::release_name!(),
+    ..Default::default()
+  }));
+
+  // Sentry will capture this
+  panic!("Everything is on fire!");
+}
+        `,
+      },
+    ],
+  },
+];
+// Configuration End
+
+export function GettingStartedWithRust({dsn, ...props}: ModuleProps) {
+  return <Layout steps={steps({dsn})} {...props} />;
+}
+
+export default GettingStartedWithRust;