← Back to Pull requests

Add an option to add host resources automatically #68

Open
agagniere opened this pull request with 326 lines diff across 4 files
View on GitHub
agagniere agagniere commented on Aug 17, 2026 09:02 UTC
Author

Added unconditionally: SDK name, version & language

Added conditionally with 3 selectable categories:
- host: arch
- os: os type
- process: runtime name & version

For now only comptime-known values are added, the remaining work for runtime detection is tracked in #17

(Moved from https://github.com/zig-o11y/opentelemetry-sdk/pull/159)

Diff: 326 lines (+298 / -28) across 4 files Reviewer: inge4pres Review duration: 91990m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.49) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.49 · 326 lines diff across 4 files
0.49
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.346
Real PR Conversation Timeline
17 items
inge4pres inge4pres commented on code on Aug 27, 2026 08:35 UTC
Code Review
opentelemetry-sdk/src/sdk/resource.zig:1
@@ -1,12 +1,57 @@
 const std = @import("std");
+const builtin = @import("builtin");
+const build_info = @import("build_info");
 const Attribute = @import("../attributes.zig").Attribute;
 const AttributeValue = @import("../attributes.zig").AttributeValue;
 const Configuration = @import("config.zig").Configuration;
 
+const os_type: []const u8 = switch (builtin.os.tag) {
+    .macos, .ios, .tvos, .watchos => "darwin",
+    .dragonfly => "dragonflybsd",
+    .illumos => "solaris",

I thought they had removed solaris support from 0.17.0-dev onwards, due to how difficult it was to maintain a valid linker for it?
Definitely remember the discussion, but if it's gone after 0.16.0, compiler will tell 😄

inge4pres inge4pres commented on code on Aug 27, 2026 08:36 UTC
Code Review
opentelemetry-sdk/src/sdk/resource.zig:1
@@ -1,12 +1,57 @@
 const std = @import("std");
+const builtin = @import("builtin");
+const build_info = @import("build_info");
 const Attribute = @import("../attributes.zig").Attribute;
 const AttributeValue = @import("../attributes.zig").AttributeValue;
 const Configuration = @import("config.zig").Configuration;
 
+const os_type: []const u8 = switch (builtin.os.tag) {
+    .macos, .ios, .tvos, .watchos => "darwin",
+    .dragonfly => "dragonflybsd",
+    .illumos => "solaris",
+    else => @tagName(builtin.os.tag),
+};
+
+const host_arch: []const u8 = switch (builtin.cpu.arch) {
+    .x86_64 => "amd64",
+    .aarch64 => "arm64",
+    .arm => "arm32",
+    .powerpc => "ppc32",
+    .powerpc64, .powerpc64le => "ppc64",
+    else => @tagName(builtin.cpu.arch),
+};

Why even bothering converting these and not awlasy use@tagName(builtin.cpu.arch)?
Arewe trying to mirror the Go/Rust SDK names or adhere to a specific convention?

inge4pres inge4pres commented on code on Aug 27, 2026 08:39 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -378,6 +387,21 @@ fn parseInt(comptime T: type, env_map: *const EnvMap, key: []const u8) ?T {
     return std.fmt.parseInt(T, value, 10) catch null;
 }
 
+/// Parse OTEL_EXPERIMENTAL_RESOURCE_DETECTORS (comma-separated detector names).
+/// Recognized names: "host", "os", "process". Unknown names are silently ignored.
+fn parseResourceDetectors(env_map: *const EnvMap) ResourceDetectors {
+    const value = env_map.get("OTEL_EXPERIMENTAL_RESOURCE_DETECTORS") orelse return .{};
+    var detectors: ResourceDetectors = .{};
+    var iter = std.mem.splitScalar(u8, value, ',');
+    while (iter.next()) |item| {
+        const name = std.mem.trim(u8, item, &std.ascii.whitespace);
+        if (std.ascii.eqlIgnoreCase(name, "host")) detectors.host = true;
+        if (std.ascii.eqlIgnoreCase(name, "os")) detectors.os = true;
+        if (std.ascii.eqlIgnoreCase(name, "process")) detectors.process = true;
+    }
+    return detectors;
+}

nit: can we have a unit test for this?
Or actually, since we're parsing the key/value form also for other env vars (see #78), can we factor out a common function that makes the parsing and returns a slice of tuple { key: []const u8, val: []const u8 }?

inge4pres inge4pres commented on code on Aug 27, 2026 08:42 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -268,13 +268,21 @@ pub const LogsConfig = struct {
     }
 };
 
+/// Resource detectors enabled via OTEL_EXPERIMENTAL_RESOURCE_DETECTORS.
+pub const ResourceDetectors = struct {
+    host: bool = false,
+    os: bool = false,
+    process: bool = false,
+};
+
 /// Global SDK Configuration
 pub const Configuration = @This();
 
 allocator: std.mem.Allocator,
 
 // Global settings
 sdk_disabled: bool,
+resource_detectors: ResourceDetectors,

What do you think of hvaing this field as optional, and initialized to null?
It would make all changes to constructors in resource.zig unneeded, and would not break compilation for existing users of the Configuration struct.
I feel like the fact that the feature is experimental supports the suggestion, let me know.

inge4pres inge4pres commented on Aug 27, 2026 08:43 UTC
Reviewer

Nice work, thanks for the proposal Antoine 🙏🏼

Left a couple of comments

agagniere agagniere commented on code on Aug 27, 2026 08:49 UTC
Code Review
opentelemetry-sdk/src/sdk/resource.zig:1
@@ -1,12 +1,57 @@
 const std = @import("std");
+const builtin = @import("builtin");
+const build_info = @import("build_info");
 const Attribute = @import("../attributes.zig").Attribute;
 const AttributeValue = @import("../attributes.zig").AttributeValue;
 const Configuration = @import("config.zig").Configuration;
 
+const os_type: []const u8 = switch (builtin.os.tag) {
+    .macos, .ios, .tvos, .watchos => "darwin",
+    .dragonfly => "dragonflybsd",
+    .illumos => "solaris",

Yes they removed solaris, which is not open-source, but kept illumos, which is open-source.

Quote from 0.16 release notes:

Support for Oracle's Solaris and IBM's AIX and z/OS has been removed. In general, the Zig project cannot support proprietary operating systems that make it unreasonably difficult to obtain system headers and thus audit contributions. Note that this does not affect illumos; being an open source fork from OpenSolaris, it remains supported.

agagniere agagniere commented on code on Aug 27, 2026 08:52 UTC
Code Review
opentelemetry-sdk/src/sdk/resource.zig:1
@@ -1,12 +1,57 @@
 const std = @import("std");
+const builtin = @import("builtin");
+const build_info = @import("build_info");
 const Attribute = @import("../attributes.zig").Attribute;
 const AttributeValue = @import("../attributes.zig").AttributeValue;
 const Configuration = @import("config.zig").Configuration;
 
+const os_type: []const u8 = switch (builtin.os.tag) {
+    .macos, .ios, .tvos, .watchos => "darwin",
+    .dragonfly => "dragonflybsd",
+    .illumos => "solaris",
+    else => @tagName(builtin.os.tag),
+};
+
+const host_arch: []const u8 = switch (builtin.cpu.arch) {
+    .x86_64 => "amd64",
+    .aarch64 => "arm64",
+    .arm => "arm32",
+    .powerpc => "ppc32",
+    .powerpc64, .powerpc64le => "ppc64",
+    else => @tagName(builtin.cpu.arch),
+};

OTel semantic convention specs:

host.arch has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

agagniere agagniere commented on code on Aug 27, 2026 09:24 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -268,13 +268,21 @@ pub const LogsConfig = struct {
     }
 };
 
+/// Resource detectors enabled via OTEL_EXPERIMENTAL_RESOURCE_DETECTORS.
+pub const ResourceDetectors = struct {
+    host: bool = false,
+    os: bool = false,
+    process: bool = false,
+};
+
 /// Global SDK Configuration
 pub const Configuration = @This();
 
 allocator: std.mem.Allocator,
 
 // Global settings
 sdk_disabled: bool,
+resource_detectors: ResourceDetectors,

This feature is not experimental: OTel docs

It's the fact of configuring it via an env var that is non-standard, only found in the python SDK (doc).
(Edited: fixed python doc link)

agagniere agagniere commented on code on Aug 27, 2026 09:30 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -378,6 +387,21 @@ fn parseInt(comptime T: type, env_map: *const EnvMap, key: []const u8) ?T {
     return std.fmt.parseInt(T, value, 10) catch null;
 }
 
+/// Parse OTEL_EXPERIMENTAL_RESOURCE_DETECTORS (comma-separated detector names).
+/// Recognized names: "host", "os", "process". Unknown names are silently ignored.
+fn parseResourceDetectors(env_map: *const EnvMap) ResourceDetectors {
+    const value = env_map.get("OTEL_EXPERIMENTAL_RESOURCE_DETECTORS") orelse return .{};
+    var detectors: ResourceDetectors = .{};
+    var iter = std.mem.splitScalar(u8, value, ',');
+    while (iter.next()) |item| {
+        const name = std.mem.trim(u8, item, &std.ascii.whitespace);
+        if (std.ascii.eqlIgnoreCase(name, "host")) detectors.host = true;
+        if (std.ascii.eqlIgnoreCase(name, "os")) detectors.os = true;
+        if (std.ascii.eqlIgnoreCase(name, "process")) detectors.process = true;
+    }
+    return detectors;
+}

Agreed, let's make an iterator for this

agagniere agagniere commented on Aug 27, 2026 12:06 UTC
Author

I realized that these should be enabled by default:

1. Those attributes are marked as:
- os.type: "Required"
- host.arch: "Recommended"
- process.runtime.: "Recommended"
- telemetry.sdk.
: "Required"
1. "Required" and "Recommended" means enabled by default

So I will make these opt-out rather than opt-in.

agagniere agagniere commented on code on Aug 27, 2026 12:14 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -413,6 +422,21 @@ fn parseInt(comptime T: type, env_map: *const EnvMap, key: []const u8) ?T {
     return std.fmt.parseInt(T, value, 10) catch null;
 }
 
+/// Parse OTEL_EXPERIMENTAL_RESOURCE_DETECTORS (comma-separated detector names).
+/// Recognized names: "host", "os", "process". Unknown names are silently ignored.

Python SDK added the possibility to include all detectors with * (PR)

inge4pres inge4pres commented on code on Sep 05, 2026 21:28 UTC
Code Review
opentelemetry-sdk/src/sdk/resource.zig:1
@@ -1,12 +1,57 @@
 const std = @import("std");
+const builtin = @import("builtin");
+const build_info = @import("build_info");
 const Attribute = @import("../attributes.zig").Attribute;
 const AttributeValue = @import("../attributes.zig").AttributeValue;
 const Configuration = @import("config.zig").Configuration;
 
+const os_type: []const u8 = switch (builtin.os.tag) {
+    .macos, .ios, .tvos, .watchos => "darwin",
+    .dragonfly => "dragonflybsd",
+    .illumos => "solaris",
+    else => @tagName(builtin.os.tag),
+};
+
+const host_arch: []const u8 = switch (builtin.cpu.arch) {
+    .x86_64 => "amd64",
+    .aarch64 => "arm64",
+    .arm => "arm32",
+    .powerpc => "ppc32",
+    .powerpc64, .powerpc64le => "ppc64",
+    else => @tagName(builtin.cpu.arch),
+};

great, do we provide in semconv an enum of host.arch known values to pull tag from? I'd love to see it referenced here.
I saw the raw values written by hand and got confused, if they were referencing the enum from semconv, we are safer.
WDYT?

inge4pres inge4pres commented on code on Sep 05, 2026 21:30 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -268,13 +268,21 @@ pub const LogsConfig = struct {
     }
 };
 
+/// Resource detectors enabled via OTEL_EXPERIMENTAL_RESOURCE_DETECTORS.
+pub const ResourceDetectors = struct {
+    host: bool = false,
+    os: bool = false,
+    process: bool = false,
+};
+
 /// Global SDK Configuration
 pub const Configuration = @This();
 
 allocator: std.mem.Allocator,
 
 // Global settings
 sdk_disabled: bool,
+resource_detectors: ResourceDetectors,

Got it, thanks 🙏🏼
So we're init'ing the new field in the constructor?

inge4pres inge4pres commented on code on Sep 05, 2026 21:32 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -268,13 +268,21 @@ pub const LogsConfig = struct {
     }
 };
 
+/// Resource detectors enabled via OTEL_EXPERIMENTAL_RESOURCE_DETECTORS.
+pub const ResourceDetectors = struct {
+    host: bool = false,
+    os: bool = false,
+    process: bool = false,
+};
+
 /// Global SDK Configuration
 pub const Configuration = @This();
 
 allocator: std.mem.Allocator,
 
 // Global settings
 sdk_disabled: bool,
+resource_detectors: ResourceDetectors,

Nvm, I saw the code once more...

agagniere agagniere commented on code on Sep 09, 2026 16:31 UTC
Code Review
opentelemetry-sdk/src/sdk/config.zig:1
@@ -378,6 +387,21 @@ fn parseInt(comptime T: type, env_map: *const EnvMap, key: []const u8) ?T {
     return std.fmt.parseInt(T, value, 10) catch null;
 }
 
+/// Parse OTEL_EXPERIMENTAL_RESOURCE_DETECTORS (comma-separated detector names).
+/// Recognized names: "host", "os", "process". Unknown names are silently ignored.
+fn parseResourceDetectors(env_map: *const EnvMap) ResourceDetectors {
+    const value = env_map.get("OTEL_EXPERIMENTAL_RESOURCE_DETECTORS") orelse return .{};
+    var detectors: ResourceDetectors = .{};
+    var iter = std.mem.splitScalar(u8, value, ',');
+    while (iter.next()) |item| {
+        const name = std.mem.trim(u8, item, &std.ascii.whitespace);
+        if (std.ascii.eqlIgnoreCase(name, "host")) detectors.host = true;
+        if (std.ascii.eqlIgnoreCase(name, "os")) detectors.os = true;
+        if (std.ascii.eqlIgnoreCase(name, "process")) detectors.process = true;
+    }
+    return detectors;
+}
agagniere agagniere commented on Sep 09, 2026 16:33 UTC
Author

After https://github.com/open-telemetry/opentelemetry-zig/pull/92 is merged I will use the iterator here

Reviewers
Assignees
agagniere agagniere
Labels
risk: low confidence: 89.3% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 49% (MEDIUM) · Higher = larger blast radius
49%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 89.3% · Lower = rushed or shallow review
89.3%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.2% · Safe to merge
5.2%