| ... | @@ -25,6 +25,8 @@ pub const Backend = enum { | ... | @@ -25,6 +25,8 @@ pub const Backend = enum { |
| 25 | otel, | 25 | otel, |
| 26 | }; | 26 | }; |
| 27 | | 27 | |
| | 28 | threadlocal var started = false; |
| | 29 | |
| 28 | pub fn init(args: @typeInfo(@TypeOf(impl.init)).@"fn".params[0].type.?) !void { | 30 | pub fn init(args: @typeInfo(@TypeOf(impl.init)).@"fn".params[0].type.?) !void { |
| 29 | try impl.init(args); | 31 | try impl.init(args); |
| 30 | } | 32 | } |
| ... | @@ -35,16 +37,18 @@ pub fn deinit() void { | ... | @@ -35,16 +37,18 @@ pub fn deinit() void { |
| 35 | | 37 | |
| 36 | pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { | 38 | pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { |
| 37 | try impl.init_thread(args); | 39 | try impl.init_thread(args); |
| | 40 | started = true; |
| 38 | } | 41 | } |
| 39 | | 42 | |
| 40 | pub fn deinit_thread() void { | 43 | pub fn deinit_thread() void { |
| 41 | impl.deinit_thread(); | 44 | impl.deinit_thread(); |
| | 45 | started = false; |
| 42 | } | 46 | } |
| 43 | | 47 | |
| 44 | pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { | 48 | pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx { |
| 45 | return .{ | 49 | return .{ |
| 46 | .src = src, | 50 | .src = src, |
| 47 | .data = impl.trace_begin(src, fmt, args), | 51 | .data = if (!started) undefined else impl.trace_begin(src, fmt, args), |
| 48 | }; | 52 | }; |
| 49 | } | 53 | } |
| 50 | | 54 | |
| ... | @@ -53,6 +57,7 @@ pub const Ctx = struct { | ... | @@ -53,6 +57,7 @@ pub const Ctx = struct { |
| 53 | data: impl.Data, | 57 | data: impl.Data, |
| 54 | | 58 | |
| 55 | pub inline fn end(self: Ctx) void { | 59 | pub inline fn end(self: Ctx) void { |
| | 60 | if (!started) return; |
| 56 | impl.trace_end(self); | 61 | impl.trace_end(self); |
| 57 | } | 62 | } |
| 58 | }; | 63 | }; |