feat(logs): add inline JSON syntax highlighting for log attributes#111730
Conversation
29aea9b to
2884591
Compare
|
not sure if it would help but we do have the https://npmx.dev/package/jsonrepair package |
2884591 to
e606674
Compare
|
Oh cool good to know! I don't think we can use that here, since we don't want to modify the log strings. The intent is just to syntax highlight any valid JSON if it's there. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| if (matchEnd === -1) { | ||
| segments.push({type: 'text', value: text.slice(nextStart)}); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Unmatched bracket aborts scanning, skipping later valid JSON
Medium Severity
When findMatchingBracket returns -1 (unmatched bracket), the scanner pushes all remaining text as a single text segment and breaks out of the loop. This causes any valid JSON appearing later in the string to be silently missed. For example, parse [ error {"status": 500} would treat everything from [ onward as plain text because [ has no matching ], even though {"status": 500} is valid extractable JSON. The JSON.parse failure path correctly advances just one character and continues scanning — the matchEnd === -1 path needs the same treatment instead of giving up on the rest of the input.
There was a problem hiding this comment.
I think this is fine. It's an edge case and syntax highlighting is not a critical UI feature.
| </span> | ||
| ))} | ||
| </Fragment> | ||
| ))} |
There was a problem hiding this comment.
Multiline JSON loses newlines during Prism rendering
Low Severity
JsonSegment renders each Prism line inside a Fragment with no newline character between lines. usePrismTokens splits on \n and consumes the newline characters during tokenization (in splitTokenContentByLine). So when a JSON segment contains actual newlines (e.g. {\n "key": "value"\n}), the rendered output collapses them — displaying { "key": "value"} instead. The white-space: pre-wrap on InlineCode doesn't help because the \n characters are already gone. Other callers of usePrismTokens typically render a line break element between lines.
There was a problem hiding this comment.
I'll look into this on Monday.
When a log attribute value contains embedded JSON within surrounding
text (e.g. "This is my JSON: {"key": "value"}"), the JSON portions
are now syntax-highlighted inline using Prism tokenization while the
non-JSON text renders as-is.
This builds on the existing full-JSON pretty-printing from LOGS-400.
The JSON extraction logic is in a standalone, dependency-free utility
(extractJsonFromText) with string-aware bracket matching that correctly
handles braces inside quoted strings and escape sequences.
Refs LINEAR-LOGS-636
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Made-with: Cursor
e606674 to
32270cd
Compare
…111730) Add inline syntax highlighting for JSON embedded within log attribute values in the expanded attribute tree view. Previously (LOGS-400), only attribute values that were *entirely* valid JSON got pretty-printed with `StructuredEventData`. Values like `This is my JSON: {"it": "would be", "nice": ["to", "highlight"], "this": true}` rendered as plain text. Now, the JSON portion gets Prism-based syntax colorizing inline — keys, strings, numbers, booleans, and punctuation each get their own color — without adding newlines or changing the layout. <img width="838" height="245" alt="Screenshot of a log with a myData field showing syntax-highlighted JSON object" src="https://github.com/user-attachments/assets/7b78bb01-5be9-494e-9010-2008fde3b59c" /> The JSON extraction logic lives in a standalone utility (`extractJsonFromText`) that uses string-aware bracket matching to correctly handle braces inside quoted strings and escape sequences — unlike existing npm packages (`balanced-match`, `extract-json-from-string`) which break on these cases. I intentionally set this up so that it acts like a standalone importable utility. It'd be nifty if we could publish this as its own package... Fixes LOGS-636 Made with [Cursor](https://cursor.com) Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
…111730) Add inline syntax highlighting for JSON embedded within log attribute values in the expanded attribute tree view. Previously (LOGS-400), only attribute values that were *entirely* valid JSON got pretty-printed with `StructuredEventData`. Values like `This is my JSON: {"it": "would be", "nice": ["to", "highlight"], "this": true}` rendered as plain text. Now, the JSON portion gets Prism-based syntax colorizing inline — keys, strings, numbers, booleans, and punctuation each get their own color — without adding newlines or changing the layout. <img width="838" height="245" alt="Screenshot of a log with a myData field showing syntax-highlighted JSON object" src="https://github.com/user-attachments/assets/7b78bb01-5be9-494e-9010-2008fde3b59c" /> The JSON extraction logic lives in a standalone utility (`extractJsonFromText`) that uses string-aware bracket matching to correctly handle braces inside quoted strings and escape sequences — unlike existing npm packages (`balanced-match`, `extract-json-from-string`) which break on these cases. I intentionally set this up so that it acts like a standalone importable utility. It'd be nifty if we could publish this as its own package... Fixes LOGS-636 Made with [Cursor](https://cursor.com) Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>



Add inline syntax highlighting for JSON embedded within log attribute values in the expanded attribute tree view.
Previously (LOGS-400), only attribute values that were entirely valid JSON got pretty-printed with
StructuredEventData. Values likeThis is my JSON: {"it": "would be", "nice": ["to", "highlight"], "this": true}rendered as plain text. Now, the JSON portion gets Prism-based syntax colorizing inline — keys, strings, numbers, booleans, and punctuation each get their own color — without adding newlines or changing the layout.The JSON extraction logic lives in a standalone utility (
extractJsonFromText) that uses string-aware bracket matching to correctly handle braces inside quoted strings and escape sequences — unlike existing npm packages (balanced-match,extract-json-from-string) which break on these cases. I intentionally set this up so that it acts like a standalone importable utility. It'd be nifty if we could publish this as its own package...Fixes LOGS-636
Made with Cursor