telemetry: remove allocation for llm event

The model length is limited to 23 char in DB.
This commit is contained in:
Pierre Tachoire
2026-06-05 11:02:03 +02:00
parent 3f012cee4c
commit d44bdaa0c9
2 changed files with 40 additions and 11 deletions

View File

@@ -198,7 +198,6 @@ fn run(allocator: Allocator, main_arena: Allocator) !void {
{
var worker_thread = try std.Thread.spawn(.{}, agentThread, .{
allocator,
main_arena,
app,
opts,
&failed,
@@ -219,7 +218,6 @@ fn run(allocator: Allocator, main_arena: Allocator) !void {
fn agentThread(
allocator: std.mem.Allocator,
arena: std.mem.Allocator,
app: *App,
opts: Config.Agent,
failed: *bool,
@@ -243,15 +241,13 @@ fn agentThread(
defer sig_bridge.detach();
if (agent_instance.ai_client) |cli| {
app.telemetry.record(.{ .llm = .{
.provider = @tagName(cli),
.model = arena.dupe(u8, agent_instance.model) catch null,
} });
app.telemetry.record(.{
.llm = app.telemetry.llm_init(@tagName(cli), agent_instance.model),
});
} else {
app.telemetry.record(.{ .llm = .{
.provider = "nollm",
.model = null,
} });
app.telemetry.record(.{
.llm = app.telemetry.llm_init("nollm", null),
});
}
if (!agent_instance.run()) {

View File

@@ -60,6 +60,10 @@ fn TelemetryT(comptime P: type) type {
log.warn(.telemetry, "record error", .{ .err = err, .type = @tagName(std.meta.activeTag(event)) });
};
}
pub fn llm_init(_: *Self, provider: [:0]const u8, model: ?[]const u8) Event.LLM {
return Event.LLM.init(provider, model);
}
};
}
@@ -117,7 +121,36 @@ pub const Event = union(enum) {
const LLM = struct {
provider: [:0]const u8,
model: ?[]const u8,
model: ?Model,
const Model = struct {
len: u8,
buffer: [32]u8,
pub fn wrap(_s: ?[]const u8) ?Model {
if (_s == null) return null;
const l = @min(_s.?.len, 32);
var m: Model = .{
.len = l,
.buffer = undefined,
};
@memcpy(m.buffer[0..l], _s.?[0..l]);
return m;
}
pub fn jsonStringify(self: *const Model, writer: anytype) !void {
try writer.write(self.buffer[0..self.len]);
}
};
pub fn init(provider: [:0]const u8, _model: ?[]const u8) LLM {
return .{
.provider = provider,
.model = Model.wrap(_model),
};
}
};
};