Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _examples/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
app.GET("/", func(ctx echo.Context) error {
if hub := sentryecho.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion _examples/fasthttp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
defaultHandler := func(ctx *fasthttp.RequestCtx) {
if hub := sentryfasthttp.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
6 changes: 3 additions & 3 deletions _examples/feature-showcase/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func captureMessage() {

func configureScope() {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetExtra("oristhis", "justfantasy")
scope.SetTag("oristhis", "justfantasy")
scope.SetTag("isthis", "reallife")
scope.SetLevel(sentry.LevelFatal)
scope.SetUser(sentry.User{
Expand Down Expand Up @@ -80,8 +80,8 @@ func addBreadcrumbs() {
func withScopeAndConfigureScope() {
sentry.WithScope(func(scope *sentry.Scope) {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetExtras(map[string]interface{}{
"istillcant": 42,
scope.SetTags(map[string]string{
"istillcant": "42",
"believe": "that",
})
scope.SetTags(map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion _examples/fiber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
app.All("/", func(ctx *fiber.Ctx) error {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion _examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
app.GET("/", func(ctx *gin.Context) {
if hub := sentrygin.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion _examples/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if hub := sentryiris.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion _examples/negroni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
hub := sentry.GetHubFromContext(r.Context())
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
rw.WriteHeader(http.StatusOK)
Expand Down
2 changes: 1 addition & 1 deletion _examples/recover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
})

sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetExtra("oristhis", "justfantasy")
scope.SetTag("oristhis", "justfantasy")
scope.SetTag("isthis", "reallife")
scope.SetLevel(sentry.LevelFatal)
scope.SetUser(sentry.User{
Expand Down
2 changes: 1 addition & 1 deletion echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ app.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
app.GET("/", func(ctx echo.Context) error {
if hub := sentryecho.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion fasthttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{
defaultHandler := func(ctx *fasthttp.RequestCtx) {
if hub := sentryfasthttp.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion fiber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ app.All("/foo", enhanceSentryEvent, func(ctx *fiber.Ctx) {
app.All("/", func(ctx *fiber.Ctx) {
if hub := sentryfiber.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion gin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ app.Use(func(ctx *gin.Context) {
app.GET("/", func(ctx *gin.Context) {
if hub := sentrygin.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type handler struct{}
func (h *handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
if hub := sentry.GetHubFromContext(r.Context()); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion iris/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ app.Use(func(ctx iris.Context) {
app.Get("/", func(ctx iris.Context) {
if hub := sentryiris.GetHubFromContext(ctx); hub != nil {
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
}
Expand Down
2 changes: 1 addition & 1 deletion negroni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mux := http.NewServeMux()
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
hub := sentry.GetHubFromContext(r.Context())
hub.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
scope.SetTag("unwantedQuery", "someQueryDataMaybe")
hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
})
rw.WriteHeader(http.StatusOK)
Expand Down
19 changes: 19 additions & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ func (scope *Scope) SetAttributes(attrs ...attribute.Builder) {
}
}

// RemoveAttribute removes an attribute from the current scope.
func (scope *Scope) RemoveAttribute(key string) {
scope.mu.Lock()
defer scope.mu.Unlock()
delete(scope.attributes, key)
}

// SetTag adds a tag to the current scope.
func (scope *Scope) SetTag(key, value string) {
scope.mu.Lock()
Expand Down Expand Up @@ -276,6 +283,10 @@ func (scope *Scope) RemoveContext(key string) {
}

// SetExtra adds an extra to the current scope.
//
// Deprecated: Use [Scope.SetAttributes] instead, which attaches typed key-value
// pairs to logs and metrics. Note that attributes do not attach to error events;
// if you only capture errors, use [Scope.SetTag] or [Scope.SetContext] to enrich them.
func (scope *Scope) SetExtra(key string, value interface{}) {
scope.mu.Lock()
defer scope.mu.Unlock()
Expand All @@ -284,6 +295,10 @@ func (scope *Scope) SetExtra(key string, value interface{}) {
}

// SetExtras assigns multiple extras to the current scope.
//
// Deprecated: Use [Scope.SetAttributes] instead, which attaches typed key-value
// pairs to logs and metrics. Note that attributes do not attach to error events;
// if you only capture errors, use [Scope.SetTag] or [Scope.SetContext] to enrich them.
func (scope *Scope) SetExtras(extra map[string]interface{}) {
scope.mu.Lock()
defer scope.mu.Unlock()
Expand All @@ -294,6 +309,10 @@ func (scope *Scope) SetExtras(extra map[string]interface{}) {
}

// RemoveExtra removes a extra from the current scope.
//
// Deprecated: Use [Scope.RemoveAttribute] instead. Note that attributes only
// attach to logs and metrics, not error events. If you only capture errors,
// use [Scope.RemoveTag] or [Scope.RemoveContext] instead.
func (scope *Scope) RemoveExtra(key string) {
scope.mu.Lock()
defer scope.mu.Unlock()
Expand Down
3 changes: 3 additions & 0 deletions scope_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/getsentry/sentry-go"
"github.com/getsentry/sentry-go/attribute"
)

func TestConcurrentScopeUsage(_ *testing.T) {
Expand Down Expand Up @@ -51,6 +52,8 @@ func touchScope(scope *sentry.Scope, x int) {
scope.SetTag("foo", "bar")
scope.SetContext("foo", sentry.Context{"foo": "bar"})
scope.SetExtra("foo", "bar")
scope.SetAttributes(attribute.String("foo", "bar"))
scope.RemoveAttribute("foo")
scope.SetLevel(sentry.LevelDebug)
scope.SetFingerprint([]string{"foo"})
scope.AddBreadcrumb(&sentry.Breadcrumb{Message: "foo"}, 100)
Expand Down
24 changes: 24 additions & 0 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ func TestScope_SetAttributes(t *testing.T) {
}, scope.attributes)
}

func TestScopeRemoveAttributeOnEmptyScope(t *testing.T) {
scope := NewScope()
scope.RemoveAttribute("key.nonexistent")

assertEqual(t, make(map[string]attribute.Value), scope.attributes)
}

func TestScopeRemoveAttributeNotInPopulateAttrs(t *testing.T) {
scope := NewScope()
scope.SetAttributes(
attribute.String("key.one", "val1"),
attribute.String("key.two", "val2"),
)
scope.RemoveAttribute("key.two")

attrs := make(map[string]attribute.Value)
scope.populateAttrs(attrs)

if _, ok := attrs["key.two"]; ok {
t.Error("removed attribute should not appear in populateAttrs output")
}
assertEqual(t, attribute.StringValue("val1"), attrs["key.one"])
}

func TestScopeRemoveTag(t *testing.T) {
scope := NewScope()
scope.SetTag("a", "foo")
Expand Down
Loading