# Scopes and Hubs | Sentry for Zap

When an event is captured and sent to Sentry, SDKs will merge that event data with extra information from the current scope. The SDK will in most cases automatically manage the scopes for you in the framework integrations and you don't need to think about them. However, you should know what a scope is and how you can use it for your advantage.

## [What's a Scope, What's a Hub](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/scopes.md#whats-a-scope-whats-a-hub)

You can think of the hub as the central point that our SDKs use to route an event to Sentry. When you call `init()` a hub is created and a client and a blank scope are created on it. That hub is then associated with the current thread and will internally hold a stack of scopes.

The scope will hold useful information that should be sent along with the event. For instance [contexts](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/context.md) or [breadcrumbs](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/breadcrumbs.md) are stored on the scope. When a scope is pushed, it inherits all data from the parent scope and when it pops all modifications are reverted.

The default SDK integrations will push and pop scopes intelligently. For instance web framework integrations will create and destroy scopes around your routes or controllers.

## [How the Scope and Hub Work](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/scopes.md#how-the-scope-and-hub-work)

As you start using an SDK, a scope and hub are automatically created for you out of the box. It's unlikely that you'll interact with the hub directly unless you're writing an integration or you want to create or destroy scopes. Scopes, on the other hand are more user facing. You can call `ConfigureScope` at any point in time to modify data stored on the scope. This is useful for doing things like [modifying the context](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/context.md).

When you call a global function such as `CaptureEvent` internally Sentry discovers the current hub and asks it to capture an event. Internally the hub will then merge the event with the topmost scope's data.

## [Configuring the Scope](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/scopes.md#configuring-the-scope)

The most useful operation when working with scopes is the `ConfigureScope` function. It can be used to reconfigure the current scope.

You can, for instance, add custom tags or inform Sentry about the currently authenticated user.

```go
sentry.ConfigureScope(func(scope *sentry.Scope) {
	scope.SetTag("my-tag", "my value")
	scope.SetUser(sentry.User{
		ID: "42",
		Email: "john.doe@example.com",
	})
})
```

You can also apply this configuration when unsetting a user at logout:

```go
sentry.ConfigureScope(func(scope *sentry.Scope) {
	scope.SetUser(sentry.User{})
})
```

To learn what useful information can be associated with scopes see [the context documentation](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/context.md).

## [Local Scopes](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/scopes.md#local-scopes)

We also support pushing and configuring a scope within a single call. This is typically called `WithScope`, `PushScope` or implemented as a function parameter on the capture methods, depending on the SDK. It's very helpful if you only want to send data for one specific event.

### [Using `WithScope`](https://docs.sentry.io/platforms/go/guides/zap/enriching-events/scopes.md#using-with-scope)

In the following example we use `WithScope` to attach a `level` and a `tag` to only one specific error:

```go
sentry.WithScope(func(scope *sentry.Scope) {
	scope.SetTag("my-tag", "my value");
	scope.SetLevel(sentry.LevelWarning);
	// will be tagged with my-tag="my value"
	sentry.CaptureException(errors.New("my error"))
})

// will not be tagged with my-tag
sentry.CaptureException(errors.New("my error"))
```

While this example looks similar to `ConfigureScope`, it is actually very different. Calls to `ConfigureScope` change the current active scope; all successive calls to `ConfigureScope` will maintain previously set changes unless they are explicitly unset.

On the other hand, `WithScope` creates a clone of the current scope, and the changes made will stay isolated within the `WithScope` callback function. This allows you to more easily isolate pieces of context information to specific locations in your code or even call `Clear` to briefly remove all context information.
