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