Skip to content

feat(go): refactor initial guide pages #14276

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 2 additions & 9 deletions docs/platforms/go/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type ClientOptions struct {
// 0.0 is treated as if it was 1.0. To drop all events, set the DSN to the
// empty string.
SampleRate float64
// Enable structured logging.
EnableLogs bool
// Enable performance tracing.
EnableTracing bool
// The sample rate for sampling traces in the range [0.0, 1.0].
Expand Down Expand Up @@ -129,15 +131,6 @@ By default, TLS uses the host's root CA set. If you don't have `ca-certificates`


```go
package main

import (
"log"

"github.com/certifi/gocertifi"
"github.com/getsentry/sentry-go"
)

sentryClientOptions := sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
}
Expand Down
22 changes: 6 additions & 16 deletions docs/platforms/go/common/configuration/transports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,13 @@ To configure transport, provide an instance of `sentry.Transport` interface to `


```go
package main
sentrySyncTransport := sentry.NewHTTPSyncTransport()
sentrySyncTransport.Timeout = time.Second * 3

import (
"time"

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

func main() {
sentrySyncTransport := sentry.NewHTTPSyncTransport()
sentrySyncTransport.Timeout = time.Second * 3

sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
Transport: sentrySyncTransport,
})
}
sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
Transport: sentrySyncTransport,
})
```

Each transport, provide it's own factory function. `NewHTTPTransport` and `NewHTTPSyncTransport` respectively.
Expand Down
14 changes: 0 additions & 14 deletions docs/platforms/go/common/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ Check out the other SDKs we support in the left-hand dropdown.

* If you don't have an account and Sentry project established already, please head over to [Sentry](https://sentry.io/signup/), and then return to this page.

## Features

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

<OnboardingOptionButtons
options={[
'error-monitoring',
'performance',
'logs',
]}
/>

## Install

<PlatformContent includePath="getting-started-install" />
Expand Down
2 changes: 1 addition & 1 deletion docs/platforms/go/common/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To disable default integrations, you can provide an empty list of integrations w

```go
sentry.Init(sentry.ClientOptions{
Dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
Dsn: "___PUBLIC_DSN___",
Integrations: func(i []sentry.Integration) []sentry.Integration {
return []sentry.Integration{}
},
Expand Down
99 changes: 40 additions & 59 deletions docs/platforms/go/guides/echo/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,25 @@ For a quick reference, there is a [complete example](https://github.com/getsentr

[Go Dev-style API documentation](https://pkg.go.dev/github.com/getsentry/sentry-go/echo) is also available.

## Features

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

## Install

<OnboardingOptionButtons
options={[
'error-monitoring',
'performance'
]}
/>

```bash
go get github.com/getsentry/sentry-go
go get github.com/getsentry/sentry-go/echo
```

<Break />

## Configure

```go
import (
"fmt"
"net/http"

"github.com/getsentry/sentry-go"
sentryecho "github.com/getsentry/sentry-go/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)

// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
if err := sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// Adds request headers and IP for users,
// visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
SendDefaultPII: true,
}); err != nil {
fmt.Printf("Sentry initialization failed: %v\n", err)
}

// Then create your app
app := echo.New()

app.Use(middleware.Logger())
app.Use(middleware.Recover())

// Once it's done, you can attach the handler as one of your middleware
app.Use(sentryecho.New(sentryecho.Options{}))

// Set up routes
app.GET("/", func(ctx echo.Context) error {
return ctx.String(http.StatusOK, "Hello, World!")
})
### Initialize the Sentry SDK

// And run it
app.Logger.Fatal(app.Start(":3000"))
```
<PlatformContent includePath="getting-started-config" />

## Configure
### Options

`sentryecho` accepts a struct of `Options` that allows you to configure how the handler will behave.

Currently it respects 3 options:

```go
// Repanic configures whether Sentry should repanic after recovery, in most cases it should be set to true,
// as echo includes its own Recover middleware that handles http responses.
Expand All @@ -92,6 +38,41 @@ WaitForDelivery bool
Timeout time.Duration
```

<Break />

```go
app := echo.New()
app.Use(sentryecho.New(sentryecho.Options{
// you can modify these options
Repanic: true,
WaitForDelivery: false,
Timeout: 5 * time.Second,
}))
```

## Verify

```go
app := echo.New()
app.Use(middleware.Logger())
app.Use(middleware.Recover())

// Attach the sentryecho handler as one of your middlewares
app.Use(sentryecho.New(sentryecho.Options{
// specify options here...
}))

// Set up routes
app.GET("/", func(ctx echo.Context) error {
// capturing an error intentionally to simulate usage
sentry.CaptureMessage("It works!")

return ctx.String(http.StatusOK, "Hello, World!")
})

app.Logger.Fatal(app.Start(":3000"))
```

## Usage

`sentryecho` attaches an instance of `*sentry.Hub` (https://pkg.go.dev/github.com/getsentry/sentry-go#Hub) to the `echo.Context`, which makes it available throughout the rest of the request's lifetime.
Expand Down
96 changes: 40 additions & 56 deletions docs/platforms/go/guides/fasthttp/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,62 @@ For a quick reference, there is a [complete example](https://github.com/getsentr

[Go Dev-style API documentation](https://pkg.go.dev/github.com/getsentry/sentry-go/fasthttp) is also available.

## Features

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

## Install

<OnboardingOptionButtons
options={[
'error-monitoring',
'performance'
]}
/>

```shell
```bash
go get github.com/getsentry/sentry-go
go get github.com/getsentry/sentry-go/fasthttp
```

<Break />

## Configure

### Initialize the Sentry SDK

<PlatformContent includePath="getting-started-config" />

### Options

`sentryfasthttp` accepts a struct of `Options` that allows you to configure how the handler will behave.

```go
import (
"fmt"
"net/http"
// Repanic configures whether Sentry should repanic after recovery, in most cases, it defaults to false,
// as fasthttp doesn't include its own Recovery handler.
Repanic bool
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
// Because fasthttp doesn't include its own `Recovery` handler, it will restart the application,
// and the event won't be delivered otherwise.
WaitForDelivery bool
// Timeout for the event delivery requests.
Timeout time.Duration
```

"github.com/getsentry/sentry-go"
sentryfasthttp "github.com/getsentry/sentry-go/fasthttp"
)
<Break />

// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
if err := sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance
EnableTracing: true,
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// Adds request headers and IP for users,
// visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
SendDefaultPII: true,
}); err != nil {
fmt.Printf("Sentry initialization failed: %v\n", err)
}
```go
// Create an instance of sentryfasthttp
sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{
Repanic: false,
WaitForDelivery: true,
Timeout: 5 * time.Second,
})
```

## Verify

```go
// Create an instance of sentryfasthttp
sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{})
sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{
// specify options here...
})

// After creating the instance, you can attach the handler as one of your middleware
fastHTTPHandler := sentryHandler.Handle(func(ctx *fasthttp.RequestCtx) {
panic("y tho")
// capturing an error intentionally to simulate usage
sentry.CaptureMessage("It works!")

ctx.SetStatusCode(fasthttp.StatusOK)
})

fmt.Println("Listening and serving HTTP on :3000")
Expand All @@ -71,24 +73,6 @@ if err := fasthttp.ListenAndServe(":3000", fastHTTPHandler); err != nil {
}
```

## Configure

`sentryfasthttp` accepts a struct of `Options` that allows you to configure how the handler will behave.

Currently, it respects three options:

```go
// Repanic configures whether Sentry should repanic after recovery, in most cases, it defaults to false,
// as fasthttp doesn't include its own Recovery handler.
Repanic bool
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
// Because fasthttp doesn't include its own `Recovery` handler, it will restart the application,
// and the event won't be delivered otherwise.
WaitForDelivery bool
// Timeout for the event delivery requests.
Timeout time.Duration
```

## Usage

`sentryfasthttp` attaches an instance of `*sentry.Hub` (https://pkg.go.dev/github.com/getsentry/sentry-go#Hub) to the request's context, which makes it available throughout the rest of the request's lifetime.
Expand Down
Loading