Skip to content

Commit

Permalink
chore(debug): Improving sentry usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Nov 26, 2022
1 parent 527b26e commit a993291
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 75 deletions.
4 changes: 1 addition & 3 deletions pkg/models/spending.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"
"time"

"github.com/getsentry/sentry-go"
"github.com/monetr/monetr/pkg/crumbs"
"github.com/monetr/monetr/pkg/internal/myownsanity"
"github.com/monetr/monetr/pkg/util"
Expand Down Expand Up @@ -89,9 +88,8 @@ func (e *Spending) CalculateNextContribution(
fundingSchedule *FundingSchedule,
now time.Time,
) error {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "CalculateNextContribution"

span.SetTag("spendingId", strconv.FormatUint(e.SpendingId, 10))

Expand Down
7 changes: 3 additions & 4 deletions pkg/repository/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/getsentry/sentry-go"
"github.com/monetr/monetr/pkg/crumbs"
"github.com/monetr/monetr/pkg/models"
"github.com/pkg/errors"
)
Expand All @@ -13,9 +14,8 @@ func (r *repositoryBase) GetAccount(ctx context.Context) (*models.Account, error
return r.account, nil
}

span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetAccount"

var account models.Account
err := r.txn.ModelContext(span.Context(), &account).
Expand All @@ -37,9 +37,8 @@ func (r *repositoryBase) GetAccount(ctx context.Context) (*models.Account, error
// DeleteAccount removes all of the records from the database related to the current account. This action cannot be
// undone. Any Plaid links should be removed BEFORE calling this function.
func (r *repositoryBase) DeleteAccount(ctx context.Context) error {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "DeleteAccount"

dataTypes := []interface{}{
&models.Transaction{},
Expand Down
8 changes: 6 additions & 2 deletions pkg/repository/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/getsentry/sentry-go"
"github.com/monetr/monetr/pkg/crumbs"
"github.com/pkg/errors"
)

Expand All @@ -20,7 +21,7 @@ type Balances struct {
}

func (r *repositoryBase) GetBalances(ctx context.Context, bankAccountId uint64) (*Balances, error) {
span := sentry.StartSpan(ctx, "GetBalances")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

var balance Balances
Expand Down Expand Up @@ -50,8 +51,11 @@ type FundingStats struct {
}

func (r *repositoryBase) GetFundingStats(ctx context.Context, bankAccountId uint64) ([]FundingStats, error) {
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

stats := make([]FundingStats, 0)
err := r.txn.ModelContext(ctx, &stats).
err := r.txn.ModelContext(span.Context(), &stats).
Where(`"funding_stats"."account_id" = ?`, r.AccountId()).
Where(`"funding_stats"."bank_account_id" = ?`, bankAccountId).
Select(&stats)
Expand Down
18 changes: 10 additions & 8 deletions pkg/repository/expenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package repository

import (
"context"
"time"

"github.com/getsentry/sentry-go"
"github.com/monetr/monetr/pkg/crumbs"
"github.com/monetr/monetr/pkg/models"
"github.com/pkg/errors"
"time"
)

func (r *repositoryBase) GetSpending(ctx context.Context, bankAccountId uint64) ([]models.Spending, error) {
span := sentry.StartSpan(ctx, "GetSpending")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand All @@ -33,7 +35,7 @@ func (r *repositoryBase) GetSpending(ctx context.Context, bankAccountId uint64)
}

func (r *repositoryBase) GetSpendingExists(ctx context.Context, bankAccountId, spendingId uint64) (bool, error) {
span := sentry.StartSpan(ctx, "GetSpendingExists")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand All @@ -58,7 +60,7 @@ func (r *repositoryBase) GetSpendingExists(ctx context.Context, bankAccountId, s
}

func (r *repositoryBase) GetSpendingByFundingSchedule(ctx context.Context, bankAccountId, fundingScheduleId uint64) ([]models.Spending, error) {
span := sentry.StartSpan(ctx, "GetSpendingByFundingSchedule")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand All @@ -84,7 +86,7 @@ func (r *repositoryBase) GetSpendingByFundingSchedule(ctx context.Context, bankA
}

func (r *repositoryBase) CreateSpending(ctx context.Context, spending *models.Spending) error {
span := sentry.StartSpan(ctx, "CreateSpending")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand All @@ -109,7 +111,7 @@ func (r *repositoryBase) CreateSpending(ctx context.Context, spending *models.Sp
// UpdateSpending should only be called with complete expense models. Do not use partial models with missing data for
// this action.
func (r *repositoryBase) UpdateSpending(ctx context.Context, bankAccountId uint64, updates []models.Spending) error {
span := sentry.StartSpan(ctx, "UpdateSpending")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

spendingIds := make([]uint64, len(updates))
Expand Down Expand Up @@ -138,7 +140,7 @@ func (r *repositoryBase) UpdateSpending(ctx context.Context, bankAccountId uint6
}

func (r *repositoryBase) GetSpendingById(ctx context.Context, bankAccountId, spendingId uint64) (*models.Spending, error) {
span := sentry.StartSpan(ctx, "GetSpendingById")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand All @@ -165,7 +167,7 @@ func (r *repositoryBase) GetSpendingById(ctx context.Context, bankAccountId, spe
}

func (r *repositoryBase) DeleteSpending(ctx context.Context, bankAccountId, spendingId uint64) error {
span := sentry.StartSpan(ctx, "Delete Spending")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

span.Data = map[string]interface{}{
Expand Down
18 changes: 6 additions & 12 deletions pkg/repository/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
)

func (r *repositoryBase) GetLink(ctx context.Context, linkId uint64) (*models.Link, error) {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetLink"
span.Data = map[string]interface{}{
"linkId": linkId,
}
Expand All @@ -33,9 +32,8 @@ func (r *repositoryBase) GetLink(ctx context.Context, linkId uint64) (*models.Li
}

func (r *repositoryBase) GetLinks(ctx context.Context) ([]models.Link, error) {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetLinks"

var result []models.Link
err := r.txn.ModelContext(span.Context(), &result).
Expand All @@ -49,9 +47,8 @@ func (r *repositoryBase) GetLinks(ctx context.Context) ([]models.Link, error) {
}

func (r *repositoryBase) GetNumberOfPlaidLinks(ctx context.Context) (int, error) {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetNumberOfPlaidLinks"

count, err := r.txn.ModelContext(span.Context(), &models.Link{}).
Where(`"link"."account_id" = ?`, r.accountId).
Expand All @@ -65,9 +62,8 @@ func (r *repositoryBase) GetNumberOfPlaidLinks(ctx context.Context) (int, error)
}

func (r *repositoryBase) GetLinkIsManual(ctx context.Context, linkId uint64) (bool, error) {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetLinkIsManual"
span.Data = map[string]interface{}{
"linkId": linkId,
}
Expand All @@ -88,9 +84,8 @@ func (r *repositoryBase) GetLinkIsManual(ctx context.Context, linkId uint64) (bo
}

func (r *repositoryBase) GetLinkIsManualByBankAccountId(ctx context.Context, bankAccountId uint64) (bool, error) {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "GetLinkIsManualByBankAccountId"
span.Data = map[string]interface{}{
"bankAccountId": bankAccountId,
}
Expand All @@ -113,9 +108,8 @@ func (r *repositoryBase) GetLinkIsManualByBankAccountId(ctx context.Context, ban
}

func (r *repositoryBase) CreateLink(ctx context.Context, link *models.Link) error {
span := sentry.StartSpan(ctx, "function")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()
span.Description = "CreateLink"

userId := r.UserId()
now := time.Now().UTC()
Expand Down
1 change: 0 additions & 1 deletion pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type BaseRepository interface {
GetLinkIsManualByBankAccountId(ctx context.Context, bankAccountId uint64) (bool, error)
GetLinks(ctx context.Context) ([]models.Link, error)
GetNumberOfPlaidLinks(ctx context.Context) (int, error)
GetPendingTransactionsForBankAccount(ctx context.Context, bankAccountId uint64) ([]models.Transaction, error)
GetSettings(ctx context.Context) (*models.Settings, error)
GetSpending(ctx context.Context, bankAccountId uint64) ([]models.Spending, error)
GetSpendingByFundingSchedule(ctx context.Context, bankAccountId, fundingScheduleId uint64) ([]models.Spending, error)
Expand Down
4 changes: 2 additions & 2 deletions pkg/repository/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewSecurityRepository(db pg.DBI) SecurityRepository {
}

func (b *baseSecurityRepository) Login(ctx context.Context, email, password string) (*models.Login, bool, error) {
span := sentry.StartSpan(ctx, "Login")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

requiresPasswordChange := false
Expand Down Expand Up @@ -109,7 +109,7 @@ func (b *baseSecurityRepository) Login(ctx context.Context, email, password stri
}

func (b *baseSecurityRepository) ChangePassword(ctx context.Context, loginId uint64, oldPassword, newPassword string) error {
span := sentry.StartSpan(ctx, "ChangePassword")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

var login models.LoginWithHash
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (r *repositoryBase) GetSettings(ctx context.Context) (*models.Settings, error) {
span := sentry.StartSpan(ctx, "GetSettings")
span := crumbs.StartFnTrace(ctx)
defer span.Finish()

result := models.Settings{
Expand Down
Loading

0 comments on commit a993291

Please sign in to comment.