(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func TestStoreTransaction(t *testing.T) { |
| 180 | db := setupTestDB(t) |
| 181 | |
| 182 | payload := json.RawMessage(`{ |
| 183 | "event_id": "txn-1", |
| 184 | "type": "transaction", |
| 185 | "transaction": "GET /api/users", |
| 186 | "op": "http.server", |
| 187 | "status": "ok", |
| 188 | "start_timestamp": 1678272500.0, |
| 189 | "timestamp": 1678272505.844, |
| 190 | "environment": "production", |
| 191 | "contexts": {"trace": {"trace_id": "aabbccdd11223344", "span_id": "root-span"}}, |
| 192 | "spans": [ |
| 193 | { |
| 194 | "span_id": "span-1", |
| 195 | "parent_span_id": "root-span", |
| 196 | "trace_id": "aabbccdd11223344", |
| 197 | "op": "db.query", |
| 198 | "description": "SELECT * FROM users", |
| 199 | "status": "ok", |
| 200 | "start_timestamp": 1678272501.0, |
| 201 | "timestamp": 1678272502.0, |
| 202 | "data": {"server.address": "db.example.com", "db.name": "mydb"} |
| 203 | }, |
| 204 | { |
| 205 | "span_id": "span-2", |
| 206 | "parent_span_id": "root-span", |
| 207 | "trace_id": "aabbccdd11223344", |
| 208 | "op": "http.client", |
| 209 | "description": "POST https://api.example.com/notify", |
| 210 | "status": "internal_error", |
| 211 | "start_timestamp": 1678272503.0, |
| 212 | "timestamp": 1678272504.5, |
| 213 | "data": {"http.url": "https://api.example.com/notify"} |
| 214 | } |
| 215 | ] |
| 216 | }`) |
| 217 | |
| 218 | var txn Transaction |
| 219 | if err := json.Unmarshal(payload, &txn); err != nil { |
| 220 | t.Fatal(err) |
| 221 | } |
| 222 | |
| 223 | id, err := storeTransaction(db, &txn, payload) |
| 224 | if err != nil { |
| 225 | t.Fatal(err) |
| 226 | } |
| 227 | if id == "" { |
| 228 | t.Fatal("expected non-empty ID") |
| 229 | } |
| 230 | |
| 231 | // Verify sentry_traces. |
| 232 | var spanCount, errorCount int |
| 233 | err = db.QueryRow(`SELECT span_count, error_count FROM sentry_traces WHERE trace_id = ?`, "aabbccdd11223344").Scan(&spanCount, &errorCount) |
| 234 | if err != nil { |
| 235 | t.Fatal(err) |
| 236 | } |
nothing calls this directly
no test coverage detected