logfire client for zig
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
6
7 // otel-zig dependency
8 const otel_dep = b.dependency("opentelemetry", .{
9 .target = target,
10 .optimize = optimize,
11 });
12
13 // config module (shared between modules)
14 const config_mod = b.createModule(.{
15 .root_source_file = b.path("src/config.zig"),
16 .target = target,
17 .optimize = optimize,
18 });
19
20 // logfire module (otel-backed)
21 const logfire_mod = b.addModule("logfire", .{
22 .root_source_file = b.path("src/otel_wrapper.zig"),
23 .target = target,
24 .optimize = optimize,
25 .imports = &.{
26 .{ .name = "otel", .module = otel_dep.module("otel") },
27 .{ .name = "config", .module = config_mod },
28 },
29 });
30
31 // tests
32 const tests = b.addTest(.{
33 .root_module = b.createModule(.{
34 .root_source_file = b.path("src/otel_wrapper.zig"),
35 .target = target,
36 .optimize = optimize,
37 .imports = &.{
38 .{ .name = "otel", .module = otel_dep.module("otel") },
39 .{ .name = "config", .module = config_mod },
40 },
41 }),
42 });
43 const run_tests = b.addRunArtifact(tests);
44
45 const test_step = b.step("test", "run unit tests");
46 test_step.dependOn(&run_tests.step);
47
48 // example executable
49 const example = b.addExecutable(.{
50 .name = "example",
51 .root_module = b.createModule(.{
52 .root_source_file = b.path("examples/otel_basic.zig"),
53 .target = target,
54 .optimize = optimize,
55 .imports = &.{.{ .name = "logfire", .module = logfire_mod }},
56 }),
57 });
58
59 const run_example = b.addRunArtifact(example);
60 const example_step = b.step("example", "run example");
61 example_step.dependOn(&run_example.step);
62
63 // validation script for otel-zig OTLP export (not in CI, requires LOGFIRE_TOKEN)
64 const validate_otel = b.addExecutable(.{
65 .name = "validate-otel-export",
66 .root_module = b.createModule(.{
67 .root_source_file = b.path("tests/validate_otel_export.zig"),
68 .target = target,
69 .optimize = optimize,
70 .imports = &.{
71 .{ .name = "otel", .module = otel_dep.module("otel") },
72 },
73 }),
74 });
75
76 const run_validate_otel = b.addRunArtifact(validate_otel);
77 const validate_step = b.step("validate-otel", "validate otel-zig OTLP export to logfire (requires LOGFIRE_TOKEN)");
78 validate_step.dependOn(&run_validate_otel.step);
79}