logfire client for zig
1//! logfire example
2//!
3//! demonstrates the otel-zig backed API.
4//! API matches current leaflet-search usage patterns.
5//!
6//! run with:
7//! LOGFIRE_TOKEN=your_token zig build example
8//!
9//! or without token for console-only output:
10//! zig build example
11
12const std = @import("std");
13const logfire = @import("logfire");
14
15pub fn main() !void {
16 // configure logfire (reads LOGFIRE_TOKEN from env)
17 // API matches: logfire.configure({...})
18 _ = logfire.configure(.{
19 .service_name = "logfire-zig-otel-example",
20 .service_version = "0.1.0",
21 .environment = "development",
22 }) catch |err| {
23 std.debug.print("logfire init failed: {}, continuing\n", .{err});
24 };
25
26 // logging - matches: logfire.info("msg", .{args})
27 logfire.info("application started", .{});
28
29 // span with attributes - matches: logfire.span("name", .{attrs})
30 // uses const span pattern for API compatibility with leaflet-search
31 {
32 const span = logfire.span("example.work", .{
33 .iteration = @as(i64, 1),
34 .query = "prefect python",
35 });
36 defer span.end();
37
38 // simulate work
39 std.posix.nanosleep(0, 50 * std.time.ns_per_ms);
40
41 logfire.info("work completed", .{});
42 }
43
44 // nested spans
45 {
46 const outer = logfire.span("example.outer", .{});
47 defer outer.end();
48
49 {
50 const inner = logfire.span("example.inner", .{});
51 defer inner.end();
52
53 std.posix.nanosleep(0, 25 * std.time.ns_per_ms);
54 }
55 }
56
57 // metrics (stubs for now)
58 logfire.counter("requests.total", 1);
59 logfire.gaugeInt("connections.active", 42);
60
61 logfire.info("example complete", .{});
62}