Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics: isolate protobuf dependency #14

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
18 changes: 2 additions & 16 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
const std = @import("std");
const protobuf = @import("protobuf");

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {

// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

// Protobuf code generation from the OpenTelemetry proto files.
Expand All @@ -40,7 +28,7 @@ pub fn build(b: *std.Build) void {
},
});

// debug protoc generation
// Debug protoc generation in all builds
protoc_step.verbose = true;

const gen_proto = b.step("gen-proto", "Generates Zig files from protobuf definitions");
Expand All @@ -57,9 +45,6 @@ pub fn build(b: *std.Build) void {

sdk_lib.root_module.addImport("protobuf", protobuf_dep.module("protobuf"));

// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(sdk_lib);

// Providing a way for the user to request running the unit tests.
Expand All @@ -71,6 +56,7 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/sdk.zig"),
.target = target,
.optimize = optimize,
// Allow passing test filter using the build args.
.filters = b.args orelse &[0][]const u8{},
});
sdk_unit_tests.root_module.addImport("protobuf", protobuf_dep.module("protobuf"));
Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
"examples",
"LICENSE",
"README.md",
},
}
5 changes: 2 additions & 3 deletions examples/metrics/basic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub fn main() !void {
var in_mem = try sdk.InMemoryExporter.init(fba.allocator());

// Create an exporter and a a metric reader to aggregate the metrics
const exporter = try sdk.MetricExporter.new(fba.allocator(), &in_mem.exporter);
const mr = try sdk.MetricReader.init(fba.allocator(), exporter);
const mr = try sdk.MetricReader.init(fba.allocator(), &in_mem.exporter);
defer mr.shutdown();

// Register the metric reader to the meter provider
Expand All @@ -40,7 +39,7 @@ pub fn main() !void {

// Print the metrics
const stored_metrics = try in_mem.fetch();
defer stored_metrics.deinit();
defer fba.allocator().free(stored_metrics);

std.debug.print("metric: {any}\n", .{stored_metrics});
}
5 changes: 1 addition & 4 deletions examples/metrics/http_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ fn setupTelemetry(allocator: std.mem.Allocator) !OTel {
var in_mem = try sdk.InMemoryExporter.init(allocator);
errdefer in_mem.deinit();

const exporter = try sdk.MetricExporter.new(allocator, &in_mem.exporter);
errdefer exporter.shutdown();

const mr = try sdk.MetricReader.init(allocator, exporter);
const mr = try sdk.MetricReader.init(allocator, &in_mem.exporter);

try mp.addReader(mr);

Expand Down
Loading