From 971cce8ca3da46b3b38f229d2aa060a6571806f4 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Tue, 25 Oct 2022 00:08:51 +0200 Subject: [PATCH] feat: Extend User inteface by adding Data, Name and Segment --- CHANGELOG.md | 2 ++ interfaces.go | 11 +++++++---- scope.go | 4 ++-- scope_test.go | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83fa381b..f51b34b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +- feat: Extend User inteface by adding Data, Name and Segment (#483) + ## 0.14.0 - feat: Add function to continue from trace string (#434) diff --git a/interfaces.go b/interfaces.go index a8250206..36674724 100644 --- a/interfaces.go +++ b/interfaces.go @@ -93,10 +93,13 @@ func (b *Breadcrumb) MarshalJSON() ([]byte, error) { // User describes the user associated with an Event. If this is used, at least // an ID or an IP address should be provided. type User struct { - Email string `json:"email,omitempty"` - ID string `json:"id,omitempty"` - IPAddress string `json:"ip_address,omitempty"` - Username string `json:"username,omitempty"` + Data map[string]string `json:"data,omitempty"` + Email string `json:"email,omitempty"` + ID string `json:"id,omitempty"` + IPAddress string `json:"ip_address,omitempty"` + Name string `json:"name,omitempty"` + Segment string `json:"segment,omitempty"` + Username string `json:"username,omitempty"` } // Request contains information on a HTTP request related to the event. diff --git a/scope.go b/scope.go index 51dd7fd3..0cfd199e 100644 --- a/scope.go +++ b/scope.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "net/http" + "reflect" "sync" "time" ) @@ -379,8 +380,7 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event { } } - var emptyUser User - if event.User == emptyUser { + if reflect.DeepEqual(event.User, User{}) { event.User = scope.user } diff --git a/scope_test.go b/scope_test.go index b7fb8c39..d6799cc0 100644 --- a/scope_test.go +++ b/scope_test.go @@ -37,8 +37,8 @@ func fillEventWithData(event *Event) *Event { func TestScopeSetUser(t *testing.T) { scope := NewScope() - scope.SetUser(User{ID: "foo"}) - assertEqual(t, User{ID: "foo"}, scope.user) + scope.SetUser(User{Data: map[string]string{"foo": "bar"}, Email: "foo@example.com", ID: "foo", IPAddress: "127.0.0.1", Name: "My Name", Segment: "My Segment", Username: "My Username"}) + assertEqual(t, User{Data: map[string]string{"foo": "bar"}, Email: "foo@example.com", ID: "foo", IPAddress: "127.0.0.1", Name: "My Name", Segment: "My Segment", Username: "My Username"}, scope.user) } func TestScopeSetUserOverrides(t *testing.T) {