Skip to content

Commit 97c146a

Browse files
committed
fix(logs): truncate strings in tracespans crashing insertion
1 parent 094f87f commit 97c146a

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

apps/sim/lib/core/utils/display-filters.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Maximum length for string values in display output
3+
* Prevents database storage issues with very large trace spans
4+
*/
5+
const MAX_STRING_LENGTH = 10000
6+
7+
/**
8+
* Truncates a string if it exceeds the maximum length
9+
*/
10+
function truncateString(value: string, maxLength = MAX_STRING_LENGTH): string {
11+
if (value.length <= maxLength) {
12+
return value
13+
}
14+
return `${value.substring(0, maxLength)}... [truncated ${value.length - maxLength} chars]`
15+
}
16+
117
/**
218
* Type guard to check if an object is a UserFile
319
*/
@@ -48,16 +64,28 @@ const DISPLAY_FILTERS = [
4864
/**
4965
* Generic helper to filter internal/technical fields from data for cleaner display in logs and console.
5066
* Applies all registered filters recursively to the data structure.
67+
* Also truncates long strings to prevent database storage issues.
5168
*
5269
* To add a new filter:
5370
* 1. Create a filter function that checks and transforms a specific data type
5471
* 2. Add it to the DISPLAY_FILTERS array above
5572
*
5673
* @param data - Data to filter (objects, arrays, primitives)
57-
* @returns Filtered data with internal fields removed
74+
* @returns Filtered data with internal fields removed and long strings truncated
5875
*/
5976
export function filterForDisplay(data: any): any {
60-
if (!data || typeof data !== 'object') {
77+
// Handle null/undefined
78+
if (data === null || data === undefined) {
79+
return data
80+
}
81+
82+
// Truncate long strings
83+
if (typeof data === 'string') {
84+
return truncateString(data)
85+
}
86+
87+
// Return primitives as-is
88+
if (typeof data !== 'object') {
6189
return data
6290
}
6391

0 commit comments

Comments
 (0)