std.log bridge routes all
standard library log calls to OpenTelemetry without changing a single call site. Records land in
the OTEL logs index pinned by your ingest API key (otel-logs-v0_9 in these examples).
Prerequisites
- A running Rootprint instance and its base URL — you’ll substitute it for
<your-rootprint>. - Zig ≥ 0.15.2.
- An ingest API key scoped to your target index. In Settings → API keys, click Create ingest key, give it a name, and pick the index (
otel-logs-v0_9for the examples here). See API keys.
Setup
1
Add the SDK to your project
Requires Zig ≥ 0.15.2. Run this in your project root:Then add these lines to The dependency key
build.zig after your exe declaration:opentelemetry matches the SDK’s package name in its
build.zig.zon; the import alias opentelemetry-sdk is what your code will
@import.2
Set environment variables
3
Minimal working example
Save as
src/main.zig and run zig build run. The bridge reads the endpoint and auth header
from the environment variables above.4
Verify in Rootprint
Open Search, filter on
service_name:my-zig-service, and your record should appear within
~2 seconds.Structured logging
Thestd.log bridge maps Zig log levels to OpenTelemetry severity numbers automatically:
Log messages and their format arguments become the log record body. Unlike Go’s
slog.With,
the std.log API does not support structured key/value attributes. Format args are interpolated
into the message string.
