Skip to content

Commit 9ba2a17

Browse files
committed
fix(logs): keep an output carrying child spans a record when compacting it
1 parent b2ecdb3 commit 9ba2a17

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/sim/lib/execution/payloads/serializer.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,18 @@ describe('compacting span trees', () => {
396396
expectSpanTree(compacted?.childTraceSpans)
397397
})
398398

399+
it('keeps the output a record when its other fields together exceed the threshold', async () => {
400+
const compacted = await compactBlockOutput(
401+
{ first: 'a'.repeat(600), second: 'b'.repeat(600), childTraceSpans: childWorkflowSpans() },
402+
options
403+
)
404+
405+
expect(isLargeValueRef(compacted)).toBe(false)
406+
expect(compacted.first).toBe('a'.repeat(600))
407+
expect(compacted.second).toBe('b'.repeat(600))
408+
expectSpanTree(compacted.childTraceSpans)
409+
})
410+
399411
it('keeps a nested child workflow span tree shaped as a tree', async () => {
400412
const nestedWorkflowSpan: TraceSpan = {
401413
id: 'nested-workflow',

‎apps/sim/lib/execution/payloads/serializer.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ async function compactTraceSpan(
295295
/**
296296
* Compacts a block output, keeping any `childTraceSpans` shaped as a span tree
297297
* (see {@link compactTraceSpanTree}). Everything else compacts as a normal
298-
* execution payload.
298+
* execution payload, except that an output carrying spans keeps its root so
299+
* the spans stay attached to it; its fields still spill individually.
299300
*/
300301
export async function compactBlockOutput<T>(
301302
output: T,
@@ -306,12 +307,9 @@ export async function compactBlockOutput<T>(
306307
}
307308
const { childTraceSpans, ...rest } = output
308309
const [compactedRest, compactedSpans] = await Promise.all([
309-
compactExecutionPayload(rest, options),
310+
compactExecutionPayload(rest, { ...options, preserveRoot: true }),
310311
compactTraceSpanTree(childTraceSpans, options),
311312
])
312-
if (!isRecordLike(compactedRest)) {
313-
return compactedRest as T
314-
}
315313
return { ...compactedRest, childTraceSpans: compactedSpans } as T
316314
}
317315

0 commit comments

Comments
 (0)