Skip to content

Add onboarding for Go Fiber #68665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sentry/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"go",
"go-echo",
"go-fasthttp",
"go-fiber",
"go-gin",
"go-http",
"go-iris",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/utils/platform_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"go",
"go-echo",
"go-fasthttp",
"go-fiber",
"go-gin",
"go-http",
"go-iris",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export enum SupportedLanguages {
const topGoFrameworks: PlatformKey[] = [
'go-echo',
'go-fasthttp',
"go-fiber",
'go-gin',
'go-http',
'go-iris',
Expand Down
2 changes: 2 additions & 0 deletions static/app/data/platformCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const backend: PlatformKey[] = [
'go',
'go-echo',
'go-fasthttp',
'go-fiber',
'go-gin',
'go-http',
'go-iris',
Expand Down Expand Up @@ -310,6 +311,7 @@ export const replayBackendPlatforms: readonly PlatformKey[] = [
'elixir',
'go-echo',
'go-fasthttp',
'go-fiber',
'go',
'go-gin',
'go-http',
Expand Down
1 change: 1 addition & 0 deletions static/app/data/platformPickerCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const server: Set<PlatformKey> = new Set([
'go-http',
'go-echo',
'go-fasthttp',
'go-fiber',
'go-gin',
'go-iris',
'go-martini',
Expand Down
7 changes: 7 additions & 0 deletions static/app/data/platforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ export const platforms: PlatformIntegration[] = [
name: 'FastHTTP',
language: 'go',
},
{
link: 'https://docs.sentry.io/platforms/go/guides/fiber/',
type: 'framework',
id: 'go-fiber',
name: 'Fiber',
language: 'go',
},
{
link: 'https://docs.sentry.io/platforms/go/guides/gin/',
type: 'framework',
Expand Down
15 changes: 15 additions & 0 deletions static/app/gettingStartedDocs/go/fiber.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
import {screen} from 'sentry-test/reactTestingLibrary';

import docs from './fiber';

describe('fiber onboarding docs', function () {
it('renders docs correctly', function () {
renderWithOnboardingLayout(docs);

// Renders main headings
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Usage'})).toBeInTheDocument();
});
});
255 changes: 255 additions & 0 deletions static/app/gettingStartedDocs/go/fiber.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';

import {Alert} from 'sentry/components/alert';
import ExternalLink from 'sentry/components/links/externalLink';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import type {
Docs,
DocsParams,
OnboardingConfig,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {
getCrashReportGenericInstallStep,
getCrashReportModalConfigDescription,
getCrashReportModalIntroduction,
} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
import {t, tct} from 'sentry/locale';

type Params = DocsParams;

const getConfigureSnippet = (params: Params) => `
import (
"fmt"
"net/http"

"github.com/getsentry/sentry-go"
sentryfiber "github.com/getsentry/sentry-go/fiber"
)

// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
if err := sentry.Init(sentry.ClientOptions{
Dsn: "${params.dsn}",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
}); err != nil {
fmt.Printf("Sentry initialization failed: %v\n", err)
}

// Later in the code
sentryHandler := sentryfiber.New(sentryfiber.Options{
Repanic: true,
WaitForDelivery: true,
})

enhanceSentryEvent := func(ctx *fiber.Ctx) error {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
}
return ctx.Next()
}

app := fiber.New()

app.Use(sentryHandler)

app.All("/foo", enhanceSentryEvent, func(c *fiber.Ctx) error {
panic("y tho")
})

app.All("/", func(ctx *fiber.Ctx) error {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
return ctx.SendStatus(fiber.StatusOK)
})

if err := app.Listen(":3000"); err != nil {
panic(err)
}`;

const getOptionsSnippet = () => `
// Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true,
// as fiber includes its own Recover middleware that handles http responses.
Repanic bool
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
// Because Fiber's "Recover" handler doesn't restart the application,
// it's safe to either skip this option or set it to "false".
WaitForDelivery bool
// Timeout for the event delivery requests.
Timeout time.Duration`;

const getUsageSnippet = () => `
sentryHandler := sentryfiber.New(sentryfiber.Options{
Repanic: true,
WaitForDelivery: true,
})

enhanceSentryEvent := func(ctx *fiber.Ctx) error {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
}
return ctx.Next()
}

app := fiber.New()

app.Use(sentryHandler)

app.All("/foo", enhanceSentryEvent, func(c *fiber.Ctx) error {
panic("y tho")
})

app.All("/", func(ctx *fiber.Ctx) error {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
return ctx.SendStatus(fiber.StatusOK)
})

if err := app.Listen(":3000"); err != nil {
panic(err)
};`

const getBeforeSendSnippet = params => `
sentry.Init(sentry.ClientOptions{
Dsn: "${params.dsn}",
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
if hint.Context != nil {
if req, ok := hint.Context.Value(sentry.RequestContextKey).(*http.Request); ok {
// You have access to the original Request here
}
}

return event
},
})`;

const onboarding: OnboardingConfig = {
install: () => [
{
type: StepType.INSTALL,
description: tct('Install our Go Fiber SDK using [code:go get]:', {
code: <code />,
}),
configurations: [
{
language: 'bash',
code: 'go get github.com/getsentry/sentry-go/fiber',
},
],
},
],
configure: params => [
{
type: StepType.CONFIGURE,
description: t(
"Import and initialize the Sentry SDK early in your application's setup:"
),
configurations: [
{
language: 'go',
code: getConfigureSnippet(params),
},
{
description: (
<Fragment>
<strong>{t('Options')}</strong>
<p>
{tct(
'[sentryFiberCode:sentryfiber] accepts a struct of [optionsCode:Options] that allows you to configure how the handler will behave.',
{sentryFiberCode: <code />, optionsCode: <code />}
)}
</p>
{t('Currently it respects 3 options:')}
</Fragment>
),
language: 'go',
code: getOptionsSnippet(),
},
],
},
{
title: t('Usage'),
description: (
<Fragment>
<p>
{tct(
"[sentryFiberCode:sentryfiber] attaches an instance of [sentryHubLink:*sentry.Hub] to the [fiberContextCode:*fiber.Ctx], which makes it available throughout the rest of the request's lifetime. You can access it by using the [getHubFromContextCode:sentryfiber.GetHubFromContext()] method on the context itself in any of your proceeding middleware and routes. And it should be used instead of the global [captureMessageCode:sentry.CaptureMessage], [captureExceptionCode:sentry.CaptureException] or any other calls, as it keeps the separation of data between the requests.",
{
sentryFiberCode: <code />,
sentryHubLink: (
<ExternalLink href="https://godoc.org/github.com/getsentry/sentry-go#Hub" />
),
fiberContextCode: <code />,
getHubFromContextCode: <code />,
captureMessageCode: <code />,
captureExceptionCode: <code />,
}
)}
</p>
<AlertWithoutMarginBottom>
{tct(
"Keep in mind that [sentryHubCode:*sentry.Hub] won't be available in middleware attached before [sentryFiberCode:sentryfiber]!",
{sentryFiberCode: <code />, sentryHubCode: <code />}
)}
</AlertWithoutMarginBottom>
</Fragment>
),
configurations: [
{
language: 'go',
code: getUsageSnippet(),
},
{
description: (
<strong>
{tct('Accessing Request in [beforeSendCode:BeforeSend] callback', {
beforeSendCode: <code />,
})}
</strong>
),
language: 'go',
code: getBeforeSendSnippet(params),
},
],
},
],
verify: () => [],
};

const crashReportOnboarding: OnboardingConfig = {
introduction: () => getCrashReportModalIntroduction(),
install: (params: Params) => getCrashReportGenericInstallStep(params),
configure: () => [
{
type: StepType.CONFIGURE,
description: getCrashReportModalConfigDescription({
link: 'https://docs.sentry.io/platforms/go/guides/fiber/user-feedback/configuration/#crash-report-modal',
}),
},
],
verify: () => [],
nextSteps: () => [],
};

const docs: Docs = {
onboarding,
replayOnboardingJsLoader,
crashReportOnboarding,
};

export default docs;

const AlertWithoutMarginBottom = styled(Alert)`
margin-bottom: 0;
`;
1 change: 1 addition & 0 deletions static/app/types/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export type PlatformKey =
| 'go'
| 'go-echo'
| 'go-fasthttp'
| 'go-fiber'
| 'go-gin'
| 'go-http'
| 'go-iris'
Expand Down
Loading