Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Improvements to logging to Sentry.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Sep 2, 2021
1 parent a6c5544 commit 65099ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 14 additions & 5 deletions pkg/controller/plaid_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@ func (c *Controller) processWebhook(ctx iris.Context, hook PlaidWebhook) error {
"webhookCode": hook.WebhookCode,
})

crumbs.Debug(c.getContext(ctx), "Handling webhook from Plaid.", map[string]interface{}{
"type": hook.WebhookType,
"code": hook.WebhookCode,
"itemId": hook.ItemId,
})
{
fields := map[string]interface{}{
"type": hook.WebhookType,
"code": hook.WebhookCode,
"itemId": hook.ItemId,
}
switch strings.ToUpper(fmt.Sprintf("%s.%s", hook.WebhookType, hook.WebhookCode)) {
case "TRANSACTIONS.DEFAULT_UPDATE":
fields["newTransactions"] = hook.NewTransactions
case "TRANSACTIONS.TRANSACTIONS_REMOVED":
fields["removedTransactions"] = hook.RemovedTransactions
}
crumbs.Debug(c.getContext(ctx), "Handling webhook from Plaid.", fields)
}

if hub := sentry.GetHubFromContext(c.getContext(ctx)); hub != nil {
hub.ConfigureScope(func(scope *sentry.Scope) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/logging/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -40,6 +41,7 @@ func (h *PostgresHooks) BeforeQuery(ctx context.Context, event *pg.QueryEvent) (
}

func (h *PostgresHooks) AfterQuery(ctx context.Context, event *pg.QueryEvent) error {
endTime := time.Now()
var queryType string
switch query := event.Query.(type) {
case string:
Expand Down Expand Up @@ -78,13 +80,15 @@ func (h *PostgresHooks) AfterQuery(ctx context.Context, event *pg.QueryEvent) er
unformattedQuery, err := event.UnformattedQuery()
if err == nil && len(unformattedQuery) > 0 {
queryString := string(unformattedQuery)
queryTime := endTime.Sub(event.StartTime)

if event.Err == nil {
hub.AddBreadcrumb(&sentry.Breadcrumb{
Type: "query",
Category: "postgres",
Message: queryString,
Data: map[string]interface{}{
"queryTime": queryTime,
},
Level: "debug",
Timestamp: event.StartTime,
Expand All @@ -95,7 +99,8 @@ func (h *PostgresHooks) AfterQuery(ctx context.Context, event *pg.QueryEvent) er
Category: "postgres",
Message: queryString,
Data: map[string]interface{}{
"error": event.Err.Error(),
"queryTime": queryTime,
"error": event.Err.Error(),
},
Level: "error",
Timestamp: event.StartTime,
Expand Down

0 comments on commit 65099ca

Please sign in to comment.