don't send empty envelopes

This commit is contained in:
Mitchell Hashimoto
2024-08-27 20:15:14 -07:00
parent b826c98701
commit 33e9bc14ef
3 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,7 @@
const std = @import("std");
const assert = std.debug.assert;
const c = @import("c.zig").c;
const Value = @import("value.zig").Value;
/// sentry_envelope_t
pub const Envelope = opaque {
@ -15,4 +16,10 @@ pub const Envelope = opaque {
path.len,
) != 0) return error.WriteFailed;
}
pub fn event(self: *Envelope) ?Value {
const val: Value = .{ .value = c.sentry_envelope_get_event(@ptrCast(self)) };
if (val.isNull()) return null;
return val;
}
};

View File

@ -31,4 +31,8 @@ pub const Value = struct {
pub fn incref(self: Value) Value {
c.sentry_value_incref(self.value);
}
pub fn isNull(self: Value) bool {
return c.sentry_value_is_null(self.value) != 0;
}
};

View File

@ -75,6 +75,9 @@ pub const Transport = struct {
/// Implementation of send but we can use Zig errors.
fn sendInternal(envelope: *sentry.Envelope) !void {
// If our envelope doesn't have an event then we don't do anything.
if (envelope.event() == null) return;
var arena = std.heap.ArenaAllocator.init(state.alloc);
defer arena.deinit();
const alloc = arena.allocator();