Browse Source

ref(getting-started-docs): Migrate go doc to sentry main repo (#52858)

Priscila Oliveira 1 year ago
parent
commit
a4ff3495f2

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

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

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

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

+ 106 - 0
static/app/gettingStartedDocs/go/go.tsx

@@ -0,0 +1,106 @@
+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('Install our Go SDK using [code:go get]:', {
+          code: <code />,
+        })}
+      </p>
+    ),
+    configurations: [
+      {
+        language: 'bash',
+        code: 'go get github.com/getsentry/sentry-go',
+      },
+    ],
+  },
+  {
+    type: StepType.CONFIGURE,
+    description: t(
+      "Import and initialize the Sentry SDK early in your application's setup:"
+    ),
+    configurations: [
+      {
+        language: 'go',
+        code: `
+package main
+
+import (
+  "log"
+
+  "github.com/getsentry/sentry-go"
+)
+
+func main() {
+  err := sentry.Init(sentry.ClientOptions{
+    Dsn: "${dsn}",
+    // Set TracesSampleRate to 1.0 to capture 100%
+    // of transactions for performance monitoring.
+    // We recommend adjusting this value in production,
+    TracesSampleRate: 1.0,
+  })
+  if err != nil {
+    log.Fatalf("sentry.Init: %s", err)
+  }
+}
+        `,
+      },
+    ],
+  },
+  {
+    type: StepType.VERIFY,
+    description: t(
+      'The quickest way to verify Sentry in your Go program is to capture a message:'
+    ),
+    configurations: [
+      {
+        language: 'go',
+        code: `
+package main
+
+import (
+  "log"
+  "time"
+
+  "github.com/getsentry/sentry-go"
+)
+
+func main() {
+  err := sentry.Init(sentry.ClientOptions{
+    Dsn: "___PUBLIC_DSN___",
+    // Set TracesSampleRate to 1.0 to capture 100%
+    // of transactions for performance monitoring.
+    // We recommend adjusting this value in production,
+    TracesSampleRate: 1.0,
+  })
+  if err != nil {
+    log.Fatalf("sentry.Init: %s", err)
+  }
+  // Flush buffered events before the program terminates.
+  defer sentry.Flush(2 * time.Second)
+
+  sentry.CaptureMessage("It works!")
+}
+        `,
+      },
+    ],
+  },
+];
+// Configuration End
+
+export function GettingStartedWithGo({dsn, ...props}: ModuleProps) {
+  return <Layout steps={steps({dsn})} {...props} />;
+}
+
+export default GettingStartedWithGo;