Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ pub fn build(b: *std.Build) !void {
},
});

{ // Build info
const build_info = b.addOptions();
build_info.addOption([]const u8, "version", zon.version);
build_info.addOption([]const u8, "name", @tagName(zon.name));
sdk_mod.addOptions("build_info", build_info);
}

// Static library for the OpenTelemetry SDK C users
const sdk_c_lib_mod = b.createModule(.{
.root_source_file = b.path("src/c.zig"),
Expand All @@ -66,6 +59,14 @@ pub fn build(b: *std.Build) !void {
.{ .name = "clock", .module = clock_mod },
},
});
{ // Build info
const build_info = b.addOptions();
build_info.addOption([]const u8, "version", zon.version);
build_info.addOption([]const u8, "name", @tagName(zon.name));
sdk_mod.addOptions("build_info", build_info);
sdk_c_lib_mod.addOptions("build_info", build_info);
}

const sdk_lib = b.addLibrary(.{
.name = "opentelemetry-sdk",
.linkage = .static,
Expand Down
24 changes: 24 additions & 0 deletions src/sdk/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
service_name: ?[]const u8,
resource_attributes: ?[]const u8,
log_level: LogLevel,
Expand Down Expand Up @@ -308,6 +316,7 @@ pub fn init(allocator: std.mem.Allocator, env_map: *const EnvMap) !*Configuratio
cfg.* = Configuration{
.allocator = allocator,
.sdk_disabled = parseBool(env_map, "OTEL_SDK_DISABLED") orelse false,
.resource_detectors = parseResourceDetectors(env_map),
.service_name = if (env_map.get("OTEL_SERVICE_NAME")) |s|
try allocator.dupe(u8, s)
else
Expand Down Expand Up @@ -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;
}

/// Parse comma-separated list of propagators
/// Default: "tracecontext,baggage"
fn parsePropagators(env_map: *const EnvMap, allocator: std.mem.Allocator) ![]const TracePropagator {
Expand Down
6 changes: 6 additions & 0 deletions src/sdk/propagation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ test "PropagatorRegistry initialization with baggage" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand All @@ -198,6 +199,7 @@ test "PropagatorRegistry initialization with multiple propagators" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand All @@ -220,6 +222,7 @@ test "PropagatorRegistry with none" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand All @@ -241,6 +244,7 @@ test "CompositePropagator inject and extract baggage" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand Down Expand Up @@ -287,6 +291,7 @@ test "CompositePropagator with baggage disabled" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand Down Expand Up @@ -324,6 +329,7 @@ test "CompositePropagator fields list" {
var config = Configuration{
.allocator = allocator,
.sdk_disabled = false,
.resource_detectors = .{},
.service_name = null,
.resource_attributes = null,
.log_level = .info,
Expand Down
Loading
Loading