sentry init uses proper cache dir, sets tags

This commit is contained in:
Mitchell Hashimoto
2024-08-27 19:08:13 -07:00
parent 7f143d9df4
commit e029490535
3 changed files with 31 additions and 6 deletions

View File

@ -14,6 +14,10 @@ pub fn captureEvent(value: Value) ?UUID {
return uuid; return uuid;
} }
pub fn setTag(key: []const u8, value: []const u8) void {
c.sentry_set_tag_n(key.ptr, key.len, value.ptr, value.len);
}
test { test {
@import("std").testing.refAllDecls(@This()); @import("std").testing.refAllDecls(@This());
} }

View File

@ -119,7 +119,7 @@ pub const GlobalState = struct {
internal_os.fixMaxFiles(); internal_os.fixMaxFiles();
// Initialize our crash reporting. // Initialize our crash reporting.
try sentry.init(); try sentry.init(self.alloc);
// const sentrylib = @import("sentry"); // const sentrylib = @import("sentry");
// if (sentrylib.captureEvent(sentrylib.Value.initMessageEvent( // if (sentrylib.captureEvent(sentrylib.Value.initMessageEvent(

View File

@ -1,7 +1,9 @@
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const build_config = @import("build_config.zig"); const build_config = @import("build_config.zig");
const sentry = @import("sentry"); const sentry = @import("sentry");
const internal_os = @import("os/main.zig");
const log = std.log.scoped(.sentry); const log = std.log.scoped(.sentry);
@ -12,7 +14,11 @@ const log = std.log.scoped(.sentry);
/// crash reports and logs, but we only store them locally (see Transport). /// crash reports and logs, but we only store them locally (see Transport).
/// It is up to the user to grab the logs and manually send them to us /// It is up to the user to grab the logs and manually send them to us
/// (or they own Sentry instance) if they want to. /// (or they own Sentry instance) if they want to.
pub fn init() !void { pub fn init(gpa: Allocator) !void {
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
const alloc = arena.allocator();
const transport = sentry.Transport.init(&Transport.send); const transport = sentry.Transport.init(&Transport.send);
errdefer transport.deinit(); errdefer transport.deinit();
@ -20,17 +26,32 @@ pub fn init() !void {
errdefer sentry.c.sentry_options_free(opts); errdefer sentry.c.sentry_options_free(opts);
sentry.c.sentry_options_set_release_n( sentry.c.sentry_options_set_release_n(
opts, opts,
build_config.version_string, build_config.version_string.ptr,
build_config.version_string.len, build_config.version_string.len,
); );
sentry.c.sentry_options_set_transport(opts, @ptrCast(transport)); sentry.c.sentry_options_set_transport(opts, @ptrCast(transport));
// Determine the Sentry cache directory.
const cache_dir = try internal_os.xdg.cache(alloc, .{ .subdir = "ghostty/sentry" });
sentry.c.sentry_options_set_database_path_n(
opts,
cache_dir.ptr,
cache_dir.len,
);
// Debug logging for Sentry // Debug logging for Sentry
sentry.c.sentry_options_set_debug(opts, @intFromBool(true)); sentry.c.sentry_options_set_debug(opts, @intFromBool(true));
if (sentry.c.sentry_init(opts) != 0) { // Setup some basic tags that we always want present
log.warn("failed to initialize sentry", .{}); sentry.setTag("app-runtime", @tagName(build_config.app_runtime));
} sentry.setTag("font-backend", @tagName(build_config.font_backend));
sentry.setTag("renderer", @tagName(build_config.renderer));
// Initialize
if (sentry.c.sentry_init(opts) != 0) return error.SentryInitFailed;
// Log some information about sentry
log.debug("sentry initialized database={s}", .{cache_dir});
} }
/// Process-wide deinitialization of our Sentry client. This ensures all /// Process-wide deinitialization of our Sentry client. This ensures all