Skip to content

Add ability to override hub stored in gin.Context #234

@pascal-de-ladurantaye

Description

@pascal-de-ladurantaye

Summary

A way to override the hub stored in the gin.Context.

Motivation

This request comes after I ran into an issue where I want to use a Copy() of the gin Context for a goroutine. This function task takes that gin Context clone and might have to report errors through sentry. Documentation on goroutines indicates that we should use a local hub to avoid race conditions when modifying the Scope.

The idea is to shield the implementation of the potentially goroutined function from having to know it is running in a goroutine and having to create its own local hub. Ideally, that function would be able to use GetHubFromContext normally and the local hub would be injected seamlessly.

Additional Context

It would be useful to be able to do the following:

for _, item := range items {
	ctxClone := ctx.Copy()
	sentrygin.SetHubInContext(ctxClone, sentrygin.GetHubFromContext(ctx).Clone())
	go doSomething(ctxClone, item, resultChannel)
}

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions