Skip to content

Commit

Permalink
Do not change Hub.lastEventID for transactions (#379)
Browse files Browse the repository at this point in the history
LastEventID was meant to be used for error IDs, and with the addition of
the transaction event type, those use cases got affected.
  • Loading branch information
rhcarvalho committed Sep 10, 2021
1 parent 8a528f8 commit d5877e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ func (hub *Hub) CaptureEvent(event *Event) *EventID {
}
eventID := client.CaptureEvent(event, nil, scope)

hub.mu.Lock()
defer hub.mu.Unlock()
if eventID != nil {
hub.lastEventID = *eventID
} else {
hub.lastEventID = ""
if event.Type != transactionType {
hub.mu.Lock()
defer hub.mu.Unlock()
if eventID != nil {
hub.lastEventID = *eventID
} else {
hub.lastEventID = ""
}
}
return eventID
}
Expand Down
10 changes: 10 additions & 0 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ func TestLastEventIDUpdatesAfterCaptures(t *testing.T) {
assertEqual(t, *eventID, hub.LastEventID())
}

func TestLastEventIDNotChangedForTransactions(t *testing.T) {
hub, _, _ := setupHubTest()

errorID := hub.CaptureException(fmt.Errorf("wat"))
assertEqual(t, *errorID, hub.LastEventID())

hub.CaptureEvent(&Event{Type: transactionType})
assertEqual(t, *errorID, hub.LastEventID())
}

func TestAddBreadcrumbRespectMaxBreadcrumbsOption(t *testing.T) {
hub, client, scope := setupHubTest()
client.options.MaxBreadcrumbs = 2
Expand Down

0 comments on commit d5877e5

Please sign in to comment.