1const std = @import("std");
2const root = @import("root");
3const extras = @import("extras");
4const nfs = @import("nfs");
5const backend: Backend = extras.globalOption("tracer_backend", Backend) orelse .none;
6const impl = switch (backend) {
7 .none => none,
8 .log => log,
9 .chrome => chrome,
10 .spall => spall,
11 .otel => otel,
12};
13
14pub const none = @import("./none.zig");
15pub const log = @import("./log.zig");
16pub const chrome = @import("./chrome.zig");
17pub const spall = @import("./spall.zig");
18pub const otel = @import("./otel.zig");
19
20pub const Backend = enum {
21 none,
22 log,
23 chrome,
24 spall,
25 otel,
26};
27
28threadlocal var started = false;
29
30pub fn init(args: @typeInfo(@TypeOf(impl.init)).@"fn".params[0].type.?) !void {
31 try impl.init(args);
32}
33
34pub fn deinit() void {
35 impl.deinit();
36}
37
38pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void {
39 try impl.init_thread(args);
40 started = true;
41}
42
43pub fn deinit_thread() void {
44 impl.deinit_thread();
45 started = false;
46}
47
48pub fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx {
49 return .{
50 .src = src,
51 .data = if (!started) undefined else impl.trace_begin(src, fmt, args),
52 };
53}
54
55pub const Ctx = struct {
56 src: std.builtin.SourceLocation,
57 data: impl.Data,
58
59 pub fn end(self: Ctx) void {
60 if (!started) return;
61 impl.trace_end(self);
62 }
63};