Skip to content

[Backtracing] Add JSON backtrace output #79009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 27, 2025

Conversation

al45tair
Copy link
Contributor

Add an option to use JSON for the crash log output; this makes it easy to ingest crash logs using tools like Splunk or Elastic, which is extremely useful in server environments.

rdar://121430255

@al45tair al45tair requested review from mikeash and a team as code owners January 29, 2025 12:48
@al45tair al45tair changed the title Add JSON backtrace output [Backtracing] Add JSON backtrace output Jan 29, 2025
@al45tair
Copy link
Contributor Author

(The very first commit is being dealt with separately in #79007. But we need it for the JSON changes, because when in JSON mode we change the filename for the former feature.)

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair al45tair requested review from czechboy0 and weissi January 29, 2025 12:51
Copy link
Member

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - caught one typo, and I have one question: should the JSON output be minified (at least have an option to do so?).

Some logging systems require that each JSON object is completely on a single line, so this prettified version might not work with them.

Even if you change to minified JSON, anyone at desk can run this through jq for reading, if needed.

@al45tair
Copy link
Contributor Author

Looks great - caught one typo, and I have one question: should the JSON output be minified (at least have an option to do so?).

Some logging systems require that each JSON object is completely on a single line, so this prettified version might not work with them.

Even if you change to minified JSON, anyone at desk can run this through jq for reading, if needed.

The JSON isn't strictly minified, since there is some whitespace, but there are (by design) no newlines. The tests are slightly misleading perhaps because they run the JSON through a JSON linter/prettifier, which means everything ends up on separate lines.

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few suggestions, nothing I'd insist on strongly.

While reading the JSON output format, it occurs to me that it doesn't have the VM region info that we get in Mac crash logs. That can be really useful sometimes and it might be nice to add it here. That doesn't belong in this PR, but I thought I'd put that out there.

@al45tair
Copy link
Contributor Author

While reading the JSON output format, it occurs to me that it doesn't have the VM region info that we get in Mac crash logs. That can be really useful sometimes and it might be nice to add it here.

Yeah, that's not a bad idea. Not in this PR though, as you say.

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

al45tair and others added 10 commits February 26, 2025 14:12
Also made it so the `sanitize` option causes the crash logs to not
include memory dumps.

Fixes swiftlang#71057
rdar://121430255
A couple of commas were in the wrong place.
The JSON output should include platform and architecture data.

rdar://121430255
Added documentation for the JSON output.

rdar://121430255
…ads.

I'd omitted the key from the dictionary by mistake.

rdar://121430255
Check that we generate valid JSON crash reports.

rdar://121430255
Fix a typo.

Co-authored-by: Honza Dvorsky <[email protected]>
Always put `registers` in the thread record, and always use the `threads`
top level key, even if we ask for only the crashed thread.  Also add an
`omittedThreads` key.

rdar://121430255
We know we need at least as much space as the number of UTF-8
characters.

rdar://121430255
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Linux gives the main thread a name based on the process name, and also
we need to tolerate an extra slash on the `<compiler-generated>` filename
for some reason.

rdar://121430255
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Contributor Author

Linux timed-out during an unrelated test.

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test Linux platform

@al45tair al45tair merged commit 8e87541 into swiftlang:main Feb 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants