Skip to main content
The opentelemetry-sdk for Zig is in alpha (v0.1.1). Expect breaking changes between releases.
Send Zig logs to Rootprint through the OpenTelemetry SDK’s std.log bridge, which routes existing std.log calls over OTLP HTTP.

Prerequisites

  • A running Rootprint instance. Substitute its host for <your-rootprint>.
  • Zig ≥ 0.15.2.
  • An ingest API key scoped to an OpenTelemetry logs index such as otel-logs-v0_9. In Settings → API keys, click Create ingest key and pick the index. See API keys.

Setup

1

Add the SDK to your project

Run this in your project root:
Then add these lines to build.zig after your exe declaration:
2

Minimal working example

SDK v0.1.1 doesn’t read the auth header from the environment, so the example sets the endpoint, header, and service name in code. Replace <your-rootprint> and <your-ingest-api-key>. Leave the OTEL_EXPORTER_OTLP_* endpoint variables unset: they override the endpoint set in code.Save as src/main.zig and run zig build run.
3

Verify in Rootprint

Open Logs, filter on service_name:my-zig-service, and your record should appear within a few seconds.

Log levels and attributes

The std.log bridge maps Zig log levels to OpenTelemetry log levels: std.log has no key/value attributes. Format arguments are interpolated into the message, which becomes the log record body:
For attributes, use the SDK’s logger API directly. See the examples/logs/ folder in the SDK repository.

Troubleshooting

  • The program hangs and prints Deadlock detected: an export failed, for example with a 401 from a wrong ingest API key. SDK v0.1.1 deadlocks when it logs the failure through the std.log bridge. Check the endpoint and key in otlp_config. See Response codes.
  • 200 but no records in Logs: the ingest API key is scoped to an index without the OpenTelemetry logs schema, so the records are discarded. See Index target.