Skip to content

Commit

Permalink
feat: track editor
Browse files Browse the repository at this point in the history
  • Loading branch information
taciturnaxolotl committed Dec 15, 2024
1 parent 823ab7a commit a2faf47
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions middlewares/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
"github.com/hackclub/hackatime/utils"
)

// SentryMiddleware is a wrapper around sentryhttp to include user information to traces
Expand All @@ -30,6 +31,13 @@ func (h *SentryMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hub.Scope().SetUser(sentry.User{ID: user.ID})
}

// Parse user agent
userAgent := r.Header.Get("User-Agent")
_, editor, err := utils.ParseUserAgent(userAgent)
if err == nil && editor != "" {
hub.Scope().SetTag("editor", editor)
}

// Attach request body if available
if r.Body != nil {
if body, err := io.ReadAll(r.Body); err == nil {
Expand Down

0 comments on commit a2faf47

Please sign in to comment.