diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0e5a731 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "opentelemetry-proto/proto-src"] + path = opentelemetry-proto/proto-src + url = https://github.com/open-telemetry/opentelemetry-proto.git + branch = main diff --git a/README.md b/README.md index 9ecabfe..0cfde76 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,7 @@

**[Zig docs]   •  ** -**[Installation](#installation)   •  ** -**[Features](#features)   •  ** -**[Examples](#examples)   •  ** +**[Modules](#modules)   •  ** **[Contributing](#contributing)   •  ** **[Community](#join-the-community)** @@ -31,142 +29,13 @@ The version of the OpenTelemetry specification targeted here is **1.48.0**. > [!IMPORTANT] > We are currently seeking additional contributors! See [help wanted](#help-wanted) for details. -## Installation +## Modules -Run the following command to add the package to your `build.zig.zon` dependencies, replacing `` with a release version: +This repository is organized as multiple self-contained modules, each in its own +top-level directory with its own README: -```shall -zig fetch --save "git+https://github.com/open-telemetry/opentelemetry-zig#" -``` - -Then in your `build.zig`: - -```zig -const sdk = b.dependency("opentelemetry-sdk", .{ - .target = target, - .optimize = optimize, -}); -``` - -## Specification Support State - -### Signals - -| Signal | Status | -|--------|--------| -| Traces | ✅ | -| Metrics | ✅ | -| Logs | ✅ | -| Profiles | ❌ | - -### OTLP Protocol - -| Feature | Status | -|---------|--------| -| HTTP/Protobuf | ✅ | -| HTTP/JSON | ✅ | -| gRPC | ❌ | -| Compression (gzip) | ✅ | - - -## Features - -### `std.log` Bridge for Seamless Migration - -The SDK includes a bridge that allows you to route Zig's standard `std.log` calls to OpenTelemetry without refactoring your entire codebase. This is perfect for gradual adoption of observability. - -**Quick Start:** - -```zig -const std = @import("std"); -const sdk = @import("opentelemetry-sdk"); - -// Override std.log to use OpenTelemetry -pub const std_options: std.Options = .{ - .logFn = sdk.logs.std_log_bridge.logFn, -}; - -pub fn main() !void { - var provider = try sdk.logs.LoggerProvider.init(allocator, null); - defer provider.deinit(); - - // Configure the bridge - try sdk.logs.std_log_bridge.configure(.{ - .provider = provider, - .also_log_to_stderr = true, // Dual mode: OTel + stderr - }); - defer sdk.logs.std_log_bridge.shutdown(); - - // Now std.log calls automatically go to OpenTelemetry! - std.log.info("Application started", .{}); -} -``` - -**Key Features:** -- **Dual-mode logging**: Send logs to both OpenTelemetry and stderr during migration -- **Thread-safe**: Safe for concurrent use across multiple threads -- **Scope strategies**: Single scope for all logs, or separate scopes per Zig module -- **Automatic severity mapping**: Zig log levels map to OpenTelemetry severity numbers -- **Source location tracking**: Optional file/line information as attributes - -See [examples/logs/std_log_basic.zig](./examples/logs/std_log_basic.zig) and [examples/logs/std_log_migration.zig](./examples/logs/std_log_migration.zig) for complete examples. - -## C Language Bindings - -The SDK provides C-compatible bindings, allowing C programs to use OpenTelemetry instrumentation. The C API covers all three signals: Traces, Metrics, and Logs. - -### Using from C - -1. **Link with the compiled library**: Build the Zig library and link it with your C project. - -2. **Include the header**: Add `include/opentelemetry.h` to your project. - -3. **Basic usage example**: - -```c -#include "opentelemetry.h" - -int main() { - // Create a meter provider - otel_meter_provider_t* provider = otel_meter_provider_create(); - - // Create an exporter and reader - otel_metric_exporter_t* exporter = otel_metric_exporter_stdout_create(); - otel_metric_reader_t* reader = otel_metric_reader_create(exporter); - otel_meter_provider_add_reader(provider, reader); - - // Get a meter - otel_meter_t* meter = otel_meter_provider_get_meter( - provider, "my-service", "1.0.0", NULL); - - // Create and use a counter - otel_counter_u64_t* counter = otel_meter_create_counter_u64( - meter, "requests", "Total requests", "1"); - otel_counter_add_u64(counter, 1, NULL, 0); - - // Collect and export metrics - otel_metric_reader_collect(reader); - - // Cleanup - otel_meter_provider_shutdown(provider); - return 0; -} -``` - -### C API Features - -- **Opaque handles**: All SDK objects are exposed as opaque handles for type safety -- **Memory management**: The C API manages memory internally using page allocators -- **Error handling**: Functions return status codes (0 for success, negative for errors) -- **Examples**: See `examples/c/` for complete examples of traces, metrics, and logs - -For detailed API documentation, refer to `include/opentelemetry.h`. - -## Examples - -Check out the [examples](./examples) folder for practical usage examples: -- `examples/` - Zig examples for traces, metrics, and logs -- `examples/c/` - C language examples demonstrating the C API bindings +- **[opentelemetry-sdk](./opentelemetry-sdk/README.md)** - the OpenTelemetry API and SDK: traces, metrics, logs, baggage, OTLP exporters, and C bindings. Start here for installation, features, and usage. +- **[opentelemetry-proto](./opentelemetry-proto/README.md)** - Zig protobuf bindings for the OpenTelemetry (OTLP) data model, generated from the official `.proto` definitions. ## Contributing diff --git a/build.zig b/build.zig index 4d265d2..baad013 100644 --- a/build.zig +++ b/build.zig @@ -2,6 +2,7 @@ const std = @import("std"); const zon = @import("build.zig.zon"); const helpers = @import("build/helpers.zig"); +const proto_build = @import("build/proto/build.zig"); const sdk_build = @import("build/sdk/build.zig"); pub fn build(b: *std.Build) !void { @@ -9,22 +10,16 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSafe }); const benchmarks_mod = b.dependency("zbench", .{}).module("zbench"); - - // OpenTelemetry proto package ships protobuf as a dependency so we'll use it. - const otel_pb_dep = b.dependency("opentelemetry_proto", .{}); - - const otel_proto_mod = otel_pb_dep.module("opentelemetry-proto"); - const protobuf_mod = otel_pb_dep.builder.dependency("protobuf", .{ + const protobuf_mod = b.dependency("protobuf", .{ .optimize = optimize, .target = target, }).module("protobuf"); - var sdk_build_mods = helpers.BuildModules.init(b.allocator); - defer sdk_build_mods.deinit(); + var build_mods = helpers.BuildModules.init(b.allocator); + defer build_mods.deinit(); - try sdk_build_mods.put("protobuf", protobuf_mod); - try sdk_build_mods.put("opentelemetry-proto", otel_proto_mod); - try sdk_build_mods.put("benchmark", benchmarks_mod); + try build_mods.put("protobuf", protobuf_mod); + try build_mods.put("benchmark", benchmarks_mod); const compilation_info = helpers.CompilationInfo{ .target = target, @@ -33,5 +28,7 @@ pub fn build(b: *std.Build) !void { .version = zon.version, }; - try sdk_build.Setup(b, compilation_info, &sdk_build_mods); + // proto exposes the "opentelemetry-proto" module the SDK imports so it needs to be built first. + try proto_build.Setup(b, compilation_info, &build_mods); + try sdk_build.Setup(b, compilation_info, &build_mods); } diff --git a/build.zig.zon b/build.zig.zon index 7f9bf20..4089011 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -27,15 +27,18 @@ .url = "git+https://github.com/hendriknielaender/zBench?ref=v0.13.0#b2b89c475e3ef1bb2bd71255c80478a82d3e0ca8", .hash = "zbench-0.13.0-YTdc7xVBAQCCMC-IdLLuotBeiNNNm8k9Pi2V4VYqrwfI", }, - .opentelemetry_proto = .{ - .url = "git+https://github.com/zig-o11y/opentelemetry-proto?ref=main#c43bd4c4db96fd839c594b7b701b44866b19457e", - .hash = "opentelemetry_proto-1.10.3-S4Y0u6zjAgBXl5JQ75DnsV5L2DsJeRzbgbYLSDTkl-f9", + // Consumed by the vendored opentelemetry-proto module (see + // build/proto/build.zig) and, transitively, by the SDK. + .protobuf = .{ + .url = "git+https://github.com/Arwalk/zig-protobuf?ref=v5.0.0#1f6cb06156b3ff4f52f98bc14f829c0b8393a6fc", + .hash = "protobuf-5.0.0-0e82avKUKAAVwTWJzTIEZ14Fu0zC11_lElR8tE6H__y1", }, }, .paths = .{ "build.zig", "build.zig.zon", "build", + "opentelemetry-proto", "opentelemetry-sdk", "LICENSE", "README.md", diff --git a/build/proto/build.zig b/build/proto/build.zig new file mode 100644 index 0000000..fc92b19 --- /dev/null +++ b/build/proto/build.zig @@ -0,0 +1,123 @@ +const std = @import("std"); +const protobuf = @import("protobuf"); +const helpers = @import("../helpers.zig"); + +const BuildError = helpers.BuildError; +const BuildModules = helpers.BuildModules; +const CompilationInfo = helpers.CompilationInfo; + +// Path of the vendored OpenTelemetry proto source root relative to build.zig. +const proto_root = "opentelemetry-proto"; + +// OpenTelemetry proto definitions to generate Zig bindings from, relative to +// the proto-src submodule root. Add entries here as the API grows. +const proto_files = [_][]const u8{ + // Signals + "opentelemetry/proto/common/v1/common.proto", + "opentelemetry/proto/resource/v1/resource.proto", + "opentelemetry/proto/metrics/v1/metrics.proto", + "opentelemetry/proto/trace/v1/trace.proto", + "opentelemetry/proto/logs/v1/logs.proto", + "opentelemetry/proto/profiles/v1development/profiles.proto", + // Collector types for OTLP + "opentelemetry/proto/collector/metrics/v1/metrics_service.proto", + "opentelemetry/proto/collector/trace/v1/trace_service.proto", + "opentelemetry/proto/collector/logs/v1/logs_service.proto", + "opentelemetry/proto/collector/profiles/v1development/profiles_service.proto", +}; + +// Sets up the opentelemetry-proto module from the vendored generated bindings +// and registers its build steps. The created module is added to `dependencies` +// so other modules (e.g. the SDK) can import it. +pub fn Setup( + b: *std.Build, + info: CompilationInfo, + dependencies: *BuildModules, +) !void { + const protobuf_mod = dependencies.get("protobuf") orelse return BuildError.ModuleNotFound; + + const proto_mod = b.addModule("opentelemetry-proto", .{ + .root_source_file = b.path(proto_root ++ "/src/root.zig"), + .target = info.target, + .optimize = info.optimize, + .imports = &.{ + .{ .name = "protobuf", .module = protobuf_mod }, + }, + }); + try dependencies.put("opentelemetry-proto", proto_mod); + + _ = try addTestStep(b, proto_mod); + _ = addUpdateTagStep(b); + try addGenerateStep(b, info); +} + +// Registers the "proto-generate" step, regenerating the Zig bindings under +// src/ from the proto-src submodule using protoc. Run it after updating +// the submodule (see the "update-tag" step). +fn addGenerateStep(b: *std.Build, info: CompilationInfo) !void { + // protoc code generation is driven by the protobuf dependency's builder. + const protobuf_dep = b.dependency("protobuf", .{ + .target = info.target, + .optimize = info.optimize, + }); + + var source_files: [proto_files.len]std.Build.LazyPath = undefined; + for (&source_files, proto_files) |*src, rel| { + src.* = b.path(b.pathJoin(&.{ proto_root, "proto-src", rel })); + } + + const protoc_step = protobuf.RunProtocStep.create(protobuf_dep.builder, info.target, .{ + .destination_directory = b.path(proto_root ++ "/src"), + .source_files = &source_files, + .include_directories = &.{ + // Imports in proto files resolve against the submodule root. + b.path(proto_root ++ "/proto-src"), + }, + }); + protoc_step.verbose = info.optimize == .Debug; + + const step = b.step("proto-generate", "Regenerate proto bindings from the proto-src submodule (requires protoc)"); + step.dependOn(&protoc_step.step); +} + +// Registers the "update-tag" step, moving the proto-src submodule (the official +// OpenTelemetry proto definitions) to a given tag, or the latest commit on its +// tracked branch. Regenerate the bindings from the updated submodule afterwards. +fn addUpdateTagStep(b: *std.Build) *std.Build.Step { + const tag = b.option([]const u8, "tag", + \\Tag of the OpenTelemetry proto submodule to check out. + \\If not set, the latest commit on the tracked branch (main) is used. + ); + + // Pull the latest commit on the submodule's tracked branch. + const update_remote = b.addSystemCommand(&.{ "git", "submodule", "update", "--remote" }); + + const update_step = b.step("proto-update-tag", "Update the OpenTelemetry proto submodule to -Dtag (or latest)"); + + if (tag) |t| { + const update_to_tag = b.addSystemCommand(&.{ + "git", "submodule", "foreach", + b.fmt("git checkout {s}", .{t}), + }); + update_to_tag.step.dependOn(&update_remote.step); + update_step.dependOn(&update_to_tag.step); + } else { + update_step.dependOn(&update_remote.step); + } + + return update_step; +} + +// Registers the "proto-test" step, building and running the proto unit tests. +fn addTestStep(b: *std.Build, proto_mod: *std.Build.Module) !*std.Build.Step { + const step = b.step("proto-test", "Run opentelemetry-proto unit tests"); + + const proto_tests = b.addTest(.{ + .root_module = proto_mod, + .filters = b.args orelse &[0][]const u8{}, + }); + const run_proto_tests = b.addRunArtifact(proto_tests); + step.dependOn(&run_proto_tests.step); + + return step; +} diff --git a/opentelemetry-proto/README.md b/opentelemetry-proto/README.md new file mode 100644 index 0000000..1d629ec --- /dev/null +++ b/opentelemetry-proto/README.md @@ -0,0 +1,59 @@ +## OpenTelemetry Protobuf Zig + +[OpenTelemetry Protobuf definitions](https://github.com/open-telemetry/opentelemetry-proto) +packaged for Zig. + +The generated Zig bindings under `src/` are committed and exposed as the +`opentelemetry-proto` module of the `opentelemetry-zig` package, wired into the +repo build by `build/proto/build.zig` (steps: `proto-test`, `proto-update-tag`, +`proto-generate`). + +### Import the package + +Fetch the `opentelemetry-zig` repository as a dependency: + +```bash +zig fetch --save "git+https://github.com/open-telemetry/opentelemetry-zig" +``` + +This adds an `opentelemetry` entry to your `build.zig.zon`. Wire the +`opentelemetry-proto` module into your artifact in `build.zig`: + +```zig +const otel = b.dependency("opentelemetry", .{}); +exe.root_module.addImport("opentelemetry-proto", otel.module("opentelemetry-proto")); +``` + +Then import the generated types in your code: + +```zig +const proto = @import("opentelemetry-proto"); +const trace = proto.trace_v1; +``` + +### Regenerating the bindings + +The `.proto` definitions live in the `proto-src` git submodule, which tracks the +`main` branch of the official +[open-telemetry/opentelemetry-proto](https://github.com/open-telemetry/opentelemetry-proto) +repository. After cloning, initialize it: + +```bash +git submodule update --init opentelemetry-proto/proto-src +``` + +To regenerate the bindings against a newer OpenTelemetry proto release (run from +the repo root; requires `protoc`): + +```bash +# Move the submodule to a specific tag (or omit -Dtag for the latest main). +zig build proto-update-tag -Dtag=vX.Y.Z +# Regenerate src/*.pb.zig from the submodule. +zig build proto-generate +``` + +Commit both the submodule bump and the regenerated `src/`. + +### Dependencies + +The [`zig-protobuf`](https://github.com/Arwalk/zig-protobuf/) library from @Arwalk. diff --git a/opentelemetry-proto/proto-src b/opentelemetry-proto/proto-src new file mode 160000 index 0000000..790608c --- /dev/null +++ b/opentelemetry-proto/proto-src @@ -0,0 +1 @@ +Subproject commit 790608c4d51e6ffc12210b541e8514cbed9e91a4 diff --git a/opentelemetry-proto/src/opentelemetry/proto/collector/logs/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/collector/logs/v1.pb.zig new file mode 100644 index 0000000..85229c1 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/collector/logs/v1.pb.zig @@ -0,0 +1,220 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.collector.logs.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.logs.v1 +const opentelemetry_proto_logs_v1 = @import("../../logs/v1.pb.zig"); + +pub const ExportLogsServiceRequest = struct { + resource_logs: std.ArrayList(opentelemetry_proto_logs_v1.ResourceLogs) = .empty, + + pub const _desc_table = .{ + .resource_logs = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportLogsServiceResponse = struct { + partial_success: ?ExportLogsPartialSuccess = null, + + pub const _desc_table = .{ + .partial_success = fd(1, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportLogsPartialSuccess = struct { + rejected_log_records: i64 = 0, + error_message: []const u8 = &.{}, + + pub const _desc_table = .{ + .rejected_log_records = fd(1, .{ .scalar = .int64 }), + .error_message = fd(2, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Service that can be used to push logs between one Application instrumented with +/// OpenTelemetry and an collector, or between an collector and a central collector (in this +/// case logs are sent/received to/from multiple Applications). +pub fn LogsService(comptime UserDataType: type, comptime ErrorSet: type) type { + return struct { + pub const package = "opentelemetry.proto.collector.logs.v1"; + pub const service_name = "LogsService"; + + Export: *const fn (userdata: *UserDataType, request: ExportLogsServiceRequest) ErrorSet!ExportLogsServiceResponse, + }; +} diff --git a/opentelemetry-proto/src/opentelemetry/proto/collector/metrics/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/collector/metrics/v1.pb.zig new file mode 100644 index 0000000..d167866 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/collector/metrics/v1.pb.zig @@ -0,0 +1,220 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.collector.metrics.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.metrics.v1 +const opentelemetry_proto_metrics_v1 = @import("../../metrics/v1.pb.zig"); + +pub const ExportMetricsServiceRequest = struct { + resource_metrics: std.ArrayList(opentelemetry_proto_metrics_v1.ResourceMetrics) = .empty, + + pub const _desc_table = .{ + .resource_metrics = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportMetricsServiceResponse = struct { + partial_success: ?ExportMetricsPartialSuccess = null, + + pub const _desc_table = .{ + .partial_success = fd(1, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportMetricsPartialSuccess = struct { + rejected_data_points: i64 = 0, + error_message: []const u8 = &.{}, + + pub const _desc_table = .{ + .rejected_data_points = fd(1, .{ .scalar = .int64 }), + .error_message = fd(2, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Service that can be used to push metrics between one Application +/// instrumented with OpenTelemetry and a collector, or between a collector and a +/// central collector. +pub fn MetricsService(comptime UserDataType: type, comptime ErrorSet: type) type { + return struct { + pub const package = "opentelemetry.proto.collector.metrics.v1"; + pub const service_name = "MetricsService"; + + Export: *const fn (userdata: *UserDataType, request: ExportMetricsServiceRequest) ErrorSet!ExportMetricsServiceResponse, + }; +} diff --git a/opentelemetry-proto/src/opentelemetry/proto/collector/profiles/v1development.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/collector/profiles/v1development.pb.zig new file mode 100644 index 0000000..06ae14c --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/collector/profiles/v1development.pb.zig @@ -0,0 +1,224 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.collector.profiles.v1development +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.profiles.v1development +const opentelemetry_proto_profiles_v1development = @import("../../profiles/v1development.pb.zig"); + +/// Status: [Alpha] +pub const ExportProfilesServiceRequest = struct { + resource_profiles: std.ArrayList(opentelemetry_proto_profiles_v1development.ResourceProfiles) = .empty, + dictionary: ?opentelemetry_proto_profiles_v1development.ProfilesDictionary = null, + + pub const _desc_table = .{ + .resource_profiles = fd(1, .{ .repeated = .submessage }), + .dictionary = fd(2, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Status: [Alpha] +pub const ExportProfilesServiceResponse = struct { + partial_success: ?ExportProfilesPartialSuccess = null, + + pub const _desc_table = .{ + .partial_success = fd(1, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Status: [Alpha] +pub const ExportProfilesPartialSuccess = struct { + rejected_profiles: i64 = 0, + error_message: []const u8 = &.{}, + + pub const _desc_table = .{ + .rejected_profiles = fd(1, .{ .scalar = .int64 }), + .error_message = fd(2, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Service that can be used to push profiles between one Application instrumented with +/// OpenTelemetry and a collector, or between a collector and a central collector. +pub fn ProfilesService(comptime UserDataType: type, comptime ErrorSet: type) type { + return struct { + pub const package = "opentelemetry.proto.collector.profiles.v1development"; + pub const service_name = "ProfilesService"; + + Export: *const fn (userdata: *UserDataType, request: ExportProfilesServiceRequest) ErrorSet!ExportProfilesServiceResponse, + }; +} diff --git a/opentelemetry-proto/src/opentelemetry/proto/collector/trace/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/collector/trace/v1.pb.zig new file mode 100644 index 0000000..08ea9cc --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/collector/trace/v1.pb.zig @@ -0,0 +1,220 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.collector.trace.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.trace.v1 +const opentelemetry_proto_trace_v1 = @import("../../trace/v1.pb.zig"); + +pub const ExportTraceServiceRequest = struct { + resource_spans: std.ArrayList(opentelemetry_proto_trace_v1.ResourceSpans) = .empty, + + pub const _desc_table = .{ + .resource_spans = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportTraceServiceResponse = struct { + partial_success: ?ExportTracePartialSuccess = null, + + pub const _desc_table = .{ + .partial_success = fd(1, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const ExportTracePartialSuccess = struct { + rejected_spans: i64 = 0, + error_message: []const u8 = &.{}, + + pub const _desc_table = .{ + .rejected_spans = fd(1, .{ .scalar = .int64 }), + .error_message = fd(2, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Service that can be used to push spans between one Application instrumented with +/// OpenTelemetry and a collector, or between a collector and a central collector (in this +/// case spans are sent/received to/from multiple Applications). +pub fn TraceService(comptime UserDataType: type, comptime ErrorSet: type) type { + return struct { + pub const package = "opentelemetry.proto.collector.trace.v1"; + pub const service_name = "TraceService"; + + Export: *const fn (userdata: *UserDataType, request: ExportTraceServiceRequest) ErrorSet!ExportTraceServiceResponse, + }; +} diff --git a/opentelemetry-proto/src/opentelemetry/proto/common/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/common/v1.pb.zig new file mode 100644 index 0000000..4656ef2 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/common/v1.pb.zig @@ -0,0 +1,467 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.common.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; + +/// Represents any type of attribute value. AnyValue may contain a +/// primitive value such as a string or integer or it may contain an arbitrary nested +/// object containing arrays, key-value lists and primitives. +pub const AnyValue = struct { + value: ?value_union = null, + + pub const _value_case = enum { + string_value, + bool_value, + int_value, + double_value, + array_value, + kvlist_value, + bytes_value, + string_value_strindex, + }; + pub const value_union = union(_value_case) { + string_value: []const u8, + bool_value: bool, + int_value: i64, + double_value: f64, + array_value: ArrayValue, + kvlist_value: KeyValueList, + bytes_value: []const u8, + string_value_strindex: i32, + pub const _desc_table = .{ + .string_value = fd(1, .{ .scalar = .string }), + .bool_value = fd(2, .{ .scalar = .bool }), + .int_value = fd(3, .{ .scalar = .int64 }), + .double_value = fd(4, .{ .scalar = .double }), + .array_value = fd(5, .submessage), + .kvlist_value = fd(6, .submessage), + .bytes_value = fd(7, .{ .scalar = .bytes }), + .string_value_strindex = fd(8, .{ .scalar = .int32 }), + }; + }; + + pub const _desc_table = .{ + .value = fd(null, .{ .oneof = value_union }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// ArrayValue is a list of AnyValue messages. We need ArrayValue as a message +/// since oneof in AnyValue does not allow repeated fields. +pub const ArrayValue = struct { + values: std.ArrayList(AnyValue) = .empty, + + pub const _desc_table = .{ + .values = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// KeyValueList is a list of KeyValue messages. We need KeyValueList as a message +/// since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need +/// a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to +/// avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches +/// are semantically equivalent. +pub const KeyValueList = struct { + values: std.ArrayList(KeyValue) = .empty, + + pub const _desc_table = .{ + .values = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Represents a key-value pair that is used to store Span attributes, Link +/// attributes, etc. +pub const KeyValue = struct { + key: []const u8 = &.{}, + value: ?AnyValue = null, + key_strindex: i32 = 0, + + pub const _desc_table = .{ + .key = fd(1, .{ .scalar = .string }), + .value = fd(2, .submessage), + .key_strindex = fd(3, .{ .scalar = .int32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// InstrumentationScope is a message representing the instrumentation scope information +/// such as the fully qualified name and version. +pub const InstrumentationScope = struct { + name: []const u8 = &.{}, + version: []const u8 = &.{}, + attributes: std.ArrayList(KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + + pub const _desc_table = .{ + .name = fd(1, .{ .scalar = .string }), + .version = fd(2, .{ .scalar = .string }), + .attributes = fd(3, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(4, .{ .scalar = .uint32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A reference to an Entity. +/// Entity represents an object of interest associated with produced telemetry: e.g spans, metrics, profiles, or logs. +/// +/// Status: [Development] +pub const EntityRef = struct { + schema_url: []const u8 = &.{}, + type: []const u8 = &.{}, + id_keys: std.ArrayList([]const u8) = .empty, + description_keys: std.ArrayList([]const u8) = .empty, + + pub const _desc_table = .{ + .schema_url = fd(1, .{ .scalar = .string }), + .type = fd(2, .{ .scalar = .string }), + .id_keys = fd(3, .{ .repeated = .{ .scalar = .string } }), + .description_keys = fd(4, .{ .repeated = .{ .scalar = .string } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/opentelemetry/proto/logs/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/logs/v1.pb.zig new file mode 100644 index 0000000..f3acf4a --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/logs/v1.pb.zig @@ -0,0 +1,359 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.logs.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.common.v1 +const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); +/// import package opentelemetry.proto.resource.v1 +const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); + +/// Possible values for LogRecord.SeverityNumber. +pub const SeverityNumber = enum(i32) { + SEVERITY_NUMBER_UNSPECIFIED = 0, + SEVERITY_NUMBER_TRACE = 1, + SEVERITY_NUMBER_TRACE2 = 2, + SEVERITY_NUMBER_TRACE3 = 3, + SEVERITY_NUMBER_TRACE4 = 4, + SEVERITY_NUMBER_DEBUG = 5, + SEVERITY_NUMBER_DEBUG2 = 6, + SEVERITY_NUMBER_DEBUG3 = 7, + SEVERITY_NUMBER_DEBUG4 = 8, + SEVERITY_NUMBER_INFO = 9, + SEVERITY_NUMBER_INFO2 = 10, + SEVERITY_NUMBER_INFO3 = 11, + SEVERITY_NUMBER_INFO4 = 12, + SEVERITY_NUMBER_WARN = 13, + SEVERITY_NUMBER_WARN2 = 14, + SEVERITY_NUMBER_WARN3 = 15, + SEVERITY_NUMBER_WARN4 = 16, + SEVERITY_NUMBER_ERROR = 17, + SEVERITY_NUMBER_ERROR2 = 18, + SEVERITY_NUMBER_ERROR3 = 19, + SEVERITY_NUMBER_ERROR4 = 20, + SEVERITY_NUMBER_FATAL = 21, + SEVERITY_NUMBER_FATAL2 = 22, + SEVERITY_NUMBER_FATAL3 = 23, + SEVERITY_NUMBER_FATAL4 = 24, + _, +}; + +/// LogRecordFlags represents constants used to interpret the +/// LogRecord.flags field, which is protobuf 'fixed32' type and is to +/// be used as bit-fields. Each non-zero value defined in this enum is +/// a bit-mask. To extract the bit-field, for example, use an +/// expression like: +/// +/// (logRecord.flags & LOG_RECORD_FLAGS_TRACE_FLAGS_MASK) +pub const LogRecordFlags = enum(i32) { + LOG_RECORD_FLAGS_DO_NOT_USE = 0, + LOG_RECORD_FLAGS_TRACE_FLAGS_MASK = 255, + _, +}; + +/// LogsData represents the logs data that can be stored in a persistent storage, +/// OR can be embedded by other protocols that transfer OTLP logs data but do not +/// implement the OTLP protocol. +/// +/// The main difference between this message and collector protocol is that +/// in this message there will not be any "control" or "metadata" specific to +/// OTLP protocol. +/// +/// When new fields are added into this message, the OTLP request MUST be updated +/// as well. +pub const LogsData = struct { + resource_logs: std.ArrayList(ResourceLogs) = .empty, + + pub const _desc_table = .{ + .resource_logs = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of ScopeLogs from a Resource. +pub const ResourceLogs = struct { + resource: ?opentelemetry_proto_resource_v1.Resource = null, + scope_logs: std.ArrayList(ScopeLogs) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .resource = fd(1, .submessage), + .scope_logs = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of Logs produced by a Scope. +pub const ScopeLogs = struct { + scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, + log_records: std.ArrayList(LogRecord) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .scope = fd(1, .submessage), + .log_records = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A log record according to OpenTelemetry Log Data Model: +/// https://github.com/open-telemetry/oteps/blob/main/text/logs/0097-log-data-model.md +pub const LogRecord = struct { + time_unix_nano: u64 = 0, + observed_time_unix_nano: u64 = 0, + severity_number: SeverityNumber = @enumFromInt(0), + severity_text: []const u8 = &.{}, + body: ?opentelemetry_proto_common_v1.AnyValue = null, + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + flags: u32 = 0, + trace_id: []const u8 = &.{}, + span_id: []const u8 = &.{}, + event_name: []const u8 = &.{}, + + pub const _desc_table = .{ + .time_unix_nano = fd(1, .{ .scalar = .fixed64 }), + .observed_time_unix_nano = fd(11, .{ .scalar = .fixed64 }), + .severity_number = fd(2, .@"enum"), + .severity_text = fd(3, .{ .scalar = .string }), + .body = fd(5, .submessage), + .attributes = fd(6, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(7, .{ .scalar = .uint32 }), + .flags = fd(8, .{ .scalar = .fixed32 }), + .trace_id = fd(9, .{ .scalar = .bytes }), + .span_id = fd(10, .{ .scalar = .bytes }), + .event_name = fd(12, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/opentelemetry/proto/metrics/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/metrics/v1.pb.zig new file mode 100644 index 0000000..66afa98 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/metrics/v1.pb.zig @@ -0,0 +1,1411 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.metrics.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.common.v1 +const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); +/// import package opentelemetry.proto.resource.v1 +const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); + +/// AggregationTemporality defines how a metric aggregator reports aggregated +/// values. It describes how those values relate to the time interval over +/// which they are aggregated. +pub const AggregationTemporality = enum(i32) { + AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, + AGGREGATION_TEMPORALITY_DELTA = 1, + AGGREGATION_TEMPORALITY_CUMULATIVE = 2, + _, +}; + +/// DataPointFlags is defined as a protobuf 'uint32' type and is to be used as a +/// bit-field representing 32 distinct boolean flags. Each flag defined in this +/// enum is a bit-mask. To test the presence of a single flag in the flags of +/// a data point, for example, use an expression like: +/// +/// (point.flags & DATA_POINT_FLAGS_NO_RECORDED_VALUE_MASK) == DATA_POINT_FLAGS_NO_RECORDED_VALUE_MASK +pub const DataPointFlags = enum(i32) { + DATA_POINT_FLAGS_DO_NOT_USE = 0, + DATA_POINT_FLAGS_NO_RECORDED_VALUE_MASK = 1, + _, +}; + +/// MetricsData represents the metrics data that can be stored in a persistent +/// storage, OR can be embedded by other protocols that transfer OTLP metrics +/// data but do not implement the OTLP protocol. +/// +/// MetricsData +/// └─── ResourceMetrics +/// ├── Resource +/// ├── SchemaURL +/// └── ScopeMetrics +/// ├── Scope +/// ├── SchemaURL +/// └── Metric +/// ├── Name +/// ├── Description +/// ├── Unit +/// └── data +/// ├── Gauge +/// ├── Sum +/// ├── Histogram +/// ├── ExponentialHistogram +/// └── Summary +/// +/// The main difference between this message and collector protocol is that +/// in this message there will not be any "control" or "metadata" specific to +/// OTLP protocol. +/// +/// When new fields are added into this message, the OTLP request MUST be updated +/// as well. +pub const MetricsData = struct { + resource_metrics: std.ArrayList(ResourceMetrics) = .empty, + + pub const _desc_table = .{ + .resource_metrics = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of ScopeMetrics from a Resource. +pub const ResourceMetrics = struct { + resource: ?opentelemetry_proto_resource_v1.Resource = null, + scope_metrics: std.ArrayList(ScopeMetrics) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .resource = fd(1, .submessage), + .scope_metrics = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of Metrics produced by an Scope. +pub const ScopeMetrics = struct { + scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, + metrics: std.ArrayList(Metric) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .scope = fd(1, .submessage), + .metrics = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Defines a Metric which has one or more timeseries. The following is a +/// brief summary of the Metric data model. For more details, see: +/// +/// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md +/// +/// The data model and relation between entities is shown in the +/// diagram below. Here, "DataPoint" is the term used to refer to any +/// one of the specific data point value types, and "points" is the term used +/// to refer to any one of the lists of points contained in the Metric. +/// +/// - Metric is composed of a metadata and data. +/// - Metadata part contains a name, description, unit. +/// - Data is one of the possible types (Sum, Gauge, Histogram, Summary). +/// - DataPoint contains timestamps, attributes, and one of the possible value type +/// fields. +/// +/// Metric +/// +------------+ +/// |name | +/// |description | +/// |unit | +------------------------------------+ +/// |data |---> |Gauge, Sum, Histogram, Summary, ... | +/// +------------+ +------------------------------------+ +/// +/// Data [One of Gauge, Sum, Histogram, Summary, ...] +/// +-----------+ +/// |... | // Metadata about the Data. +/// |points |--+ +/// +-----------+ | +/// | +---------------------------+ +/// | |DataPoint 1 | +/// v |+------+------+ +------+ | +/// +-----+ ||label |label |...|label | | +/// | 1 |-->||value1|value2|...|valueN| | +/// +-----+ |+------+------+ +------+ | +/// | . | |+-----+ | +/// | . | ||value| | +/// | . | |+-----+ | +/// | . | +---------------------------+ +/// | . | . +/// | . | . +/// | . | . +/// | . | +---------------------------+ +/// | . | |DataPoint M | +/// +-----+ |+------+------+ +------+ | +/// | M |-->||label |label |...|label | | +/// +-----+ ||value1|value2|...|valueN| | +/// |+------+------+ +------+ | +/// |+-----+ | +/// ||value| | +/// |+-----+ | +/// +---------------------------+ +/// +/// Each distinct type of DataPoint represents the output of a specific +/// aggregation function, the result of applying the DataPoint's +/// associated function of to one or more measurements. +/// +/// All DataPoint types have three common fields: +/// - Attributes includes key-value pairs associated with the data point +/// - TimeUnixNano is required, set to the end time of the aggregation +/// - StartTimeUnixNano is optional, but strongly encouraged for DataPoints +/// having an AggregationTemporality field, as discussed below. +/// +/// Both TimeUnixNano and StartTimeUnixNano values are expressed as +/// UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. +/// +/// # TimeUnixNano +/// +/// This field is required, having consistent interpretation across +/// DataPoint types. TimeUnixNano is the moment corresponding to when +/// the data point's aggregate value was captured. +/// +/// Data points with the 0 value for TimeUnixNano SHOULD be rejected +/// by consumers. +/// +/// # StartTimeUnixNano +/// +/// StartTimeUnixNano in general allows detecting when a sequence of +/// observations is unbroken. This field indicates to consumers the +/// start time for points with cumulative and delta +/// AggregationTemporality, and it should be included whenever possible +/// to support correct rate calculation. Although it may be omitted +/// when the start time is truly unknown, setting StartTimeUnixNano is +/// strongly encouraged. +pub const Metric = struct { + name: []const u8 = &.{}, + description: []const u8 = &.{}, + unit: []const u8 = &.{}, + metadata: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + data: ?data_union = null, + + pub const _data_case = enum { + gauge, + sum, + histogram, + exponential_histogram, + summary, + }; + pub const data_union = union(_data_case) { + gauge: Gauge, + sum: Sum, + histogram: Histogram, + exponential_histogram: ExponentialHistogram, + summary: Summary, + pub const _desc_table = .{ + .gauge = fd(5, .submessage), + .sum = fd(7, .submessage), + .histogram = fd(9, .submessage), + .exponential_histogram = fd(10, .submessage), + .summary = fd(11, .submessage), + }; + }; + + pub const _desc_table = .{ + .name = fd(1, .{ .scalar = .string }), + .description = fd(2, .{ .scalar = .string }), + .unit = fd(3, .{ .scalar = .string }), + .metadata = fd(12, .{ .repeated = .submessage }), + .data = fd(null, .{ .oneof = data_union }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Gauge represents the type of a scalar metric that always exports the +/// "current value" for every data point. It should be used for an "unknown" +/// aggregation. +/// +/// A Gauge does not support different aggregation temporalities. Given the +/// aggregation is unknown, points cannot be combined using the same +/// aggregation, regardless of aggregation temporalities. Therefore, +/// AggregationTemporality is not included. Consequently, this also means +/// "StartTimeUnixNano" is ignored for all data points. +pub const Gauge = struct { + data_points: std.ArrayList(NumberDataPoint) = .empty, + + pub const _desc_table = .{ + .data_points = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Sum represents the type of a scalar metric that is calculated as a sum of all +/// reported measurements over a time interval. +pub const Sum = struct { + data_points: std.ArrayList(NumberDataPoint) = .empty, + aggregation_temporality: AggregationTemporality = @enumFromInt(0), + is_monotonic: bool = false, + + pub const _desc_table = .{ + .data_points = fd(1, .{ .repeated = .submessage }), + .aggregation_temporality = fd(2, .@"enum"), + .is_monotonic = fd(3, .{ .scalar = .bool }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Histogram represents the type of a metric that is calculated by aggregating +/// as a Histogram of all reported measurements over a time interval. +pub const Histogram = struct { + data_points: std.ArrayList(HistogramDataPoint) = .empty, + aggregation_temporality: AggregationTemporality = @enumFromInt(0), + + pub const _desc_table = .{ + .data_points = fd(1, .{ .repeated = .submessage }), + .aggregation_temporality = fd(2, .@"enum"), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// ExponentialHistogram represents the type of a metric that is calculated by aggregating +/// as a ExponentialHistogram of all reported double measurements over a time interval. +pub const ExponentialHistogram = struct { + data_points: std.ArrayList(ExponentialHistogramDataPoint) = .empty, + aggregation_temporality: AggregationTemporality = @enumFromInt(0), + + pub const _desc_table = .{ + .data_points = fd(1, .{ .repeated = .submessage }), + .aggregation_temporality = fd(2, .@"enum"), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Summary metric data are used to convey quantile summaries, +/// a Prometheus (see: https://prometheus.io/docs/concepts/metric_types/#summary) +/// and OpenMetrics (see: https://github.com/prometheus/OpenMetrics/blob/4dbf6075567ab43296eed941037c12951faafb92/protos/prometheus.proto#L45) +/// data type. These data points cannot always be merged in a meaningful way. +/// While they can be useful in some applications, histogram data points are +/// recommended for new applications. +/// Summary metrics do not have an aggregation temporality field. This is +/// because the count and sum fields of a SummaryDataPoint are assumed to be +/// cumulative values. +pub const Summary = struct { + data_points: std.ArrayList(SummaryDataPoint) = .empty, + + pub const _desc_table = .{ + .data_points = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// NumberDataPoint is a single data point in a timeseries that describes the +/// time-varying scalar value of a metric. +pub const NumberDataPoint = struct { + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + start_time_unix_nano: u64 = 0, + time_unix_nano: u64 = 0, + exemplars: std.ArrayList(Exemplar) = .empty, + flags: u32 = 0, + value: ?value_union = null, + + pub const _value_case = enum { + as_double, + as_int, + }; + pub const value_union = union(_value_case) { + as_double: f64, + as_int: i64, + pub const _desc_table = .{ + .as_double = fd(4, .{ .scalar = .double }), + .as_int = fd(6, .{ .scalar = .sfixed64 }), + }; + }; + + pub const _desc_table = .{ + .attributes = fd(7, .{ .repeated = .submessage }), + .start_time_unix_nano = fd(2, .{ .scalar = .fixed64 }), + .time_unix_nano = fd(3, .{ .scalar = .fixed64 }), + .exemplars = fd(5, .{ .repeated = .submessage }), + .flags = fd(8, .{ .scalar = .uint32 }), + .value = fd(null, .{ .oneof = value_union }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// HistogramDataPoint is a single data point in a timeseries that describes the +/// time-varying values of a Histogram. A Histogram contains summary statistics +/// for a population of values, it may optionally contain the distribution of +/// those values across a set of buckets. +/// +/// If the histogram contains the distribution of values, then both +/// "explicit_bounds" and "bucket counts" fields must be defined. +/// If the histogram does not contain the distribution of values, then both +/// "explicit_bounds" and "bucket_counts" must be omitted and only "count" and +/// "sum" are known. +pub const HistogramDataPoint = struct { + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + start_time_unix_nano: u64 = 0, + time_unix_nano: u64 = 0, + count: u64 = 0, + sum: ?f64 = null, + bucket_counts: std.ArrayList(u64) = .empty, + explicit_bounds: std.ArrayList(f64) = .empty, + exemplars: std.ArrayList(Exemplar) = .empty, + flags: u32 = 0, + min: ?f64 = null, + max: ?f64 = null, + + pub const _desc_table = .{ + .attributes = fd(9, .{ .repeated = .submessage }), + .start_time_unix_nano = fd(2, .{ .scalar = .fixed64 }), + .time_unix_nano = fd(3, .{ .scalar = .fixed64 }), + .count = fd(4, .{ .scalar = .fixed64 }), + .sum = fd(5, .{ .scalar = .double }), + .bucket_counts = fd(6, .{ .packed_repeated = .{ .scalar = .fixed64 } }), + .explicit_bounds = fd(7, .{ .packed_repeated = .{ .scalar = .double } }), + .exemplars = fd(8, .{ .repeated = .submessage }), + .flags = fd(10, .{ .scalar = .uint32 }), + .min = fd(11, .{ .scalar = .double }), + .max = fd(12, .{ .scalar = .double }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// ExponentialHistogramDataPoint is a single data point in a timeseries that describes the +/// time-varying values of a ExponentialHistogram of double values. A ExponentialHistogram contains +/// summary statistics for a population of values, it may optionally contain the +/// distribution of those values across a set of buckets. +pub const ExponentialHistogramDataPoint = struct { + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + start_time_unix_nano: u64 = 0, + time_unix_nano: u64 = 0, + count: u64 = 0, + sum: ?f64 = null, + scale: i32 = 0, + zero_count: u64 = 0, + positive: ?ExponentialHistogramDataPoint.Buckets = null, + negative: ?ExponentialHistogramDataPoint.Buckets = null, + flags: u32 = 0, + exemplars: std.ArrayList(Exemplar) = .empty, + min: ?f64 = null, + max: ?f64 = null, + zero_threshold: f64 = 0, + + pub const _desc_table = .{ + .attributes = fd(1, .{ .repeated = .submessage }), + .start_time_unix_nano = fd(2, .{ .scalar = .fixed64 }), + .time_unix_nano = fd(3, .{ .scalar = .fixed64 }), + .count = fd(4, .{ .scalar = .fixed64 }), + .sum = fd(5, .{ .scalar = .double }), + .scale = fd(6, .{ .scalar = .sint32 }), + .zero_count = fd(7, .{ .scalar = .fixed64 }), + .positive = fd(8, .submessage), + .negative = fd(9, .submessage), + .flags = fd(10, .{ .scalar = .uint32 }), + .exemplars = fd(11, .{ .repeated = .submessage }), + .min = fd(12, .{ .scalar = .double }), + .max = fd(13, .{ .scalar = .double }), + .zero_threshold = fd(14, .{ .scalar = .double }), + }; + + /// Buckets are a set of bucket counts, encoded in a contiguous array + /// of counts. + pub const Buckets = struct { + offset: i32 = 0, + bucket_counts: std.ArrayList(u64) = .empty, + + pub const _desc_table = .{ + .offset = fd(1, .{ .scalar = .sint32 }), + .bucket_counts = fd(2, .{ .packed_repeated = .{ .scalar = .uint64 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// SummaryDataPoint is a single data point in a timeseries that describes the +/// time-varying values of a Summary metric. The count and sum fields represent +/// cumulative values. +pub const SummaryDataPoint = struct { + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + start_time_unix_nano: u64 = 0, + time_unix_nano: u64 = 0, + count: u64 = 0, + sum: f64 = 0, + quantile_values: std.ArrayList(SummaryDataPoint.ValueAtQuantile) = .empty, + flags: u32 = 0, + + pub const _desc_table = .{ + .attributes = fd(7, .{ .repeated = .submessage }), + .start_time_unix_nano = fd(2, .{ .scalar = .fixed64 }), + .time_unix_nano = fd(3, .{ .scalar = .fixed64 }), + .count = fd(4, .{ .scalar = .fixed64 }), + .sum = fd(5, .{ .scalar = .double }), + .quantile_values = fd(6, .{ .repeated = .submessage }), + .flags = fd(8, .{ .scalar = .uint32 }), + }; + + /// Represents the value at a given quantile of a distribution. + /// + /// To record Min and Max values following conventions are used: + /// - The 1.0 quantile is equivalent to the maximum value observed. + /// - The 0.0 quantile is equivalent to the minimum value observed. + /// + /// See the following issue for more context: + /// https://github.com/open-telemetry/opentelemetry-proto/issues/125 + pub const ValueAtQuantile = struct { + quantile: f64 = 0, + value: f64 = 0, + + pub const _desc_table = .{ + .quantile = fd(1, .{ .scalar = .double }), + .value = fd(2, .{ .scalar = .double }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A representation of an exemplar, which is a sample input measurement. +/// Exemplars also hold information about the environment when the measurement +/// was recorded, for example the span and trace ID of the active span when the +/// exemplar was recorded. +pub const Exemplar = struct { + filtered_attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + time_unix_nano: u64 = 0, + span_id: []const u8 = &.{}, + trace_id: []const u8 = &.{}, + value: ?value_union = null, + + pub const _value_case = enum { + as_double, + as_int, + }; + pub const value_union = union(_value_case) { + as_double: f64, + as_int: i64, + pub const _desc_table = .{ + .as_double = fd(3, .{ .scalar = .double }), + .as_int = fd(6, .{ .scalar = .sfixed64 }), + }; + }; + + pub const _desc_table = .{ + .filtered_attributes = fd(7, .{ .repeated = .submessage }), + .time_unix_nano = fd(2, .{ .scalar = .fixed64 }), + .span_id = fd(4, .{ .scalar = .bytes }), + .trace_id = fd(5, .{ .scalar = .bytes }), + .value = fd(null, .{ .oneof = value_union }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/opentelemetry/proto/profiles/v1development.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/profiles/v1development.pb.zig new file mode 100644 index 0000000..6b12efd --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/profiles/v1development.pb.zig @@ -0,0 +1,1133 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.profiles.v1development +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.common.v1 +const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); +/// import package opentelemetry.proto.resource.v1 +const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); + +/// ProfilesDictionary contains all the dictionary tables that are shared +/// across the entire ProfilesData message. +/// +/// The following applies to all fields in this message: +/// +/// - A dictionary is an array of dictionary items. Users of the dictionary +/// compactly reference the items using the index within the array. +/// +/// - The element at index 0 MUST be the zero value for the dictionary's element +/// type (e.g. `""` for `string_table`, `Location{}` for `location_table`). This +/// allows for _index fields pointing into the dictionary to use a 0 pointer +/// value to indicate 'null' / 'not set'. Unless otherwise defined, a 'zero +/// value' message value is one with all default field values, so as to +/// minimize wire encoded size. +/// +/// - There SHOULD NOT be duplicate items in a dictionary. The identity of a +/// dictionary item is based on its value, recursively as needed. If a particular +/// implementation does emit duplicate items, it MUST NOT attempt to give them +/// meaning based on the index or order. A profile processor MAY remove +/// duplicates and this MUST NOT have any observable effects for consumers. +/// +/// - There SHOULD NOT be orphaned (unreferenced) items in a dictionary. A +/// profile processor MAY remove ("garbage-collect") orphaned items and this +/// MUST NOT have any observable effects for consumers. +/// +/// Status: [Alpha] +pub const ProfilesDictionary = struct { + mapping_table: std.ArrayList(Mapping) = .empty, + location_table: std.ArrayList(Location) = .empty, + function_table: std.ArrayList(Function) = .empty, + link_table: std.ArrayList(Link) = .empty, + string_table: std.ArrayList([]const u8) = .empty, + attribute_table: std.ArrayList(KeyValueAndUnit) = .empty, + stack_table: std.ArrayList(Stack) = .empty, + + pub const _desc_table = .{ + .mapping_table = fd(1, .{ .repeated = .submessage }), + .location_table = fd(2, .{ .repeated = .submessage }), + .function_table = fd(3, .{ .repeated = .submessage }), + .link_table = fd(4, .{ .repeated = .submessage }), + .string_table = fd(5, .{ .repeated = .{ .scalar = .string } }), + .attribute_table = fd(6, .{ .repeated = .submessage }), + .stack_table = fd(7, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// ProfilesData represents the profiles data that can be stored in persistent storage, +/// OR can be embedded by other protocols that transfer OTLP profiles data but do not +/// implement the OTLP protocol. +/// +/// The main difference between this message and collector protocol is that +/// in this message there will not be any "control" or "metadata" specific to +/// OTLP protocol. +/// +/// When new fields are added into this message, the OTLP request MUST be updated +/// as well. +/// +/// Status: [Alpha] +pub const ProfilesData = struct { + resource_profiles: std.ArrayList(ResourceProfiles) = .empty, + dictionary: ?ProfilesDictionary = null, + + pub const _desc_table = .{ + .resource_profiles = fd(1, .{ .repeated = .submessage }), + .dictionary = fd(2, .submessage), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of ScopeProfiles from a Resource. +/// +/// Status: [Alpha] +pub const ResourceProfiles = struct { + resource: ?opentelemetry_proto_resource_v1.Resource = null, + scope_profiles: std.ArrayList(ScopeProfiles) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .resource = fd(1, .submessage), + .scope_profiles = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of Profiles produced by an InstrumentationScope. +/// +/// Status: [Alpha] +pub const ScopeProfiles = struct { + scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, + profiles: std.ArrayList(Profile) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .scope = fd(1, .submessage), + .profiles = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Represents a complete profile, including sample types, samples, mappings to +/// binaries, stacks, locations, functions, string table, and additional +/// metadata. It modifies and annotates pprof Profile with OpenTelemetry +/// specific fields. +/// +/// Status: [Alpha] +pub const Profile = struct { + sample_type: ?ValueType = null, + samples: std.ArrayList(Sample) = .empty, + time_unix_nano: u64 = 0, + duration_nano: u64 = 0, + period_type: ?ValueType = null, + period: i64 = 0, + profile_id: []const u8 = &.{}, + dropped_attributes_count: u32 = 0, + original_payload_format: []const u8 = &.{}, + original_payload: []const u8 = &.{}, + attribute_indices: std.ArrayList(i32) = .empty, + + pub const _desc_table = .{ + .sample_type = fd(1, .submessage), + .samples = fd(2, .{ .repeated = .submessage }), + .time_unix_nano = fd(3, .{ .scalar = .fixed64 }), + .duration_nano = fd(4, .{ .scalar = .uint64 }), + .period_type = fd(5, .submessage), + .period = fd(6, .{ .scalar = .int64 }), + .profile_id = fd(7, .{ .scalar = .bytes }), + .dropped_attributes_count = fd(8, .{ .scalar = .uint32 }), + .original_payload_format = fd(9, .{ .scalar = .string }), + .original_payload = fd(10, .{ .scalar = .bytes }), + .attribute_indices = fd(11, .{ .packed_repeated = .{ .scalar = .int32 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A pointer from a profile Sample to a trace Span. +/// Connects a profile sample to a trace span, identified by unique trace and span IDs. +/// +/// Status: [Alpha] +pub const Link = struct { + trace_id: []const u8 = &.{}, + span_id: []const u8 = &.{}, + + pub const _desc_table = .{ + .trace_id = fd(1, .{ .scalar = .bytes }), + .span_id = fd(2, .{ .scalar = .bytes }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// ValueType describes the type and units of a value. +/// +/// Status: [Alpha] +pub const ValueType = struct { + type_strindex: i32 = 0, + unit_strindex: i32 = 0, + + pub const _desc_table = .{ + .type_strindex = fd(1, .{ .scalar = .int32 }), + .unit_strindex = fd(2, .{ .scalar = .int32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Each Sample records values encountered in some program context. The program +/// context is typically a stack trace, perhaps augmented with auxiliary +/// information like the thread-id, some indicator of a higher level request +/// being handled etc. +/// +/// A Sample MUST have have at least one entry in values or timestamps_unix_nano. +/// If both fields are populated, they MUST contain the same number of elements, +/// and the elements at the same index MUST refer to the same event. +/// +/// For the purposes of efficiently representing aggregated data observations, a Sample is regarded +/// as having a shared identity and an associated collection of per-observation data points. +/// A Sample's identity (i.e. primary key) is the tuple of {stack_index, set_of(attribute_indices), link_index}. +/// Samples having the same identity SHOULD be combined by appending timestamps and values to the data arrays. +/// +/// Examples of different ways ('shapes') of representing a sample with the total value of 10: +/// +/// Timestamps only (consumers must assume the value is 1 for each timestamp): +/// values: [] +/// timestamps_unix_nano: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +/// +/// Single aggregated value without timestamps (one element representing the total): +/// values: [10] +/// timestamps_unix_nano: [] +/// +/// Per-timestamp value (each point in time records a specific value): +/// values: [2, 2, 3, 3] +/// timestamps_unix_nano: [1, 2, 3, 4] +/// +/// All Samples for a Profile SHOULD have the same shape, i.e. all data observation series should consistently +/// adopt the same data recording style. +/// +/// Status: [Alpha] +pub const Sample = struct { + stack_index: i32 = 0, + attribute_indices: std.ArrayList(i32) = .empty, + link_index: i32 = 0, + values: std.ArrayList(i64) = .empty, + timestamps_unix_nano: std.ArrayList(u64) = .empty, + + pub const _desc_table = .{ + .stack_index = fd(1, .{ .scalar = .int32 }), + .attribute_indices = fd(2, .{ .packed_repeated = .{ .scalar = .int32 } }), + .link_index = fd(3, .{ .scalar = .int32 }), + .values = fd(4, .{ .packed_repeated = .{ .scalar = .int64 } }), + .timestamps_unix_nano = fd(5, .{ .packed_repeated = .{ .scalar = .fixed64 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Describes the mapping of a binary in memory, including its address range, +/// file offset, and metadata like build ID +/// +/// Status: [Alpha] +pub const Mapping = struct { + memory_start: u64 = 0, + memory_limit: u64 = 0, + file_offset: u64 = 0, + filename_strindex: i32 = 0, + attribute_indices: std.ArrayList(i32) = .empty, + + pub const _desc_table = .{ + .memory_start = fd(1, .{ .scalar = .uint64 }), + .memory_limit = fd(2, .{ .scalar = .uint64 }), + .file_offset = fd(3, .{ .scalar = .uint64 }), + .filename_strindex = fd(4, .{ .scalar = .int32 }), + .attribute_indices = fd(5, .{ .packed_repeated = .{ .scalar = .int32 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A Stack represents a stack trace as a list of locations (leaf first). +/// For example, the stack trace resulting from the call stack +/// main -> foo -> bar would be encoded into the location_indices list +/// [2, 1, 0] which references the locations in location_table as: +/// [Location{"main"}, Location{"foo"}, Location{"bar"}]. +/// +/// Status: [Alpha] +pub const Stack = struct { + location_indices: std.ArrayList(i32) = .empty, + + pub const _desc_table = .{ + .location_indices = fd(1, .{ .packed_repeated = .{ .scalar = .int32 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Contains function and line table debug information for a single frame. +/// +/// Status: [Alpha] +pub const Location = struct { + mapping_index: i32 = 0, + address: u64 = 0, + lines: std.ArrayList(Line) = .empty, + attribute_indices: std.ArrayList(i32) = .empty, + + pub const _desc_table = .{ + .mapping_index = fd(1, .{ .scalar = .int32 }), + .address = fd(2, .{ .scalar = .uint64 }), + .lines = fd(3, .{ .repeated = .submessage }), + .attribute_indices = fd(4, .{ .packed_repeated = .{ .scalar = .int32 } }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Details a specific line in a source code, linked to a function. +/// +/// Status: [Alpha] +pub const Line = struct { + function_index: i32 = 0, + line: i64 = 0, + column: i64 = 0, + + pub const _desc_table = .{ + .function_index = fd(1, .{ .scalar = .int32 }), + .line = fd(2, .{ .scalar = .int64 }), + .column = fd(3, .{ .scalar = .int64 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// Describes a function, including its human-readable name, system name, +/// source file, and starting line number in the source. At least one of +/// {name_strindex, system_name_strindex, filename_strindex} MUST be present. +/// +/// Status: [Alpha] +pub const Function = struct { + name_strindex: i32 = 0, + system_name_strindex: i32 = 0, + filename_strindex: i32 = 0, + start_line: i64 = 0, + + pub const _desc_table = .{ + .name_strindex = fd(1, .{ .scalar = .int32 }), + .system_name_strindex = fd(2, .{ .scalar = .int32 }), + .filename_strindex = fd(3, .{ .scalar = .int32 }), + .start_line = fd(4, .{ .scalar = .int64 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A custom 'dictionary native' style of encoding attributes which is more convenient +/// for profiles than opentelemetry.proto.common.v1.KeyValue +/// Specifically, uses the ProfilesDictionary.string_table for keys +/// and allows optional unit information. +/// +/// Status: [Alpha] +pub const KeyValueAndUnit = struct { + key_strindex: i32 = 0, + value: ?opentelemetry_proto_common_v1.AnyValue = null, + unit_strindex: i32 = 0, + + pub const _desc_table = .{ + .key_strindex = fd(1, .{ .scalar = .int32 }), + .value = fd(2, .submessage), + .unit_strindex = fd(3, .{ .scalar = .int32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/opentelemetry/proto/resource/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/resource/v1.pb.zig new file mode 100644 index 0000000..23414f6 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/resource/v1.pb.zig @@ -0,0 +1,79 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.resource.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.common.v1 +const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); + +/// Resource information. +pub const Resource = struct { + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + entity_refs: std.ArrayList(opentelemetry_proto_common_v1.EntityRef) = .empty, + + pub const _desc_table = .{ + .attributes = fd(1, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(2, .{ .scalar = .uint32 }), + .entity_refs = fd(3, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/opentelemetry/proto/trace/v1.pb.zig b/opentelemetry-proto/src/opentelemetry/proto/trace/v1.pb.zig new file mode 100644 index 0000000..2583df4 --- /dev/null +++ b/opentelemetry-proto/src/opentelemetry/proto/trace/v1.pb.zig @@ -0,0 +1,594 @@ +// Code generated by protoc-gen-zig +///! package opentelemetry.proto.trace.v1 +const std = @import("std"); + +const protobuf = @import("protobuf"); +const fd = protobuf.fd; +/// import package opentelemetry.proto.common.v1 +const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); +/// import package opentelemetry.proto.resource.v1 +const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); + +/// SpanFlags represents constants used to interpret the +/// Span.flags field, which is protobuf 'fixed32' type and is to +/// be used as bit-fields. Each non-zero value defined in this enum is +/// a bit-mask. To extract the bit-field, for example, use an +/// expression like: +/// +/// (span.flags & SPAN_FLAGS_TRACE_FLAGS_MASK) +/// +/// See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. +/// +/// Note that Span flags were introduced in version 1.1 of the +/// OpenTelemetry protocol. Older Span producers do not set this +/// field, consequently consumers should not rely on the absence of a +/// particular flag bit to indicate the presence of a particular feature. +pub const SpanFlags = enum(i32) { + SPAN_FLAGS_DO_NOT_USE = 0, + SPAN_FLAGS_TRACE_FLAGS_MASK = 255, + SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 256, + SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 512, + _, +}; + +/// TracesData represents the traces data that can be stored in a persistent storage, +/// OR can be embedded by other protocols that transfer OTLP traces data but do +/// not implement the OTLP protocol. +/// +/// The main difference between this message and collector protocol is that +/// in this message there will not be any "control" or "metadata" specific to +/// OTLP protocol. +/// +/// When new fields are added into this message, the OTLP request MUST be updated +/// as well. +pub const TracesData = struct { + resource_spans: std.ArrayList(ResourceSpans) = .empty, + + pub const _desc_table = .{ + .resource_spans = fd(1, .{ .repeated = .submessage }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of ScopeSpans from a Resource. +pub const ResourceSpans = struct { + resource: ?opentelemetry_proto_resource_v1.Resource = null, + scope_spans: std.ArrayList(ScopeSpans) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .resource = fd(1, .submessage), + .scope_spans = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A collection of Spans produced by an InstrumentationScope. +pub const ScopeSpans = struct { + scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, + spans: std.ArrayList(Span) = .empty, + schema_url: []const u8 = &.{}, + + pub const _desc_table = .{ + .scope = fd(1, .submessage), + .spans = fd(2, .{ .repeated = .submessage }), + .schema_url = fd(3, .{ .scalar = .string }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// A Span represents a single operation performed by a single component of the system. +/// +/// The next available field id is 17. +pub const Span = struct { + trace_id: []const u8 = &.{}, + span_id: []const u8 = &.{}, + trace_state: []const u8 = &.{}, + parent_span_id: []const u8 = &.{}, + flags: u32 = 0, + name: []const u8 = &.{}, + kind: Span.SpanKind = @enumFromInt(0), + start_time_unix_nano: u64 = 0, + end_time_unix_nano: u64 = 0, + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + events: std.ArrayList(Span.Event) = .empty, + dropped_events_count: u32 = 0, + links: std.ArrayList(Span.Link) = .empty, + dropped_links_count: u32 = 0, + status: ?Status = null, + + pub const _desc_table = .{ + .trace_id = fd(1, .{ .scalar = .bytes }), + .span_id = fd(2, .{ .scalar = .bytes }), + .trace_state = fd(3, .{ .scalar = .string }), + .parent_span_id = fd(4, .{ .scalar = .bytes }), + .flags = fd(16, .{ .scalar = .fixed32 }), + .name = fd(5, .{ .scalar = .string }), + .kind = fd(6, .@"enum"), + .start_time_unix_nano = fd(7, .{ .scalar = .fixed64 }), + .end_time_unix_nano = fd(8, .{ .scalar = .fixed64 }), + .attributes = fd(9, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(10, .{ .scalar = .uint32 }), + .events = fd(11, .{ .repeated = .submessage }), + .dropped_events_count = fd(12, .{ .scalar = .uint32 }), + .links = fd(13, .{ .repeated = .submessage }), + .dropped_links_count = fd(14, .{ .scalar = .uint32 }), + .status = fd(15, .submessage), + }; + + /// SpanKind is the type of span. Can be used to specify additional relationships between spans + /// in addition to a parent/child relationship. + pub const SpanKind = enum(i32) { + SPAN_KIND_UNSPECIFIED = 0, + SPAN_KIND_INTERNAL = 1, + SPAN_KIND_SERVER = 2, + SPAN_KIND_CLIENT = 3, + SPAN_KIND_PRODUCER = 4, + SPAN_KIND_CONSUMER = 5, + _, + }; + + /// Event is a time-stamped annotation of the span, consisting of user-supplied + /// text description and key-value pairs. + pub const Event = struct { + time_unix_nano: u64 = 0, + name: []const u8 = &.{}, + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + + pub const _desc_table = .{ + .time_unix_nano = fd(1, .{ .scalar = .fixed64 }), + .name = fd(2, .{ .scalar = .string }), + .attributes = fd(3, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(4, .{ .scalar = .uint32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } + }; + + /// A pointer from the current span to another span in the same trace or in a + /// different trace. For example, this can be used in batching operations, + /// where a single batch handler processes multiple requests from different + /// traces or when the handler receives a request from a different project. + pub const Link = struct { + trace_id: []const u8 = &.{}, + span_id: []const u8 = &.{}, + trace_state: []const u8 = &.{}, + attributes: std.ArrayList(opentelemetry_proto_common_v1.KeyValue) = .empty, + dropped_attributes_count: u32 = 0, + flags: u32 = 0, + + pub const _desc_table = .{ + .trace_id = fd(1, .{ .scalar = .bytes }), + .span_id = fd(2, .{ .scalar = .bytes }), + .trace_state = fd(3, .{ .scalar = .string }), + .attributes = fd(4, .{ .repeated = .submessage }), + .dropped_attributes_count = fd(5, .{ .scalar = .uint32 }), + .flags = fd(6, .{ .scalar = .fixed32 }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +/// The Status type defines a logical error model that is suitable for different +/// programming environments, including REST APIs and RPC APIs. +pub const Status = struct { + message: []const u8 = &.{}, + code: Status.StatusCode = @enumFromInt(0), + + pub const _desc_table = .{ + .message = fd(2, .{ .scalar = .string }), + .code = fd(3, .@"enum"), + }; + + /// For the semantics of status codes see + /// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status + pub const StatusCode = enum(i32) { + STATUS_CODE_UNSET = 0, + STATUS_CODE_OK = 1, + STATUS_CODE_ERROR = 2, + _, + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; diff --git a/opentelemetry-proto/src/root.zig b/opentelemetry-proto/src/root.zig new file mode 100644 index 0000000..8a310dc --- /dev/null +++ b/opentelemetry-proto/src/root.zig @@ -0,0 +1,12 @@ +pub const common_v1 = @import("./opentelemetry/proto/common/v1.pb.zig"); +pub const resource_v1 = @import("./opentelemetry/proto/resource/v1.pb.zig"); + +pub const collector_logs_v1 = @import("./opentelemetry/proto/collector/logs/v1.pb.zig"); +pub const collector_metrics_v1 = @import("./opentelemetry/proto/collector/metrics/v1.pb.zig"); +pub const collector_trace_v1 = @import("./opentelemetry/proto/collector/trace/v1.pb.zig"); + +pub const logs_v1 = @import("./opentelemetry/proto/logs/v1.pb.zig"); +pub const metrics_v1 = @import("./opentelemetry/proto/metrics/v1.pb.zig"); +pub const trace_v1 = @import("./opentelemetry/proto/trace/v1.pb.zig"); + +pub const profiles_v1development = @import("./opentelemetry/proto/profiles/v1development.pb.zig"); diff --git a/opentelemetry-sdk/README.md b/opentelemetry-sdk/README.md new file mode 100644 index 0000000..50a927b --- /dev/null +++ b/opentelemetry-sdk/README.md @@ -0,0 +1,159 @@ +## OpenTelemetry SDK for Zig + +The `opentelemetry-sdk` module: Zig implementations of the OpenTelemetry API and +SDK for traces, metrics, and logs, with OTLP and stdout exporters and C bindings. + +It is wired into the repo build by `build/sdk/build.zig` and exposed as the `sdk` +module of the `opentelemetry-zig` package. + +## Installation + +Run the following command to add the package to your `build.zig.zon` dependencies, replacing `` with a release version or branch name: + +```bash +zig fetch --save "git+https://github.com/open-telemetry/opentelemetry-zig#" +``` + +This adds an `opentelemetry` entry to your `build.zig.zon`. Then in your `build.zig`, import the `sdk` module: + +```zig +const otel = b.dependency("opentelemetry", .{}); +exe.root_module.addImport("opentelemetry-sdk", otel.module("sdk")); +``` + +And use it in your code: + +```zig +const sdk = @import("opentelemetry-sdk"); +``` + +## Specification Support State + +### Signals + +| Signal | Status | +|--------|--------| +| Traces | ✅ | +| Metrics | ✅ | +| Logs | ✅ | +| Profiles | ❌ | + +### OTLP Protocol + +| Feature | Status | +|---------|--------| +| HTTP/Protobuf | ✅ | +| HTTP/JSON | ✅ | +| gRPC | ❌ | +| Compression (gzip) | ✅ | + + +## Features + +### `std.log` Bridge for Seamless Migration + +The SDK includes a bridge that allows you to route Zig's standard `std.log` calls to OpenTelemetry without refactoring your entire codebase. This is perfect for gradual adoption of observability. + +**Quick Start:** + +```zig +const std = @import("std"); +const sdk = @import("opentelemetry-sdk"); + +// Override std.log to use OpenTelemetry +pub const std_options: std.Options = .{ + .logFn = sdk.logs.std_log_bridge.logFn, +}; + +pub fn main() !void { + var provider = try sdk.logs.LoggerProvider.init(allocator, null); + defer provider.deinit(); + + // Configure the bridge + try sdk.logs.std_log_bridge.configure(.{ + .provider = provider, + .also_log_to_stderr = true, // Dual mode: OTel + stderr + }); + defer sdk.logs.std_log_bridge.shutdown(); + + // Now std.log calls automatically go to OpenTelemetry! + std.log.info("Application started", .{}); +} +``` + +**Key Features:** +- **Dual-mode logging**: Send logs to both OpenTelemetry and stderr during migration +- **Thread-safe**: Safe for concurrent use across multiple threads +- **Scope strategies**: Single scope for all logs, or separate scopes per Zig module +- **Automatic severity mapping**: Zig log levels map to OpenTelemetry severity numbers +- **Source location tracking**: Optional file/line information as attributes + +See [examples/logs/std_log_basic.zig](./examples/logs/std_log_basic.zig) and [examples/logs/std_log_migration.zig](./examples/logs/std_log_migration.zig) for complete examples. + +## C Language Bindings + +The SDK provides C-compatible bindings, allowing C programs to use OpenTelemetry instrumentation. The C API covers all three signals: Traces, Metrics, and Logs. + +### Using from C + +1. **Link with the compiled library**: Build the Zig library and link it with your C project. + +2. **Include the header**: Add `include/opentelemetry.h` to your project. + +3. **Basic usage example**: + +```c +#include "opentelemetry.h" + +int main() { + // Create a meter provider + otel_meter_provider_t* provider = otel_meter_provider_create(); + + // Create an exporter and reader + otel_metric_exporter_t* exporter = otel_metric_exporter_stdout_create(); + otel_metric_reader_t* reader = otel_metric_reader_create(exporter); + otel_meter_provider_add_reader(provider, reader); + + // Get a meter + otel_meter_t* meter = otel_meter_provider_get_meter( + provider, "my-service", "1.0.0", NULL); + + // Create and use a counter + otel_counter_u64_t* counter = otel_meter_create_counter_u64( + meter, "requests", "Total requests", "1"); + otel_counter_add_u64(counter, 1, NULL, 0); + + // Collect and export metrics + otel_metric_reader_collect(reader); + + // Cleanup + otel_meter_provider_shutdown(provider); + return 0; +} +``` + +### C API Features + +- **Opaque handles**: All SDK objects are exposed as opaque handles for type safety +- **Memory management**: The C API manages memory internally using page allocators +- **Error handling**: Functions return status codes (0 for success, negative for errors) +- **Examples**: See `examples/c/` for complete examples of traces, metrics, and logs + +For detailed API documentation, refer to `include/opentelemetry.h`. + +## Examples + +Check out the [examples](./examples) folder for practical usage examples: +- `examples/` - Zig examples for traces, metrics, and logs +- `examples/c/` - C language examples demonstrating the C API bindings + +## Layout + +- `src/` - API and SDK implementations (traces, metrics, logs, OTLP, C bindings) +- `include/opentelemetry.h` - C API header +- `examples/` - Zig and C usage examples +- `benchmarks/` - benchmarks +- `integration_tests/` - Docker-based integration tests +- `docs/` - design docs (e.g. `logs-emit-flow.md`) + +The SDK build steps (`sdk-test`, `sdk-examples`, `sdk-benchmarks`, `sdk-integration`, `sdk-docs`) are documented in [CONTRIBUTING.md](../CONTRIBUTING.md).