# Capturing Errors | Sentry for Zap

Sentry's SDK hooks into your runtime environment, letting recover from panics and also manually capture and report errors and other events.

Key terms:

* An *event* is one instance of sending data to Sentry. Generally, this data is an error or panic.
* An *issue* is a grouping of similar events.
* The reporting of an event is called *capturing*. When an event is captured, it’s sent to Sentry.

The most common form of capturing is to capture errors. What can be captured as an error varies by platform. In general, if you have something that looks like an exception, it can be captured. For some SDKs, you can also omit the argument to `CaptureException` and Sentry will attempt to capture the current exception. It is also useful for manual reporting of errors or messages to Sentry.

While capturing an event, you can also record the breadcrumbs that lead up to that event. Breadcrumbs are different from events: they will not create an event in Sentry, but will be buffered until the next event is sent. Learn more about breadcrumbs in our [Breadcrumbs documentation](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/breadcrumbs.md).

## [Capturing Errors](https://docs.sentry.io/platforms/go/guides/zap/usage.md#capturing-errors)

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](https://docs.sentry.io/platforms/go/guides/zap/usage.md#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):

* `github.com/pkg/errors`
* `github.com/go-errors/errors`
* `github.com/pingcap/errors`
* `github.com/rotisserie/eris`

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

## [Exception Groups](https://docs.sentry.io/platforms/go/guides/zap/usage.md#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](https://docs.sentry.io/platforms/go/guides/zap/usage.md#basic-example)

```go
f, err := os.Open("filename.ext")
if err != nil {
	sentry.CaptureException(err)
}
```

## [Capturing Messages](https://docs.sentry.io/platforms/go/guides/zap/usage.md#capturing-messages)

Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. Typically, our SDKs don't automatically capture messages, but you can capture them manually.

Messages show up as issues on your issue stream, with the message as the issue name.

```go
sentry.CaptureMessage("Something went wrong")
```

By default, Sentry's Go SDK uses an asynchronous transport. That means that calls to `CaptureException`, `CaptureEvent`, and `CaptureMessage` return without waiting for network operations. Instead, events are buffered and sent over the network in a background goroutine. Call `sentry.Flush` to wait for event delivery before the program terminates. You can change the default behavior by using a different transport, for example `HTTPSyncTransport`. More details in the [`Transports` section](https://docs.sentry.io/platforms/go/configuration/transports.md).

## [Capturing Logs](https://docs.sentry.io/platforms/go/guides/zap/usage.md#capturing-logs)

Another common operation is to capture logs. Check [Logs ](https://docs.sentry.io/platforms/go/guides/zap/logs.md)for how to setup your logging integration to send log entries to Sentry.

## Pages in this section

- [Handling Panics](https://docs.sentry.io/platforms/go/guides/zap/usage/panics.md)
- [Concurrency](https://docs.sentry.io/platforms/go/guides/zap/usage/concurrency.md)
- [Set the Level](https://docs.sentry.io/platforms/go/guides/zap/usage/set-level.md)
- [Serverless](https://docs.sentry.io/platforms/go/guides/zap/usage/serverless.md)
- [SDK Fingerprinting](https://docs.sentry.io/platforms/go/guides/zap/usage/sdk-fingerprinting.md)
