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

Function storeErrorEvent

modules/sentry/store_error.go:15–134  ·  view source on GitHub ↗

storeErrorEvent stores a parsed error event with its exceptions and breadcrumbs in a single DB transaction.

(db *sql.DB, ev *ErrorEvent, payload json.RawMessage, projectID string)

Source from the content-addressed store, hash-verified

13// storeErrorEvent stores a parsed error event with its exceptions and breadcrumbs
14// in a single DB transaction.
15func storeErrorEvent(db *sql.DB, ev *ErrorEvent, payload json.RawMessage, projectID string) (string, error) {
16 tx, err := db.Begin()
17 if err != nil {
18 return "", err
19 }
20 defer tx.Rollback()
21
22 id := event.GenerateUUID()
23 fingerprint := computeFingerprint(ev)
24
25 level := ev.Level
26 if level == "" {
27 level = "error"
28 }
29
30 var handled *int
31 if ev.Exception != nil && len(ev.Exception.Values) > 0 {
32 if m := ev.Exception.Values[0].Mechanism; m != nil && m.Handled != nil {
33 v := 0
34 if *m.Handled {
35 v = 1
36 }
37 handled = &v
38 }
39 }
40
41 eventTS := parseTimestamp(ev.Timestamp.Number())
42
43 _, err = tx.Exec(
44 `INSERT INTO sentry_error_events
45 (id, event_id, project_id, trace_id, span_id, level, environment, release, server_name, platform, "transaction", fingerprint, handled, event_ts, payload)
46 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
47 id,
48 ev.EventID,
49 nullIfEmpty(projectID),
50 nullIfEmpty(ev.traceID()),
51 nullIfEmpty(ev.spanID()),
52 level,
53 nullIfEmpty(ev.Environment),
54 nullIfEmpty(ev.Release),
55 nullIfEmpty(ev.ServerName),
56 nullIfEmpty(ev.Platform),
57 nullIfEmpty(ev.Transaction),
58 fingerprint,
59 handled,
60 eventTS,
61 string(payload),
62 )
63 if err != nil {
64 return "", fmt.Errorf("insert sentry_error_events: %w", err)
65 }
66
67 // Insert exceptions.
68 if ev.Exception != nil {
69 for i, exc := range ev.Exception.Values {
70 excID := event.GenerateUUID()
71 var excHandled *int
72 if exc.Mechanism != nil && exc.Mechanism.Handled != nil {

Callers 5

storeJSONEventMethod · 0.85
handleEventItemMethod · 0.85
TestStoreErrorEventFunction · 0.85
seedTestDataFunction · 0.85

Calls 8

GenerateUUIDFunction · 0.92
computeFingerprintFunction · 0.85
nullIfEmptyFunction · 0.85
mechanismTypeFunction · 0.85
NumberMethod · 0.80
traceIDMethod · 0.80
spanIDMethod · 0.80
parseTimestampFunction · 0.70

Tested by 3

TestStoreErrorEventFunction · 0.68
seedTestDataFunction · 0.68