Skip to content

Add an option to add host resources automatically - #68

Draft
agagniere wants to merge 6 commits into
open-telemetry:mainfrom
agagniere:host-resources
Draft

Add an option to add host resources automatically#68
agagniere wants to merge 6 commits into
open-telemetry:mainfrom
agagniere:host-resources

Conversation

@agagniere

@agagniere agagniere commented Aug 17, 2026

Copy link
Copy Markdown
Member

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 zig-o11y/opentelemetry-sdk#159)

Added unconditionally: SDK name, version & language
Added conditionally with 3 selectable categories:
 - host: arch
 - os: os type
 - process: runtime name & version
@agagniere agagniere self-assigned this Aug 17, 2026
@agagniere
agagniere requested a review from a team as a code owner August 17, 2026 09:02
@agagniere agagniere added the enhancement New feature or request label Aug 17, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Zig SIG Aug 17, 2026
@agagniere agagniere moved this from Backlog to In review in Zig SIG Aug 17, 2026

@inge4pres inge4pres left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks for the proposal Antoine 🙏🏼

Left a couple of comments

const os_type: []const u8 = switch (builtin.os.tag) {
.macos, .ios, .tvos, .watchos => "darwin",
.dragonfly => "dragonflybsd",
.illumos => "solaris",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +15 to +22
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),
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +392 to +403
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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's make an iterator for this


// Global settings
sdk_disabled: bool,
resource_detectors: ResourceDetectors,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@agagniere agagniere Aug 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

I realized that these should be enabled by default:

  1. Those attributes are marked as:
  2. "Required" and "Recommended" means enabled by default

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

@agagniere
agagniere marked this pull request as draft August 27, 2026 12:06
Comment thread opentelemetry-sdk/src/sdk/config.zig Outdated
@agagniere agagniere moved this from In review to In progress in Zig SIG Aug 28, 2026
Add a flag to control the inclusion of the SDK-related attributes

the env var parsing now handles:
- "" to mean default,
- "*" to mean all,
- "none" to disable all

Assisted-by: Opus 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants