Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ pub fn build(b: *std.Build) void {
lib.root_module.addImport("types", types);
types.addImport("utils", lib_mod);

// IMPORTANT: Expose the module for external packages
// This allows other packages to import sentry_zig via b.dependency().module()
_ = b.addModule("sentry_zig", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "types", .module = types },
.{ .name = "sentry_build", .module = sentry_build_opts.createModule() },
},
});

// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
Expand Down
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
10 changes: 10 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: {any}", .{dsn});

// 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: {any}", .{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,12 +81,14 @@ 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" },
Expand Down Expand Up @@ -135,9 +142,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.

Bug: Unconditional Debug Statements Leak Sensitive Information

A few unconditional std.debug.print statements were added that bypass the existing conditional std.log.debug system. These appear to be temporary debugging code and will produce unwanted output in production. Some also expose sensitive DSN details and authentication headers.

Additional Locations (1)

Fix in Cursor Fix in Web

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