@@ -6,10 +6,10 @@ const Loop = @import("jsruntime").Loop;
66const Client = @import ("asyncio" ).Client ;
77const Event = @import ("telemetry.zig" ).Event ;
88const RunMode = @import ("../app.zig" ).RunMode ;
9+ const builtin = @import ("builtin" );
10+ const build_info = @import ("build_info" );
911
1012const log = std .log .scoped (.telemetry );
11-
12- const DATA_VERSION = 1 ;
1313const URL = "https://lightpanda.io/browser-stats" ;
1414
1515pub const LightPanda = struct {
@@ -37,15 +37,18 @@ pub const LightPanda = struct {
3737 self .client_context_pool .deinit ();
3838 }
3939
40- pub fn send (self : * LightPanda , iid : ? []const u8 , run_mode : RunMode , event : * const Event ) ! void {
40+ pub fn send (self : * LightPanda , iid : ? []const u8 , run_mode : RunMode , event : Event ) ! void {
4141 var arena = std .heap .ArenaAllocator .init (self .allocator );
4242 errdefer arena .deinit ();
4343
4444 const resp_header_buffer = try arena .allocator ().alloc (u8 , 4096 );
45- const body = try std .json .stringifyAlloc (arena .allocator (), EventWrap {
45+ const body = try std .json .stringifyAlloc (arena .allocator (), . {
4646 .iid = iid ,
47- .event = event ,
4847 .run_mode = run_mode ,
48+ .os = builtin .os .tag ,
49+ .aarch = builtin .cpu .arch ,
50+ .version = build_info .git_commit ,
51+ .event = std .meta .activeTag (event ),
4952 }, .{});
5053
5154 const sending = try self .sending_pool .create ();
@@ -161,40 +164,3 @@ const Sending = struct {
161164 self .request .deinit ();
162165 }
163166};
164-
165- // wraps a telemetry event so that we can serialize it to plausible's event endpoint
166- const EventWrap = struct {
167- iid : ? []const u8 ,
168- event : * const Event ,
169- run_mode : RunMode ,
170-
171- const builtin = @import ("builtin" );
172- const build_info = @import ("build_info" );
173-
174- pub fn jsonStringify (self : * const EventWrap , jws : anytype ) ! void {
175- try jws .beginObject ();
176- try jws .objectField ("iid" );
177- try jws .write (self .iid );
178- try jws .objectField ("event" );
179- try jws .write (@tagName (self .event .* ));
180- try jws .objectField ("mode" );
181- try jws .write (self .run_mode );
182- try jws .objectField ("version" );
183- try jws .write (DATA_VERSION );
184- try jws .objectField ("os" );
185- try jws .write (builtin .os .tag );
186- try jws .objectField ("version" );
187- try jws .write (build_info .git_commit );
188- try jws .objectField ("arch" );
189- try jws .write (builtin .cpu .arch );
190- switch (self .event .* ) {
191- .run = > {},
192- .navigate = > {},
193- .flag = > | f | {
194- try jws .objectField ("flag" );
195- try jws .write (f );
196- },
197- }
198- try jws .endObject ();
199- }
200- };
0 commit comments