logfire client for zig
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add setStatus and recordError API to Span

enables HTTP and DB instrumentation with proper error tracking:
- StatusCode enum (unset, ok, error) per otel semantic conventions
- setStatus(code, description) for explicit status setting
- recordError(e) - zig-idiomatic naming (not recordException)
zig has errors, not exceptions; maps to otel's recordException internally

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

zzstoatzz 7cc16e72 1aec0459

+42
+42
src/otel_wrapper.zig
··· 233 233 // Span wrapper 234 234 // ============================================================================ 235 235 236 + /// span status codes (per otel semantic conventions) 237 + pub const StatusCode = enum { 238 + /// default - status not explicitly set 239 + unset, 240 + /// operation completed successfully 241 + ok, 242 + /// operation failed 243 + @"error", 244 + }; 245 + 236 246 pub const Span = struct { 237 247 inner: ?otel_api.trace.Span, 238 248 parent_context: ?otel_api.trace.Span.Context, ··· 260 270 if (toOtelValue(value)) |val| { 261 271 s.setAttribute(.{ .key = key, .value = val }); 262 272 } 273 + } 274 + } 275 + } 276 + 277 + /// set span status (call with .@"error" to mark failures) 278 + pub fn setStatus(self: *const Span, code: StatusCode, description: ?[]const u8) void { 279 + if (self.inner != null) { 280 + const mutable = @constCast(self); 281 + if (mutable.inner) |*s| { 282 + s.setStatus(.{ 283 + .code = switch (code) { 284 + .unset => .unset, 285 + .ok => .ok, 286 + .@"error" => .@"error", 287 + }, 288 + .description = description, 289 + }); 290 + } 291 + } 292 + } 293 + 294 + /// record an error on the span (adds event + sets error status) 295 + pub fn recordError(self: *const Span, e: anyerror) void { 296 + if (self.inner != null) { 297 + const mutable = @constCast(self); 298 + if (mutable.inner) |*s| { 299 + // otel API calls this "exception" but we use zig-idiomatic naming 300 + s.recordException(e, null, null) catch {}; 301 + s.setStatus(.{ 302 + .code = .@"error", 303 + .description = @errorName(e), 304 + }); 263 305 } 264 306 } 265 307 }