MCPcopy Create free account
hub / github.com/buggregator/server / handleExceptionsChronological

Function handleExceptionsChronological

modules/sentry/api_exceptions.go:124–208  ·  view source on GitHub ↗
(db *sql.DB, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

122}
123
124func handleExceptionsChronological(db *sql.DB, w http.ResponseWriter, r *http.Request) {
125 limit, offset := pagination(r, 50)
126 q := r.URL.Query()
127
128 query := `SELECT
129 e.id, e.event_id, e.fingerprint,
130 (SELECT COUNT(*) FROM sentry_error_events e2 WHERE e2.fingerprint = e.fingerprint) as occurrence_count,
131 (SELECT se.exception_type FROM sentry_exceptions se WHERE se.error_event_id = e.id AND se.position = 0 LIMIT 1) as exception_type,
132 (SELECT se.exception_value FROM sentry_exceptions se WHERE se.error_event_id = e.id AND se.position = 0 LIMIT 1) as exception_value,
133 e.level, e.handled, e."transaction", e.received_at, e.trace_id
134 FROM sentry_error_events e`
135
136 countQuery := `SELECT COUNT(*) FROM sentry_error_events e`
137
138 var conditions []string
139 var args []any
140
141 if v := q.Get("level"); v != "" {
142 conditions = append(conditions, "e.level = ?")
143 args = append(args, v)
144 }
145 if v := q.Get("handled"); v != "" {
146 if v == "true" {
147 conditions = append(conditions, "e.handled = 1")
148 } else {
149 conditions = append(conditions, "e.handled = 0")
150 }
151 }
152
153 where := ""
154 if len(conditions) > 0 {
155 where = " WHERE " + strings.Join(conditions, " AND ")
156 }
157
158 query += where + " ORDER BY e.received_at DESC LIMIT ? OFFSET ?"
159 countQuery += where
160
161 var total int
162 db.QueryRow(countQuery, args...).Scan(&total)
163
164 queryArgs := append(args, limit, offset)
165 rows, err := db.Query(query, queryArgs...)
166 if err != nil {
167 apiError(w, err.Error(), http.StatusInternalServerError)
168 return
169 }
170 defer rows.Close()
171
172 var data []map[string]any
173 for rows.Next() {
174 var (
175 id, eventID, fingerprint string
176 occurrenceCount int
177 excType, excValue sql.NullString
178 level string
179 handled sql.NullBool
180 txn sql.NullString
181 receivedAt string

Callers 1

handleExceptionsListFunction · 0.85

Calls 9

paginationFunction · 0.85
apiErrorFunction · 0.85
scanNullStringFunction · 0.85
scanNullBoolFunction · 0.85
apiJSONFunction · 0.85
listResponseFunction · 0.85
currentPageFunction · 0.85
ScanMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected