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

Function storeLogs

modules/sentry/store_log.go:14–69  ·  view source on GitHub ↗

storeLogs batch inserts Sentry native log items.

(db *sql.DB, logs []LogRecord)

Source from the content-addressed store, hash-verified

12
13// storeLogs batch inserts Sentry native log items.
14func storeLogs(db *sql.DB, logs []LogRecord) error {
15 if len(logs) == 0 {
16 return nil
17 }
18
19 tx, err := db.Begin()
20 if err != nil {
21 return err
22 }
23 defer tx.Rollback()
24
25 stmt, err := tx.Prepare(
26 `INSERT INTO sentry_logs
27 (id, trace_id, span_id, level, severity_number, body, attributes, log_ts)
28 VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
29 )
30 if err != nil {
31 return fmt.Errorf("prepare sentry_logs: %w", err)
32 }
33 defer stmt.Close()
34
35 for _, log := range logs {
36 id := event.GenerateUUID()
37
38 var attrs *string
39 if log.Attributes != nil {
40 b, _ := json.Marshal(log.Attributes)
41 s := string(b)
42 attrs = &s
43 }
44
45 var sevNum *int
46 if log.SeverityNumber > 0 {
47 v := log.SeverityNumber
48 sevNum = &v
49 }
50
51 logTS := parseLogTimestamp(log.Timestamp)
52
53 _, err = stmt.Exec(
54 id,
55 nullIfEmpty(log.TraceID),
56 nullIfEmpty(log.SpanID),
57 log.Level,
58 sevNum,
59 log.Body,
60 attrs,
61 logTS,
62 )
63 if err != nil {
64 return fmt.Errorf("insert sentry_logs: %w", err)
65 }
66 }
67
68 return tx.Commit()
69}
70
71// parseLogTimestamp handles both float epoch seconds and string ISO timestamps.

Callers 3

handleLogItemMethod · 0.85
TestStoreLogsFunction · 0.85
seedTestDataFunction · 0.85

Calls 3

GenerateUUIDFunction · 0.92
parseLogTimestampFunction · 0.85
nullIfEmptyFunction · 0.85

Tested by 2

TestStoreLogsFunction · 0.68
seedTestDataFunction · 0.68