TypeScript
fix(diagnostics): include browser trace failures (#23438)
Aditya Garud3a537d2c916e
diff --git a/apps/server/src/diagnostics/TraceDiagnostics.test.ts b/apps/server/src/diagnostics/TraceDiagnostics.test.tsindex 97156800e3d..35909007c39 100644--- a/apps/server/src/diagnostics/TraceDiagnostics.test.ts+++ b/apps/server/src/diagnostics/TraceDiagnostics.test.ts@@ -61,6 +61,35 @@ function readTraces(fileSystem: Partial<FileSystem.FileSystem>) {}describe("TraceDiagnostics", () => {+ it("includes browser failures and interruptions in diagnostics", () => {+ const diagnostics = aggregateLines(+ [+ { status: { code: "2", message: "Browser request failed" }, attributes: {} },+ { status: { code: "0" }, attributes: { "effect.fiber.interrupted": true } },+ { status: { code: "1", message: "Interrupted" }, attributes: {} },+ { status: { code: "1" }, attributes: {} },+ ].map((outcome, index) =>+ JSON.stringify({+ type: "otlp-span",+ name: "browser.request",+ traceId: `trace-${index}`,+ spanId: `span-${index}`,+ startTimeUnixNano: ns(index * 100),+ endTimeUnixNano: ns(index * 100 + 10),+ durationMs: 10,+ ...outcome,+ }),+ ),+ );++ assert.equal(diagnostics.recordCount, 4);+ assert.equal(diagnostics.failureCount, 1);+ assert.equal(diagnostics.interruptionCount, 2);+ assert.equal(diagnostics.topSpansByCount[0]?.failureCount, 1);+ assert.equal(diagnostics.commonFailures[0]?.cause, "Browser request failed");+ assert.equal(diagnostics.latestFailures[0]?.cause, "Browser request failed");+ });+it.effect("aggregates failures, slow spans, log levels, and parse errors", () =>Effect.sync(() => {const diagnostics = aggregateLines([diff --git a/apps/server/src/diagnostics/TraceDiagnostics.ts b/apps/server/src/diagnostics/TraceDiagnostics.tsindex 0cd5ae9b3a7..6f25c424a7b 100644--- a/apps/server/src/diagnostics/TraceDiagnostics.ts+++ b/apps/server/src/diagnostics/TraceDiagnostics.ts@@ -18,17 +18,6 @@ import * as Result from "effect/Result";import * as Schema from "effect/Schema";import * as Stream from "effect/Stream";-interface TraceRecordLike {- readonly name?: unknown;- readonly traceId?: unknown;- readonly spanId?: unknown;- readonly startTimeUnixNano?: unknown;- readonly endTimeUnixNano?: unknown;- readonly durationMs?: unknown;- readonly exit?: unknown;- readonly events?: unknown;-}-interface TraceEventLike {readonly name?: unknown;readonly timeUnixNano?: unknown;@@ -85,7 +74,7 @@ export function toRotatedTracePaths(return [...backups, traceFilePath];}-function isRecordObject(value: unknown): value is TraceRecordLike {+function isRecordObject(value: unknown): value is Readonly<Record<string, unknown>> {return typeof value === "object" && value !== null;}@@ -253,8 +242,13 @@ export function makeTraceDiagnosticsAggregator(lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt;const exitTag = readExitTag(parsed.exit);- const isFailure = exitTag === "Failure";- const isInterrupted = exitTag === "Interrupted";+ const status = isRecordObject(parsed.status) ? parsed.status : {};+ const attributes = isRecordObject(parsed.attributes) ? parsed.attributes : {};+ const isFailure = exitTag === "Failure" || status.code === "2";+ const isInterrupted =+ exitTag === "Interrupted" ||+ attributes["effect.fiber.interrupted"] === true ||+ status.message === "Interrupted";if (isFailure) failureCount += 1;if (isInterrupted) interruptionCount += 1;@@ -277,7 +271,10 @@ export function makeTraceDiagnosticsAggregator(insertBounded(slowestSpans, spanItem, TOP_LIMIT, slowestFirst);if (isFailure) {- const cause = readExitCause(parsed.exit);+ const cause =+ exitTag === "Failure"+ ? readExitCause(parsed.exit)+ : (toStringValue(status.message)?.trim() ?? "Failure");insertBounded(latestFailures, { ...spanItem, cause }, RECENT_LIMIT, latestEndedFirst);const failureKey = `${name}\0${cause}`;