| ... | ... | @@ -16,6 +16,7 @@ import * as Option from "effect/Option"; |
| 16 | 16 | import * as PlatformError from "effect/PlatformError"; |
| 17 | 17 | import * as Result from "effect/Result"; |
| 18 | 18 | import * as Schema from "effect/Schema"; |
| 19 | import * as Stream from "effect/Stream"; |
| 19 | 20 | |
| 20 | 21 | interface TraceRecordLike { |
| 21 | 22 | readonly name?: unknown; |
| ... | ... | @@ -63,16 +64,6 @@ export class TraceDiagnostics extends Context.Service< |
| 63 | 64 | } |
| 64 | 65 | >()("t3/diagnostics/TraceDiagnostics") {} |
| 65 | 66 | |
| 66 | | interface TraceDiagnosticsInput { |
| 67 | | readonly traceFilePath: string; |
| 68 | | readonly files: ReadonlyArray<{ readonly path: string; readonly text: string }>; |
| 69 | | readonly scannedFilePaths?: ReadonlyArray<string>; |
| 70 | | readonly slowSpanThresholdMs?: number; |
| 71 | | readonly readAt: DateTime.Utc; |
| 72 | | readonly error?: TraceDiagnosticsErrorSummary; |
| 73 | | readonly partialFailure?: boolean; |
| 74 | | } |
| 75 | | |
| 76 | 67 | interface TraceDiagnosticsErrorSummary { |
| 77 | 68 | readonly kind: ServerTraceDiagnosticsErrorKind; |
| 78 | 69 | readonly message: string; |
| ... | ... | @@ -173,44 +164,50 @@ function isNotFoundError(error: PlatformError.PlatformError): boolean { |
| 173 | 164 | return error.reason._tag === "NotFound"; |
| 174 | 165 | } |
| 175 | 166 | |
| 176 | | function insertBoundedSlowestSpan( |
| 177 | | slowestSpans: ServerTraceDiagnosticsSpanOccurrence[], |
| 178 | | span: ServerTraceDiagnosticsSpanOccurrence, |
| 167 | /** |
| 168 | * Adds `item` to `items`, which stays sorted by `order` and holds at most |
| 169 | * `limit` entries. Same result as a stable sort and slice over every item, but |
| 170 | * memory stays bounded however many items stream in. |
| 171 | */ |
| 172 | function insertBounded<A>( |
| 173 | items: A[], |
| 174 | item: A, |
| 175 | limit: number, |
| 176 | order: (left: A, right: A) => number, |
| 179 | 177 | ): void { |
| 180 | | if ( |
| 181 | | slowestSpans.length >= TOP_LIMIT && |
| 182 | | span.durationMs <= slowestSpans[slowestSpans.length - 1]!.durationMs |
| 183 | | ) { |
| 178 | if (items.length >= limit && order(item, items[items.length - 1]!) >= 0) { |
| 184 | 179 | return; |
| 185 | 180 | } |
| 186 | 181 | |
| 187 | | slowestSpans.push(span); |
| 188 | | slowestSpans.sort((left, right) => right.durationMs - left.durationMs); |
| 189 | | if (slowestSpans.length > TOP_LIMIT) { |
| 190 | | slowestSpans.length = TOP_LIMIT; |
| 182 | items.push(item); |
| 183 | items.sort(order); |
| 184 | if (items.length > limit) { |
| 185 | items.length = limit; |
| 191 | 186 | } |
| 192 | 187 | } |
| 193 | 188 | |
| 194 | | export function aggregateTraceDiagnostics( |
| 195 | | input: TraceDiagnosticsInput, |
| 196 | | ): ServerTraceDiagnosticsResult { |
| 197 | | const readAt = input.readAt; |
| 198 | | const slowSpanThresholdMs = input.slowSpanThresholdMs ?? DEFAULT_SLOW_SPAN_THRESHOLD_MS; |
| 199 | | const scannedFilePaths = input.scannedFilePaths ?? input.files.map((file) => file.path); |
| 200 | | if (input.files.length === 0) { |
| 201 | | return makeEmptyDiagnostics({ |
| 202 | | traceFilePath: input.traceFilePath, |
| 203 | | scannedFilePaths, |
| 204 | | readAt, |
| 205 | | slowSpanThresholdMs, |
| 206 | | error: input.error ?? { |
| 207 | | kind: "trace-file-not-found", |
| 208 | | message: "No local trace files were found.", |
| 209 | | }, |
| 210 | | ...(input.partialFailure ? { partialFailure: true } : {}), |
| 211 | | }); |
| 212 | | } |
| 213 | | |
| 189 | const slowestFirst = ( |
| 190 | left: ServerTraceDiagnosticsSpanOccurrence, |
| 191 | right: ServerTraceDiagnosticsSpanOccurrence, |
| 192 | ) => right.durationMs - left.durationMs; |
| 193 | |
| 194 | const latestEndedFirst = ( |
| 195 | left: ServerTraceDiagnosticsRecentFailure, |
| 196 | right: ServerTraceDiagnosticsRecentFailure, |
| 197 | ) => DateTime.toEpochMillis(right.endedAt) - DateTime.toEpochMillis(left.endedAt); |
| 198 | |
| 199 | const latestSeenFirst = ( |
| 200 | left: ServerTraceDiagnosticsLogEvent, |
| 201 | right: ServerTraceDiagnosticsLogEvent, |
| 202 | ) => DateTime.toEpochMillis(right.seenAt) - DateTime.toEpochMillis(left.seenAt); |
| 203 | |
| 204 | /** |
| 205 | * Folds trace NDJSON into diagnostics. Call `addLine` once per line as the |
| 206 | * rotated files stream in, then `finish` for the result. |
| 207 | */ |
| 208 | export function makeTraceDiagnosticsAggregator( |
| 209 | slowSpanThresholdMs = DEFAULT_SLOW_SPAN_THRESHOLD_MS, |
| 210 | ) { |
| 214 | 211 | let parseErrorCount = 0; |
| 215 | 212 | let recordCount = 0; |
| 216 | 213 | let failureCount = 0; |
| ... | ... | @@ -229,182 +226,184 @@ export function aggregateTraceDiagnostics( |
| 229 | 226 | const latestWarningAndErrorLogs: ServerTraceDiagnosticsLogEvent[] = []; |
| 230 | 227 | const logLevelCounts: Record<string, number> = {}; |
| 231 | 228 | |
| 232 | | for (const file of input.files) { |
| 233 | | const lines = file.text.split(/\r?\n/); |
| 234 | | for (const line of lines) { |
| 235 | | if (line.trim().length === 0) continue; |
| 236 | | |
| 237 | | let parsed: unknown; |
| 238 | | try { |
| 239 | | parsed = JSON.parse(line); |
| 240 | | } catch { |
| 241 | | parseErrorCount += 1; |
| 242 | | continue; |
| 243 | | } |
| 229 | const addLine = (line: string) => { |
| 230 | if (line.trim().length === 0) return; |
| 244 | 231 | |
| 245 | | if (!isRecordObject(parsed)) { |
| 246 | | parseErrorCount += 1; |
| 247 | | continue; |
| 248 | | } |
| 232 | let parsed: unknown; |
| 233 | try { |
| 234 | parsed = JSON.parse(line); |
| 235 | } catch { |
| 236 | parseErrorCount += 1; |
| 237 | return; |
| 238 | } |
| 249 | 239 | |
| 250 | | const name = toStringValue(parsed.name); |
| 251 | | const traceId = toStringValue(parsed.traceId); |
| 252 | | const spanId = toStringValue(parsed.spanId); |
| 253 | | const durationMs = toNumberValue(parsed.durationMs); |
| 254 | | const endedAt = unixNanoToDateTime(parsed.endTimeUnixNano); |
| 255 | | const startedAt = unixNanoToDateTime(parsed.startTimeUnixNano); |
| 240 | if (!isRecordObject(parsed)) { |
| 241 | parseErrorCount += 1; |
| 242 | return; |
| 243 | } |
| 256 | 244 | |
| 257 | | if (!name || !traceId || !spanId || durationMs === null || !endedAt) { |
| 258 | | parseErrorCount += 1; |
| 259 | | continue; |
| 260 | | } |
| 245 | const name = toStringValue(parsed.name); |
| 246 | const traceId = toStringValue(parsed.traceId); |
| 247 | const spanId = toStringValue(parsed.spanId); |
| 248 | const durationMs = toNumberValue(parsed.durationMs); |
| 249 | const endedAt = unixNanoToDateTime(parsed.endTimeUnixNano); |
| 250 | const startedAt = unixNanoToDateTime(parsed.startTimeUnixNano); |
| 261 | 251 | |
| 262 | | recordCount += 1; |
| 263 | | firstSpanAt = |
| 264 | | startedAt && (firstSpanAt === null || DateTime.isLessThan(startedAt, firstSpanAt)) |
| 265 | | ? startedAt |
| 266 | | : firstSpanAt; |
| 267 | | lastSpanAt = |
| 268 | | lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt; |
| 269 | | |
| 270 | | const exitTag = readExitTag(parsed.exit); |
| 271 | | const isFailure = exitTag === "Failure"; |
| 272 | | const isInterrupted = exitTag === "Interrupted"; |
| 273 | | if (isFailure) failureCount += 1; |
| 274 | | if (isInterrupted) interruptionCount += 1; |
| 275 | | |
| 276 | | const spanSummary = spansByName.get(name) ?? { |
| 277 | | count: 0, |
| 278 | | failureCount: 0, |
| 279 | | totalDurationMs: 0, |
| 280 | | maxDurationMs: 0, |
| 281 | | }; |
| 282 | | spanSummary.count += 1; |
| 283 | | spanSummary.totalDurationMs += durationMs; |
| 284 | | spanSummary.maxDurationMs = Math.max(spanSummary.maxDurationMs, durationMs); |
| 285 | | if (isFailure) spanSummary.failureCount += 1; |
| 286 | | spansByName.set(name, spanSummary); |
| 287 | | |
| 288 | | const spanItem = { name, durationMs, endedAt, traceId, spanId }; |
| 289 | | if (durationMs >= slowSpanThresholdMs) { |
| 290 | | slowSpanCount += 1; |
| 291 | | } |
| 292 | | insertBoundedSlowestSpan(slowestSpans, spanItem); |
| 293 | | |
| 294 | | if (isFailure) { |
| 295 | | const cause = readExitCause(parsed.exit); |
| 296 | | latestFailures.push({ ...spanItem, cause }); |
| 297 | | |
| 298 | | const failureKey = `${name}\0${cause}`; |
| 299 | | const existing = failuresByKey.get(failureKey); |
| 300 | | const isLatestFailure = !existing || DateTime.isGreaterThan(endedAt, existing.lastSeenAt); |
| 301 | | failuresByKey.set(failureKey, { |
| 302 | | name, |
| 303 | | cause, |
| 304 | | count: (existing?.count ?? 0) + 1, |
| 305 | | lastSeenAt: isLatestFailure ? endedAt : existing!.lastSeenAt, |
| 306 | | traceId: isLatestFailure ? traceId : existing!.traceId, |
| 307 | | spanId: isLatestFailure ? spanId : existing!.spanId, |
| 308 | | }); |
| 309 | | } |
| 252 | if (!name || !traceId || !spanId || durationMs === null || !endedAt) { |
| 253 | parseErrorCount += 1; |
| 254 | return; |
| 255 | } |
| 310 | 256 | |
| 311 | | if (Array.isArray(parsed.events)) { |
| 312 | | for (const rawEvent of parsed.events) { |
| 313 | | if (!isTraceEvent(rawEvent)) continue; |
| 314 | | const attributes = readEventAttributes(rawEvent); |
| 315 | | const level = toStringValue(attributes["effect.logLevel"]); |
| 316 | | if (!level) continue; |
| 317 | | |
| 318 | | logLevelCounts[level] = (logLevelCounts[level] ?? 0) + 1; |
| 319 | | const normalizedLevel = level.toLowerCase(); |
| 320 | | if ( |
| 321 | | normalizedLevel !== "warning" && |
| 322 | | normalizedLevel !== "warn" && |
| 323 | | normalizedLevel !== "error" && |
| 324 | | normalizedLevel !== "fatal" |
| 325 | | ) { |
| 326 | | continue; |
| 327 | | } |
| 328 | | |
| 329 | | const seenAt = unixNanoToDateTime(rawEvent.timeUnixNano) ?? endedAt; |
| 330 | | const message = toStringValue(rawEvent.name)?.trim() ?? "Log event"; |
| 331 | | latestWarningAndErrorLogs.push({ |
| 332 | | spanName: name, |
| 333 | | level, |
| 334 | | message, |
| 335 | | seenAt, |
| 336 | | traceId, |
| 337 | | spanId, |
| 338 | | }); |
| 257 | recordCount += 1; |
| 258 | firstSpanAt = |
| 259 | startedAt && (firstSpanAt === null || DateTime.isLessThan(startedAt, firstSpanAt)) |
| 260 | ? startedAt |
| 261 | : firstSpanAt; |
| 262 | lastSpanAt = |
| 263 | lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt; |
| 264 | |
| 265 | const exitTag = readExitTag(parsed.exit); |
| 266 | const isFailure = exitTag === "Failure"; |
| 267 | const isInterrupted = exitTag === "Interrupted"; |
| 268 | if (isFailure) failureCount += 1; |
| 269 | if (isInterrupted) interruptionCount += 1; |
| 270 | |
| 271 | const spanSummary = spansByName.get(name) ?? { |
| 272 | count: 0, |
| 273 | failureCount: 0, |
| 274 | totalDurationMs: 0, |
| 275 | maxDurationMs: 0, |
| 276 | }; |
| 277 | spanSummary.count += 1; |
| 278 | spanSummary.totalDurationMs += durationMs; |
| 279 | spanSummary.maxDurationMs = Math.max(spanSummary.maxDurationMs, durationMs); |
| 280 | if (isFailure) spanSummary.failureCount += 1; |
| 281 | spansByName.set(name, spanSummary); |
| 282 | |
| 283 | const spanItem = { name, durationMs, endedAt, traceId, spanId }; |
| 284 | if (durationMs >= slowSpanThresholdMs) { |
| 285 | slowSpanCount += 1; |
| 286 | } |
| 287 | insertBounded(slowestSpans, spanItem, TOP_LIMIT, slowestFirst); |
| 288 | |
| 289 | if (isFailure) { |
| 290 | const cause = readExitCause(parsed.exit); |
| 291 | insertBounded(latestFailures, { ...spanItem, cause }, RECENT_LIMIT, latestEndedFirst); |
| 292 | |
| 293 | const failureKey = `${name}\0${cause}`; |
| 294 | const existing = failuresByKey.get(failureKey); |
| 295 | const isLatestFailure = !existing || DateTime.isGreaterThan(endedAt, existing.lastSeenAt); |
| 296 | failuresByKey.set(failureKey, { |
| 297 | name, |
| 298 | cause, |
| 299 | count: (existing?.count ?? 0) + 1, |
| 300 | lastSeenAt: isLatestFailure ? endedAt : existing!.lastSeenAt, |
| 301 | traceId: isLatestFailure ? traceId : existing!.traceId, |
| 302 | spanId: isLatestFailure ? spanId : existing!.spanId, |
| 303 | }); |
| 304 | } |
| 305 | |
| 306 | if (Array.isArray(parsed.events)) { |
| 307 | for (const rawEvent of parsed.events) { |
| 308 | if (!isTraceEvent(rawEvent)) continue; |
| 309 | const attributes = readEventAttributes(rawEvent); |
| 310 | const level = toStringValue(attributes["effect.logLevel"]); |
| 311 | if (!level) continue; |
| 312 | |
| 313 | logLevelCounts[level] = (logLevelCounts[level] ?? 0) + 1; |
| 314 | const normalizedLevel = level.toLowerCase(); |
| 315 | if ( |
| 316 | normalizedLevel !== "warning" && |
| 317 | normalizedLevel !== "warn" && |
| 318 | normalizedLevel !== "error" && |
| 319 | normalizedLevel !== "fatal" |
| 320 | ) { |
| 321 | continue; |
| 339 | 322 | } |
| 323 | |
| 324 | const seenAt = unixNanoToDateTime(rawEvent.timeUnixNano) ?? endedAt; |
| 325 | const message = toStringValue(rawEvent.name)?.trim() ?? "Log event"; |
| 326 | insertBounded( |
| 327 | latestWarningAndErrorLogs, |
| 328 | { spanName: name, level, message, seenAt, traceId, spanId }, |
| 329 | RECENT_LIMIT, |
| 330 | latestSeenFirst, |
| 331 | ); |
| 340 | 332 | } |
| 341 | 333 | } |
| 342 | | } |
| 343 | | |
| 344 | | const topSpansByCount: ServerTraceDiagnosticsSpanSummary[] = [...spansByName.entries()] |
| 345 | | .map(([name, span]) => ({ |
| 346 | | name, |
| 347 | | count: span.count, |
| 348 | | failureCount: span.failureCount, |
| 349 | | totalDurationMs: span.totalDurationMs, |
| 350 | | averageDurationMs: span.count > 0 ? span.totalDurationMs / span.count : 0, |
| 351 | | maxDurationMs: span.maxDurationMs, |
| 352 | | })) |
| 353 | | .toSorted((left, right) => right.count - left.count || right.maxDurationMs - left.maxDurationMs) |
| 354 | | .slice(0, TOP_LIMIT); |
| 334 | }; |
| 355 | 335 | |
| 356 | | return { |
| 357 | | traceFilePath: input.traceFilePath, |
| 358 | | scannedFilePaths, |
| 359 | | readAt, |
| 360 | | recordCount, |
| 361 | | parseErrorCount, |
| 362 | | firstSpanAt: Option.fromNullishOr(firstSpanAt), |
| 363 | | lastSpanAt: Option.fromNullishOr(lastSpanAt), |
| 364 | | failureCount, |
| 365 | | interruptionCount, |
| 366 | | slowSpanThresholdMs, |
| 367 | | slowSpanCount, |
| 368 | | logLevelCounts, |
| 369 | | topSpansByCount, |
| 370 | | slowestSpans, |
| 371 | | commonFailures: [...failuresByKey.values()] |
| 372 | | .toSorted( |
| 373 | | (left, right) => |
| 374 | | right.count - left.count || |
| 375 | | DateTime.toEpochMillis(right.lastSeenAt) - DateTime.toEpochMillis(left.lastSeenAt), |
| 376 | | ) |
| 377 | | .slice(0, TOP_LIMIT), |
| 378 | | latestFailures: latestFailures |
| 336 | const finish = (input: { |
| 337 | readonly traceFilePath: string; |
| 338 | readonly scannedFilePaths: ReadonlyArray<string>; |
| 339 | readonly readAt: DateTime.Utc; |
| 340 | readonly error?: TraceDiagnosticsErrorSummary; |
| 341 | readonly partialFailure?: boolean; |
| 342 | }): ServerTraceDiagnosticsResult => { |
| 343 | const topSpansByCount: ServerTraceDiagnosticsSpanSummary[] = [...spansByName.entries()] |
| 344 | .map(([name, span]) => ({ |
| 345 | name, |
| 346 | count: span.count, |
| 347 | failureCount: span.failureCount, |
| 348 | totalDurationMs: span.totalDurationMs, |
| 349 | averageDurationMs: span.count > 0 ? span.totalDurationMs / span.count : 0, |
| 350 | maxDurationMs: span.maxDurationMs, |
| 351 | })) |
| 379 | 352 | .toSorted( |
| 380 | | (left, right) => |
| 381 | | DateTime.toEpochMillis(right.endedAt) - DateTime.toEpochMillis(left.endedAt), |
| 353 | (left, right) => right.count - left.count || right.maxDurationMs - left.maxDurationMs, |
| 382 | 354 | ) |
| 383 | | .slice(0, RECENT_LIMIT), |
| 384 | | latestWarningAndErrorLogs: latestWarningAndErrorLogs |
| 385 | | .toSorted( |
| 386 | | (left, right) => DateTime.toEpochMillis(right.seenAt) - DateTime.toEpochMillis(left.seenAt), |
| 387 | | ) |
| 388 | | .slice(0, RECENT_LIMIT), |
| 389 | | partialFailure: input.partialFailure ? Option.some(true) : Option.none(), |
| 390 | | error: Option.fromNullishOr(input.error), |
| 355 | .slice(0, TOP_LIMIT); |
| 356 | |
| 357 | return { |
| 358 | traceFilePath: input.traceFilePath, |
| 359 | scannedFilePaths: input.scannedFilePaths, |
| 360 | readAt: input.readAt, |
| 361 | recordCount, |
| 362 | parseErrorCount, |
| 363 | firstSpanAt: Option.fromNullishOr(firstSpanAt), |
| 364 | lastSpanAt: Option.fromNullishOr(lastSpanAt), |
| 365 | failureCount, |
| 366 | interruptionCount, |
| 367 | slowSpanThresholdMs, |
| 368 | slowSpanCount, |
| 369 | logLevelCounts, |
| 370 | topSpansByCount, |
| 371 | slowestSpans, |
| 372 | commonFailures: [...failuresByKey.values()] |
| 373 | .toSorted( |
| 374 | (left, right) => |
| 375 | right.count - left.count || |
| 376 | DateTime.toEpochMillis(right.lastSeenAt) - DateTime.toEpochMillis(left.lastSeenAt), |
| 377 | ) |
| 378 | .slice(0, TOP_LIMIT), |
| 379 | latestFailures, |
| 380 | latestWarningAndErrorLogs, |
| 381 | partialFailure: input.partialFailure ? Option.some(true) : Option.none(), |
| 382 | error: Option.fromNullishOr(input.error), |
| 383 | }; |
| 391 | 384 | }; |
| 392 | | } |
| 393 | 385 | |
| 394 | | type TraceFileReadResult = |
| 395 | | | { readonly _tag: "Loaded"; readonly path: string; readonly text: string } |
| 396 | | | { readonly _tag: "Missing"; readonly path: string }; |
| 386 | return { addLine, finish }; |
| 387 | } |
| 397 | 388 | |
| 398 | | function readTraceFile( |
| 389 | /** |
| 390 | * Feeds each line of one trace file to `onLine`, streaming so only one chunk of |
| 391 | * text is in memory at a time. Succeeds with false when the file does not exist. |
| 392 | */ |
| 393 | export function streamTraceFileLines( |
| 399 | 394 | fileSystem: FileSystem.FileSystem, |
| 400 | 395 | path: string, |
| 401 | | ): Effect.Effect<TraceFileReadResult, TraceFileReadError> { |
| 402 | | return fileSystem.readFileString(path).pipe( |
| 403 | | Effect.map((text): TraceFileReadResult => ({ _tag: "Loaded", path, text })), |
| 396 | onLine: (line: string) => void, |
| 397 | ): Effect.Effect<boolean, TraceFileReadError> { |
| 398 | return fileSystem.stream(path).pipe( |
| 399 | Stream.decodeText, |
| 400 | Stream.splitLines, |
| 401 | Stream.runForEachArray((lines) => Effect.sync(() => lines.forEach(onLine))), |
| 402 | Effect.as(true), |
| 404 | 403 | Effect.catchTags({ |
| 405 | 404 | PlatformError: (cause) => |
| 406 | 405 | isNotFoundError(cause) |
| 407 | | ? Effect.succeed<TraceFileReadResult>({ _tag: "Missing", path }) |
| 406 | ? Effect.succeed(false) |
| 408 | 407 | : Effect.fail( |
| 409 | 408 | new TraceFileReadError({ |
| 410 | 409 | traceFilePath: path, |
| ... | ... | @@ -425,10 +424,11 @@ export const make = Effect.gen(function* () { |
| 425 | 424 | const readAt = options.readAt ?? (yield* DateTime.now); |
| 426 | 425 | const slowSpanThresholdMs = options.slowSpanThresholdMs ?? DEFAULT_SLOW_SPAN_THRESHOLD_MS; |
| 427 | 426 | const paths = toRotatedTracePaths(options.traceFilePath, options.maxFiles); |
| 427 | const aggregator = makeTraceDiagnosticsAggregator(slowSpanThresholdMs); |
| 428 | 428 | const results = yield* Effect.forEach( |
| 429 | 429 | paths, |
| 430 | 430 | (path) => |
| 431 | | readTraceFile(fileSystem, path).pipe( |
| 431 | streamTraceFileLines(fileSystem, path, aggregator.addLine).pipe( |
| 432 | 432 | Effect.tapError((cause) => |
| 433 | 433 | Effect.logWarning("Failed to read local trace file.").pipe( |
| 434 | 434 | Effect.annotateLogs({ |
| ... | ... | @@ -440,15 +440,10 @@ export const make = Effect.gen(function* () { |
| 440 | 440 | ), |
| 441 | 441 | Effect.result, |
| 442 | 442 | ), |
| 443 | | { |
| 444 | | concurrency: 1, |
| 445 | | }, |
| 446 | | ); |
| 447 | | const files = results.flatMap((result) => |
| 448 | | Result.isSuccess(result) && result.success._tag === "Loaded" |
| 449 | | ? [{ path: result.success.path, text: result.success.text }] |
| 450 | | : [], |
| 443 | // Every file feeds one aggregator, so read them one at a time, oldest first. |
| 444 | { concurrency: 1 }, |
| 451 | 445 | ); |
| 446 | const foundFile = results.some((result) => Result.isSuccess(result) && result.success); |
| 452 | 447 | const readFailure = results.find(Result.isFailure); |
| 453 | 448 | const readFailureError = readFailure |
| 454 | 449 | ? ({ |
| ... | ... | @@ -457,7 +452,7 @@ export const make = Effect.gen(function* () { |
| 457 | 452 | } satisfies TraceDiagnosticsErrorSummary) |
| 458 | 453 | : undefined; |
| 459 | 454 | |
| 460 | | if (files.length === 0) { |
| 455 | if (!foundFile) { |
| 461 | 456 | return makeEmptyDiagnostics({ |
| 462 | 457 | traceFilePath: options.traceFilePath, |
| 463 | 458 | scannedFilePaths: paths, |
| ... | ... | @@ -472,12 +467,10 @@ export const make = Effect.gen(function* () { |
| 472 | 467 | }); |
| 473 | 468 | } |
| 474 | 469 | |
| 475 | | return aggregateTraceDiagnostics({ |
| 470 | return aggregator.finish({ |
| 476 | 471 | traceFilePath: options.traceFilePath, |
| 477 | | files, |
| 478 | 472 | scannedFilePaths: paths, |
| 479 | 473 | readAt, |
| 480 | | slowSpanThresholdMs, |
| 481 | 474 | ...(readFailureError ? { partialFailure: true, error: readFailureError } : {}), |
| 482 | 475 | }); |
| 483 | 476 | }, |