crash: tag the thread type

This commit is contained in:
Mitchell Hashimoto
2024-09-02 09:59:19 -07:00
parent d8cc19612f
commit bae12993b3
3 changed files with 16 additions and 1 deletions

View File

@ -23,8 +23,13 @@ var init_thread: ?std.Thread = null;
/// This means that if we want to set thread-specific data we have to do it
/// on our own in the on crash callback.
pub const ThreadState = struct {
/// Thread type, used to tag the crash
type: Type,
/// The surface that this thread is attached to.
surface: *Surface,
pub const Type = enum { main, renderer, io };
};
/// See ThreadState. This should only ever be set by the owner of the
@ -156,6 +161,14 @@ fn beforeSend(
event.set("contexts", obj);
break :contexts obj;
};
const tags = event.get("tags") orelse tags: {
const obj = sentry.Value.initObject();
event.set("tags", obj);
break :tags obj;
};
// Store our thread type
tags.set("thread-type", sentry.Value.initString(@tagName(thr_state.type)));
// Read the surface data. This is likely unsafe because on a crash
// other threads can continue running. We don't have race-safe way to
@ -189,7 +202,7 @@ fn beforeSend(
sentry.Value.initInt32(std.math.cast(i32, surface.cell_size.height) orelse -1),
);
contexts.set("dimensions", obj);
contexts.set("Dimensions", obj);
}
return event_val;

View File

@ -194,6 +194,7 @@ fn threadMain_(self: *Thread) !void {
// Setup our crash metadata
crash.sentry.thread_state = .{
.type = .renderer,
.surface = self.renderer.surface_mailbox.surface,
};
defer crash.sentry.thread_state = null;

View File

@ -203,6 +203,7 @@ fn threadMain_(self: *Thread, io: *termio.Termio) !void {
// Setup our crash metadata
crash.sentry.thread_state = .{
.type = .io,
.surface = io.surface_mailbox.surface,
};
defer crash.sentry.thread_state = null;