Skip to content
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
1 change: 1 addition & 0 deletions docs/platforms/go/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type ClientOptions struct {
CaCerts *x509.CertPool
// MaxErrorDepth is the maximum number of errors reported in a chain of errors.
// This protects the SDK from an arbitrarily long chain of wrapped errors.
// The default value is 100.
//
// An additional consideration is that arguably reporting a long chain of errors
// is of little use when debugging production errors with Sentry. The Sentry UI
Expand Down
27 changes: 26 additions & 1 deletion platform-includes/capture-error/go.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
To capture an event in Go, you can pass any struct implementing an `error` interface to `CaptureException()`. If you use a 3rd party library instead of the native `errors` package and it implements the `Unwrap() error` or `Cause() error` method, we'll follow the chain of errors and extract the stack trace from the root cause.
To capture an event in Go, you can pass any struct implementing an `error` interface to `CaptureException()`. The SDK automatically unwraps and captures all errors in the error chain, providing comprehensive error context to Sentry. The SDK also supports third-party libraries and extracts all stack traces in the chain.

## Error Unwrapping

The SDK supports multiple error wrapping patterns:

- **Standard library**: `fmt.Errorf` with `%w` and `errors.Join` (Go 1.20+)
- **Single error chains**: Errors implementing `Unwrap() error`
- **Third-party libraries**: Errors implementing `Cause() error`

The SDK is fully compatible with (but not limited to):

Expand All @@ -9,6 +17,23 @@ The SDK is fully compatible with (but not limited to):

If there is an errors package that's not working out of the box, let us know!

## Exception Groups

When you use `errors.Join` to combine multiple errors, the SDK captures them as an **exception group**. This allows you to see all related errors together in Sentry, properly structured with their relationships preserved.

```go
err1 := errors.New("first error")
err2 := errors.New("second error")
joinedErr := errors.Join(err1, err2)

// This will be captured as an exception group in Sentry
sentry.CaptureException(joinedErr)
```

For errors wrapped with `fmt.Errorf` or single-error chains, the SDK captures each error in the chain individually, maintaining the causal relationship.

## Basic Example

```go
f, err := os.Open("filename.ext")
if err != nil {
Expand Down
Loading