|
5 | 5 | } from "@trigger.dev/core/v3/schemas"; |
6 | 6 | import type { CursorPageResponse } from "@trigger.dev/core/v3/zodfetch"; |
7 | 7 |
|
| 8 | +const MAX_TRACE_LINES = 1000; |
| 9 | + |
8 | 10 | export function formatRun(run: RetrieveRunResponse): string { |
9 | 11 | const lines: string[] = []; |
10 | 12 |
|
@@ -177,16 +179,25 @@ export function formatRunTrace(trace: RetrieveRunTraceResponseBody["trace"]): st |
177 | 179 | lines.push(""); |
178 | 180 |
|
179 | 181 | // Format the root span and its children recursively |
180 | | - formatSpan(trace.rootSpan, lines, 0); |
| 182 | + const reachedMaxLines = formatSpan(trace.rootSpan, lines, 0, MAX_TRACE_LINES); |
| 183 | + |
| 184 | + if (reachedMaxLines) { |
| 185 | + lines.push(`(truncated logs to ${MAX_TRACE_LINES} lines)`); |
| 186 | + } |
181 | 187 |
|
182 | 188 | return lines.join("\n"); |
183 | 189 | } |
184 | 190 |
|
185 | 191 | function formatSpan( |
186 | 192 | span: RetrieveRunTraceResponseBody["trace"]["rootSpan"], |
187 | 193 | lines: string[], |
188 | | - depth: number |
189 | | -): void { |
| 194 | + depth: number, |
| 195 | + maxLines: number |
| 196 | +): boolean { |
| 197 | + if (lines.length >= maxLines) { |
| 198 | + return true; |
| 199 | + } |
| 200 | + |
190 | 201 | const indent = " ".repeat(depth); |
191 | 202 | const prefix = depth === 0 ? "└─" : "├─"; |
192 | 203 |
|
@@ -263,14 +274,20 @@ function formatSpan( |
263 | 274 |
|
264 | 275 | // Recursively format children |
265 | 276 | if (span.children) { |
266 | | - span.children.forEach((child, index) => { |
267 | | - formatSpan(child, lines, depth + 1); |
| 277 | + const reachedMaxLines = span.children.some((child, index) => { |
| 278 | + const reachedMaxLines = formatSpan(child, lines, depth + 1, maxLines); |
268 | 279 | // Add spacing between sibling spans (except for the last one) |
269 | | - if (index < span.children.length - 1) { |
| 280 | + if (index < span.children.length - 1 && !reachedMaxLines) { |
270 | 281 | lines.push(""); |
271 | 282 | } |
| 283 | + |
| 284 | + return reachedMaxLines; |
272 | 285 | }); |
| 286 | + |
| 287 | + return reachedMaxLines; |
273 | 288 | } |
| 289 | + |
| 290 | + return false; |
274 | 291 | } |
275 | 292 |
|
276 | 293 | function getStatusIndicator( |
|
0 commit comments