Skip to content

Commit 528250c

Browse files
authored
feat(go): add exception group changes (#15139)
1 parent 7f1b49d commit 528250c

File tree

1 file changed

+26
-1
lines changed
  • platform-includes/capture-error

1 file changed

+26
-1
lines changed

platform-includes/capture-error/go.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
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.
1+
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.
2+
3+
## Error Unwrapping
4+
5+
The SDK supports multiple error wrapping patterns:
6+
7+
- **Standard library**: `fmt.Errorf` with `%w` and `errors.Join` (Go 1.20+)
8+
- **Single error chains**: Errors implementing `Unwrap() error`
9+
- **Third-party libraries**: Errors implementing `Cause() error`
210

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

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

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

20+
## Exception Groups
21+
22+
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.
23+
24+
```go
25+
err1 := errors.New("first error")
26+
err2 := errors.New("second error")
27+
joinedErr := errors.Join(err1, err2)
28+
29+
// This will be captured as an exception group in Sentry
30+
sentry.CaptureException(joinedErr)
31+
```
32+
33+
For errors wrapped with `fmt.Errorf` or single-error chains, the SDK captures each error in the chain individually, maintaining the causal relationship.
34+
35+
## Basic Example
36+
1237
```go
1338
f, err := os.Open("filename.ext")
1439
if err != nil {

0 commit comments

Comments
 (0)