Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub const SentryClient = struct {
.items = buf[0..],
};

std.debug.print("Sending envelope", .{});
_ = try self.transport.send(envelope);

return prepared_event.event_id.value;
Expand Down
12 changes: 12 additions & 0 deletions src/transport.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ pub const HttpTransport = struct {
}

pub fn send(self: *HttpTransport, envelope: SentryEnvelope) !TransportResult {
std.debug.print("sending envelope", .{});
const payload = try self.envelopeToPayload(envelope);
defer self.allocator.free(payload);

// Check if DSN is configured
const dsn = self.options.dsn orelse {
return TransportResult{ .response_code = 0 };
};
std.debug.print("dsn: {s}", .{dsn});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Potential bug: `std.debug.print` calls use the `{s}` specifier for `Dsn` and `Uri` structs, which will cause a compilation error as `{s}` requires a string.
  • Description: The std.debug.print calls at src/transport.zig:52 and src/transport.zig:75 attempt to print the dsn and uri structs using the {s} format specifier. In Zig, {s} is strictly for string types ([]const u8). Since neither the Dsn nor std.Uri structs implement a custom format method to handle this, the compiler will raise a type mismatch error. This bug will prevent the project from compiling, blocking any testing or deployment of the new transport functionality.

  • Suggested fix: Replace the {s} format specifier with {} to use the default struct formatting for std.debug.print. For example, change std.debug.print("dsn: {s}", .{dsn}); to std.debug.print("dsn: {}", .{dsn});.
    severity: 0.9, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

// Construct the Sentry envelope endpoint URL
const netloc = dsn.getNetloc(self.allocator) catch {
return TransportResult{ .response_code = 0 };
};
defer self.allocator.free(netloc);
std.debug.print("netloc: {s}", .{netloc});

const endpoint_url = std.fmt.allocPrint(self.allocator, "{s}://{s}/api/{s}/envelope/", .{
dsn.scheme,
Expand All @@ -63,11 +66,13 @@ pub const HttpTransport = struct {
return TransportResult{ .response_code = 0 };
};
defer self.allocator.free(endpoint_url);
std.debug.print("endpoint_url: {s}", .{endpoint_url});

// Parse the URL and make the HTTP request
const uri = std.Uri.parse(endpoint_url) catch {
return TransportResult{ .response_code = 0 };
};
std.debug.print("uri: {s}", .{uri});

// Construct the auth header
const auth_header = std.fmt.allocPrint(self.allocator, "Sentry sentry_version=7,sentry_key={s},sentry_client=sentry-zig/0.1.0", .{
Expand All @@ -76,19 +81,23 @@ pub const HttpTransport = struct {
return TransportResult{ .response_code = 0 };
};
defer self.allocator.free(auth_header);
std.debug.print("auth_header: {s}", .{auth_header});

// Create Content-Length header value
const content_length = std.fmt.allocPrint(self.allocator, "{d}", .{payload.len}) catch {
return TransportResult{ .response_code = 0 };
};
defer self.allocator.free(content_length);
std.debug.print("content_length: {s}", .{content_length});

const headers = [_]std.http.Header{
.{ .name = "Content-Type", .value = "application/x-sentry-envelope" },
.{ .name = "Content-Length", .value = content_length },
.{ .name = "X-Sentry-Auth", .value = auth_header },
};

std.debug.print("headers: {any}", .{headers});

var response_body = std.ArrayList(u8).init(self.allocator);
defer response_body.deinit();

Expand Down Expand Up @@ -135,9 +144,12 @@ pub const HttpTransport = struct {
var list = std.ArrayList(u8).init(self.allocator);
errdefer list.deinit();

std.debug.print("stringifying event");

try std.json.stringify(event, .{}, list.writer());

const data = try list.toOwnedSlice();
std.debug.print("Creating envelope item");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Potential bug: Two `std.debug.print` calls are missing the required empty tuple argument `.{}` which will cause a compilation error.
  • Description: The std.debug.print calls on lines 147 and 152 of src/transport.zig are missing their second argument. The Zig standard library requires std.debug.print to always be called with a tuple for its format arguments, even if the format string contains no specifiers. In such cases, an empty tuple .{} must be provided. This omission will cause a compilation failure, preventing the code from being built.

  • Suggested fix: Add the required empty tuple argument .{} to the std.debug.print calls on lines 147 and 152, like so: std.debug.print("stringifying event", .{});.
    severity: 0.9, confidence: 0.98

Did we get this right? 👍 / 👎 to inform future reviews.

return SentryEnvelopeItem{
.header = .{
.type = .event,
Expand Down
Loading