---
title: "Usage"
url: https://docs.sentry.io/platforms/go/legacy-sdk/usage/
---

# Usage | Sentry for Go

##### Deprecation Warning

A [new Go SDK](https://docs.sentry.io/platforms/go.md) has superseded this deprecated version. Sentry preserves this documentation for customers using the old `raven-go` client. Learn more about the project on [GitHub](https://github.com/getsentry/sentry-go) and check out our [migration guide](https://docs.sentry.io/platforms/go/migration.md).

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

In Go, there are both errors and panics, and Raven can handle both. To learn more about the differences, please read [Error handling and Go](https://blog.golang.org/error-handling-and-go).

To handle normal `error` responses, we have two options: `CaptureErrorAndWait` and `CaptureError`. The former is a blocking call, for a case where you’d like to exit the application after reporting, and the latter is non-blocking.

```go
f, err := os.Open("filename.ext")
if err != nil {
	raven.CaptureErrorAndWait(err, nil)
	log.Panic(err)
}
```

## [Capturing Panics](https://docs.sentry.io/platforms/go/legacy-sdk/usage.md#capturing-panics)

Capturing a panic is pretty simple as well. We just need to wrap our code in `CapturePanic`. `CapturePanic` will execute the `func` and if a panic happened, we will record it, and gracefully continue.

```go
raven.CapturePanic(func() {
	// do all of the scary things here
	panic("My first Sentry error!")
}, nil)
```

You can verify your Sentry integration by using the above snippet to send a test event.

Other than regular Errors and Panics, there are also two additional methods that allow sending information to Sentry.

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

`CaptureMessage` and it's sibling `CaptureMessageAndWait` let you send arbitrary messages that the SDK will log in your Sentry project.

```go
raven.CaptureMessageAndWait("Something bad happened and I would like to know about that", map[string]string{"category": "logging"})
```

## [Capturing Events](https://docs.sentry.io/platforms/go/legacy-sdk/usage.md#capturing-events)

`Capture` is a low-level method that can be used to deliver hand-crafted events (named type Packet in The Sentry Go SDK). It has no `CaptureAndWait` counterpart, but returns a channel in case you want to verify delivery status. To form a `Packet`, you can use `Packet` type directly, or `NewPacket` and `NewPacketWithExtra` helper methods which creates an empty event with a message and optional extra data.

```go
packet := &raven.Packet{
    Message: "Hand-crafted event",
    Extra: &raven.Extra{
        "runtime.Version": runtime.Version(),
        "runtime.NumCPU": runtime.NumCPU(),
    },
}
raven.Capture(packet, nil)
```

## [Additional Data](https://docs.sentry.io/platforms/go/legacy-sdk/usage.md#additional-data)

All `Capture*` calls can take additional arguments which can help you make more sense out of your reports. To read more about it, see [Context](https://docs.sentry.io/platforms/go/legacy-sdk/context.md) section.

## [Event Sampling](https://docs.sentry.io/platforms/go/legacy-sdk/usage.md#event-sampling)

To set up client-side sampling you can use `SetSampleRate` Client function. The Sentry SDK disables error sampling by default (sampleRate=1).

```go
raven.SetSampleRate(0.25)
```
