Skip to content

Commit

Permalink
feat: Extend User inteface by adding Data, Name and Segment
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Oct 24, 2022
1 parent 2503eee commit 971cce8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions 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)
Expand Down
11 changes: 7 additions & 4 deletions interfaces.go
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions scope.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"net/http"
"reflect"
"sync"
"time"
)
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions scope_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit 971cce8

Please sign in to comment.