|
8 | 8 | createStreamReadUrl, |
9 | 9 | encodeStreamOffset, |
10 | 10 | getStreamEventsWindow, |
| 11 | + normalizeStreamEvents, |
11 | 12 | useStreamEvents, |
12 | 13 | } from "./use-stream-events"; |
13 | 14 | import type { StudioStream } from "./use-streams"; |
@@ -262,6 +263,128 @@ describe("useStreamEvents", () => { |
262 | 263 | ); |
263 | 264 | }); |
264 | 265 |
|
| 266 | + it("summarizes evlog request previews without showing raw JSON", () => { |
| 267 | + const events = normalizeStreamEvents({ |
| 268 | + events: [ |
| 269 | + { |
| 270 | + timestamp: "2026-06-12T17:05:10.935Z", |
| 271 | + level: "info", |
| 272 | + service: "storefront", |
| 273 | + method: "GET", |
| 274 | + path: "/product/acme-mug", |
| 275 | + status: 200, |
| 276 | + duration: 0, |
| 277 | + message: "Storefront request", |
| 278 | + }, |
| 279 | + { |
| 280 | + timestamp: "2026-06-12T17:09:18.912Z", |
| 281 | + level: "error", |
| 282 | + service: "storefront", |
| 283 | + method: "POST", |
| 284 | + path: "/api/observability/simulate", |
| 285 | + status: 500, |
| 286 | + message: "Synthetic diagnostic: Trace fanout", |
| 287 | + }, |
| 288 | + ], |
| 289 | + startExclusiveSequence: 0n, |
| 290 | + stream: { |
| 291 | + epoch: 0, |
| 292 | + name: "webshop-production-events", |
| 293 | + profile: "evlog", |
| 294 | + }, |
| 295 | + }); |
| 296 | + |
| 297 | + expect(events.map((event) => event.preview)).toEqual([ |
| 298 | + "GET /product/acme-mug", |
| 299 | + "POST /api/observability/simulate 500 Synthetic diagnostic: Trace fanout", |
| 300 | + ]); |
| 301 | + }); |
| 302 | + |
| 303 | + it("keeps generic previews for non-evlog streams", () => { |
| 304 | + const events = normalizeStreamEvents({ |
| 305 | + events: [ |
| 306 | + { |
| 307 | + method: "GET", |
| 308 | + path: "/product/acme-mug", |
| 309 | + status: 200, |
| 310 | + message: "Storefront request", |
| 311 | + }, |
| 312 | + ], |
| 313 | + startExclusiveSequence: 0n, |
| 314 | + stream: { |
| 315 | + epoch: 0, |
| 316 | + name: "generic-json-events", |
| 317 | + profile: null, |
| 318 | + }, |
| 319 | + }); |
| 320 | + |
| 321 | + expect(events[0]?.preview).toBe( |
| 322 | + '{"method":"GET","path":"/product/acme-mug","status":200,"message":"Storefront request"}', |
| 323 | + ); |
| 324 | + }); |
| 325 | + |
| 326 | + it("summarizes otel trace span previews without showing raw JSON", () => { |
| 327 | + const events = normalizeStreamEvents({ |
| 328 | + events: [ |
| 329 | + { |
| 330 | + attributes: { |
| 331 | + "http.request.method": "POST", |
| 332 | + "http.response.status_code": 200, |
| 333 | + "url.path": "/api/query-insights/snapshot", |
| 334 | + }, |
| 335 | + endUnixNano: "1810000003486000000", |
| 336 | + kind: "server", |
| 337 | + name: "fetchHandler POST", |
| 338 | + resource: { |
| 339 | + attributes: { |
| 340 | + "service.name": "console", |
| 341 | + }, |
| 342 | + }, |
| 343 | + spanId: "086e83747d0e381e", |
| 344 | + startUnixNano: "1810000000000000000", |
| 345 | + status: { code: "ok", message: null }, |
| 346 | + traceId: "5b8efff798038103d269b633813fc60c", |
| 347 | + }, |
| 348 | + { |
| 349 | + attributes: { "url.full": "https://payments.internal/charges" }, |
| 350 | + endUnixNano: "1810000000192000000", |
| 351 | + events: [ |
| 352 | + { |
| 353 | + attributes: { |
| 354 | + "exception.message": "Card declined by issuer", |
| 355 | + "exception.type": "CardDeclinedError", |
| 356 | + }, |
| 357 | + name: "exception", |
| 358 | + timeUnixNano: "1810000000190000000", |
| 359 | + }, |
| 360 | + ], |
| 361 | + kind: "client", |
| 362 | + name: "POST payments /charges", |
| 363 | + resource: { |
| 364 | + attributes: { |
| 365 | + "service.name": "payments", |
| 366 | + }, |
| 367 | + }, |
| 368 | + spanId: "22dd83747d0e3822", |
| 369 | + startUnixNano: "1810000000041000000", |
| 370 | + status: { code: "error", message: "402 from issuer" }, |
| 371 | + traceId: "5b8efff798038103d269b633813fc60c", |
| 372 | + }, |
| 373 | + ], |
| 374 | + startExclusiveSequence: 0n, |
| 375 | + stream: { |
| 376 | + epoch: 0, |
| 377 | + name: "webshop-production-traces", |
| 378 | + profile: "otel-traces", |
| 379 | + }, |
| 380 | + }); |
| 381 | + |
| 382 | + expect(events.map((event) => event.preview)).toEqual([ |
| 383 | + "POST /api/query-insights/snapshot | console | 3.49s", |
| 384 | + "POST payments /charges | payments | 151ms | error: 402 from issuer", |
| 385 | + ]); |
| 386 | + }); |
| 387 | + |
265 | 388 | it("loads a tail window and normalizes events into newest-first rows", async () => { |
266 | 389 | const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue( |
267 | 390 | new Response( |
|
0 commit comments