Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extend User struct by adding Data, Name and Segment #483

Merged
merged 7 commits into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"`
cleptric marked this conversation as resolved.
Show resolved Hide resolved
Email string `json:"email,omitempty"`
ID string `json:"id,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
Name string `json:"name,omitempty"`
cleptric marked this conversation as resolved.
Show resolved Hide resolved
Segment string `json:"segment,omitempty"`
cleptric marked this conversation as resolved.
Show resolved Hide resolved
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{}) {
cleptric marked this conversation as resolved.
Show resolved Hide resolved
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