diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b25c548c..e2ac881a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,8 +42,7 @@ jobs: allow-prerelease-opam: true - run: | - opam pin ocaml-protoc 3.0.1 -y -n - opam pin pbrt 3.0.1 -y -n + opam pin https://github.com/mransan/ocaml-protoc.git#5510694deffde13283742b8ad116fab61b65dfbc -y -n opam install pbrt -y # We cannot install packages that need eio on ocaml versions before 5 diff --git a/Makefile b/Makefile index f769d8f1..4291a68f 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ clean: @dune clean protoc-gen: - FORCE_GENPROTO=true @dune build @lint + FORCE_GENPROTO=true dune build @lint format: @dune build @fmt --auto-promote diff --git a/dune-project b/dune-project index 0b782996..41ba5911 100644 --- a/dune-project +++ b/dune-project @@ -37,8 +37,8 @@ (alcotest :with-test) (pbrt (and - (>= 3.0) - (< 4.0))) + (>= 4.0) + (< 5.0))) (ocaml-lsp-server :with-dev-setup) (ocamlformat (and diff --git a/flake.nix b/flake.nix index 9a63f604..6f294061 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,13 @@ overlay = final: prev: { # You can add overrides here + pbrt = prev.pbrt.overrideAttrs (oldAttrs: { + src = pkgs.fetchgit { + url = "https://github.com/mransan/ocaml-protoc.git"; + rev = "5510694deffde13283742b8ad116fab61b65dfbc"; + sha256 = "sha256-0eQEaAZMs/OydNLsEKxdbdwx0/Ots6fLEpYg89VxK3k="; + }; + }); }; scope' = scope.overrideScope overlay; # Packages from devPackagesQuery diff --git a/opentelemetry.opam b/opentelemetry.opam index cdbdcf2e..7e3128d9 100644 --- a/opentelemetry.opam +++ b/opentelemetry.opam @@ -21,7 +21,7 @@ depends: [ "thread-local-storage" {>= "0.2" & < "0.3"} "odoc" {with-doc} "alcotest" {with-test} - "pbrt" {>= "3.0" & < "4.0"} + "pbrt" {>= "4.0" & < "5.0"} "ocaml-lsp-server" {with-dev-setup} "ocamlformat" {with-dev-setup & >= "0.27" & < "0.28"} "mtime" {>= "1.4"} diff --git a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml index 189b341e..9f71d52f 100644 --- a/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml +++ b/src/client-cohttp-eio/opentelemetry_client_cohttp_eio.ml @@ -81,8 +81,14 @@ let report_err_ = function | `Sysbreak -> Printf.eprintf "opentelemetry: ctrl-c captured, stopping\n%!" | `Failure msg -> Format.eprintf "@[<2>opentelemetry: export failed: %s@]@." msg - | `Status (code, { Opentelemetry.Proto.Status.code = scode; message; details }) - -> + | `Status + ( code, + { + Opentelemetry.Proto.Status.code = scode; + message; + details; + _presence = _; + } ) -> let pp_details out l = List.iter (fun s -> Format.fprintf out "%S;@ " (Bytes.unsafe_to_string s)) diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml index 4cb8f22e..53786ed2 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml @@ -61,8 +61,14 @@ let report_err_ = function | `Sysbreak -> Printf.eprintf "opentelemetry: ctrl-c captured, stopping\n%!" | `Failure msg -> Format.eprintf "@[<2>opentelemetry: export failed: %s@]@." msg - | `Status (code, { Opentelemetry.Proto.Status.code = scode; message; details }) - -> + | `Status + ( code, + { + Opentelemetry.Proto.Status.code = scode; + message; + details; + _presence = _; + } ) -> let pp_details out l = List.iter (fun s -> Format.fprintf out "%S;@ " (Bytes.unsafe_to_string s)) diff --git a/src/client-ocurl/opentelemetry_client_ocurl.ml b/src/client-ocurl/opentelemetry_client_ocurl.ml index 55d4788c..a58f78b7 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.ml +++ b/src/client-ocurl/opentelemetry_client_ocurl.ml @@ -117,6 +117,8 @@ module Backend_impl : sig val send_event : t -> Event.t -> unit + val n_bytes_sent : unit -> int + val shutdown : t -> on_done:(unit -> unit) -> unit end = struct open Opentelemetry.Proto @@ -187,6 +189,10 @@ end = struct let[@inline] send_event (self : t) ev : unit = B_queue.push self.q ev + let n_bytes_sent_ = Atomic.make 0 + + let[@inline] n_bytes_sent () = Atomic.get n_bytes_sent_ + (** Thread that, in a loop, reads from [q] to get the next message to send via http *) let bg_thread_loop (self : t) : unit = @@ -199,7 +205,9 @@ end = struct Self_trace.with_ ~kind:Span_kind_producer name ~attrs:[ "n", `Int (List.length l) ] in - conv l |> send_http_ ~stop ~config ~url client + let msg = conv l in + ignore (Atomic.fetch_and_add n_bytes_sent_ (String.length msg) : int); + send_http_ ~stop ~config ~url client msg in try while not (Atomic.get stop) do @@ -471,3 +479,5 @@ let with_setup ?stop ?config ?(enable = true) () f = Fun.protect ~finally:remove_backend f ) else f () + +let n_bytes_sent = Backend_impl.n_bytes_sent diff --git a/src/client-ocurl/opentelemetry_client_ocurl.mli b/src/client-ocurl/opentelemetry_client_ocurl.mli index 47daf805..6d3918dc 100644 --- a/src/client-ocurl/opentelemetry_client_ocurl.mli +++ b/src/client-ocurl/opentelemetry_client_ocurl.mli @@ -11,6 +11,9 @@ val set_headers : (string * string) list -> unit module Atomic = Opentelemetry_atomic.Atomic module Config = Config +val n_bytes_sent : unit -> int +(** Global counter of bytes sent (or attempted to be sent) *) + val create_backend : ?stop:bool Atomic.t -> ?config:Config.t -> diff --git a/src/client/self_trace.ml b/src/client/self_trace.ml index 62d04cae..46757302 100644 --- a/src/client/self_trace.ml +++ b/src/client/self_trace.ml @@ -1,6 +1,6 @@ module OT = Opentelemetry -let enabled = Atomic.make true +let enabled = Atomic.make false let add_event (scope : OT.Scope.t) ev = OT.Scope.add_event scope (fun () -> ev) diff --git a/src/client/signal.ml b/src/client/signal.ml index 7a2eddd5..d3fafcfa 100644 --- a/src/client/signal.ml +++ b/src/client/signal.ml @@ -54,14 +54,14 @@ module Encode = struct resource_logs |> resource_to_string ~encoder ~ctor:(fun r -> - Logs_service.default_export_logs_service_request ~resource_logs:r ()) + Logs_service.make_export_logs_service_request ~resource_logs:r ()) ~enc:Logs_service.encode_pb_export_logs_service_request let metrics ?encoder resource_metrics = resource_metrics |> resource_to_string ~encoder ~ctor:(fun r -> - Metrics_service.default_export_metrics_service_request + Metrics_service.make_export_metrics_service_request ~resource_metrics:r ()) ~enc:Metrics_service.encode_pb_export_metrics_service_request @@ -69,8 +69,7 @@ module Encode = struct resource_spans |> resource_to_string ~encoder ~ctor:(fun r -> - Trace_service.default_export_trace_service_request ~resource_spans:r - ()) + Trace_service.make_export_trace_service_request ~resource_spans:r ()) ~enc:Trace_service.encode_pb_export_trace_service_request end diff --git a/src/core/opentelemetry.ml b/src/core/opentelemetry.ml index ffac42b7..4b189819 100644 --- a/src/core/opentelemetry.ml +++ b/src/core/opentelemetry.ml @@ -673,7 +673,7 @@ open struct let _conv_key_value (k, v) = let open Proto.Common in let value = _conv_value v in - default_key_value ~key:k ~value () + make_key_value ~key:k ?value () end (** {2 Global settings} *) @@ -695,9 +695,8 @@ module Globals = struct @since 0.12 *) let service_version = ref None - let instrumentation_library = - default_instrumentation_scope ~version:"%%VERSION_NUM%%" ~name:"ocaml-otel" - () + let instrumentation_library : instrumentation_scope = + make_instrumentation_scope ~version:"%%VERSION_NUM%%" ~name:"ocaml-otel" () (** Global attributes, initially set via OTEL_RESOURCE_ATTRIBUTES and modifiable by the user code. They will be attached to each outgoing @@ -705,7 +704,7 @@ module Globals = struct let global_attributes : key_value list ref = let parse_pair s = match String.split_on_char '=' s with - | [ a; b ] -> default_key_value ~key:a ~value:(Some (String_value b)) () + | [ a; b ] -> make_key_value ~key:a ~value:(String_value b) () | _ -> failwith (Printf.sprintf "invalid attribute: %S" s) in ref @@ -734,32 +733,32 @@ module Globals = struct let mk_attributes ?(service_name = !service_name) ?(attrs = []) () : _ list = let l = List.map _conv_key_value attrs in let l = - default_key_value ~key:Conventions.Attributes.Service.name - ~value:(Some (String_value service_name)) () + make_key_value ~key:Conventions.Attributes.Service.name + ~value:(String_value service_name) () :: l in let l = match !service_instance_id with | None -> l | Some v -> - default_key_value ~key:Conventions.Attributes.Service.instance_id - ~value:(Some (String_value v)) () + make_key_value ~key:Conventions.Attributes.Service.instance_id + ~value:(String_value v) () :: l in let l = match !service_namespace with | None -> l | Some v -> - default_key_value ~key:Conventions.Attributes.Service.namespace - ~value:(Some (String_value v)) () + make_key_value ~key:Conventions.Attributes.Service.namespace + ~value:(String_value v) () :: l in let l = match !service_version with | None -> l | Some v -> - default_key_value ~key:Conventions.Attributes.Service.version - ~value:(Some (String_value v)) () + make_key_value ~key:Conventions.Attributes.Service.version + ~value:(String_value v) () :: l in l |> merge_global_attributes_ @@ -786,7 +785,7 @@ end = struct let make ?(time_unix_nano = Timestamp_ns.now_unix_ns ()) ?(attrs = []) (name : string) : t = let attrs = List.map _conv_key_value attrs in - default_span_event ~time_unix_nano ~name ~attributes:attrs () + make_span_event ~time_unix_nano ~name ~attributes:attrs () end (** Span Link @@ -826,7 +825,7 @@ end = struct let dropped_attributes_count = Option.map Int32.of_int dropped_attributes_count in - default_span_link + make_span_link ~trace_id:(Trace_id.to_bytes trace_id) ~span_id:(Span_id.to_bytes span_id) ?trace_state ~attributes ?dropped_attributes_count () @@ -840,9 +839,10 @@ end module Span_status : sig open Proto.Trace - type t = status = { - message: string; - code: status_status_code; + type t = status = private { + mutable _presence: Pbrt.Bitfield.t; + mutable message: string; + mutable code: status_status_code; } type code = status_status_code = @@ -854,9 +854,10 @@ module Span_status : sig end = struct open Proto.Trace - type t = status = { - message: string; - code: status_status_code; + type t = status = private { + mutable _presence: Pbrt.Bitfield.t; + mutable message: string; + mutable code: status_status_code; } type code = status_status_code = @@ -864,7 +865,7 @@ end = struct | Status_code_ok | Status_code_error - let make ~message ~code = { message; code } + let[@inline] make ~message ~code : t = make_status ~message ~code () end (** @since 0.11 *) @@ -1199,8 +1200,8 @@ end = struct let parent_span_id = Option.map Span_id.to_bytes parent in let attributes = List.map _conv_key_value attrs in let span = - default_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id) - ~attributes ~events ?trace_state ~status ~kind ~name ~links + make_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id) + ~attributes ~events ?trace_state ?status ~kind ~name ~links ~start_time_unix_nano:start_time ~end_time_unix_nano:end_time () in span, id @@ -1216,14 +1217,13 @@ module Trace = struct type span = Span.t - let make_resource_spans ?service_name ?attrs spans = + let make_resource_spans ?service_name ?attrs spans : resource_spans = let ils = - default_scope_spans ~scope:(Some Globals.instrumentation_library) ~spans - () + make_scope_spans ~scope:Globals.instrumentation_library ~spans () in let attributes = Globals.mk_attributes ?service_name ?attrs () in - let resource = Proto.Resource.default_resource ~attributes () in - default_resource_spans ~resource:(Some resource) ~scope_spans:[ ils ] () + let resource = Proto.Resource.make_resource ~attributes () in + make_resource_spans ~resource ~scope_spans:[ ils ] () (** Sync emitter. @@ -1290,7 +1290,7 @@ module Trace = struct | Error (e, bt) -> Scope.record_exception scope e bt; Some - (default_status ~code:Status_code_error + (make_status ~code:Status_code_error ~message:(Printexc.to_string e) ())) in let span, _ = @@ -1371,23 +1371,22 @@ module Metrics = struct ?(now = Timestamp_ns.now_unix_ns ()) ?(attrs = []) (d : float) : number_data_point = let attributes = attrs |> List.map _conv_key_value in - default_number_data_point ~start_time_unix_nano ~time_unix_nano:now - ~attributes ~value:(As_double d) () + make_number_data_point ~start_time_unix_nano ~time_unix_nano:now ~attributes + ~value:(As_double d) () (** Number data point, as an int *) let int ?(start_time_unix_nano = _program_start) ?(now = Timestamp_ns.now_unix_ns ()) ?(attrs = []) (i : int) : number_data_point = let attributes = attrs |> List.map _conv_key_value in - default_number_data_point ~start_time_unix_nano ~time_unix_nano:now - ~attributes + make_number_data_point ~start_time_unix_nano ~time_unix_nano:now ~attributes ~value:(As_int (Int64.of_int i)) () (** Aggregation of a scalar metric, always with the current value *) let gauge ~name ?description ?unit_ (l : number_data_point list) : t = - let data = Gauge (default_gauge ~data_points:l ()) in - default_metric ~name ?description ?unit_ ~data () + let data = Gauge (make_gauge ~data_points:l ()) in + make_metric ~name ?description ?unit_ ~data () type aggregation_temporality = Metrics.aggregation_temporality = | Aggregation_temporality_unspecified @@ -1399,9 +1398,9 @@ module Metrics = struct ?(aggregation_temporality = Aggregation_temporality_cumulative) ?is_monotonic (l : number_data_point list) : t = let data = - Sum (default_sum ~data_points:l ?is_monotonic ~aggregation_temporality ()) + Sum (make_sum ~data_points:l ?is_monotonic ~aggregation_temporality ()) in - default_metric ~name ?description ?unit_ ~data () + make_metric ~name ?description ?unit_ ~data () (** Histogram data @param count number of values in population (non negative) @@ -1416,15 +1415,15 @@ module Metrics = struct ?(explicit_bounds = []) ?sum ~bucket_counts ~count () : histogram_data_point = let attributes = attrs |> List.map _conv_key_value in - default_histogram_data_point ~start_time_unix_nano ~time_unix_nano:now + make_histogram_data_point ~start_time_unix_nano ~time_unix_nano:now ~attributes ~exemplars ~bucket_counts ~explicit_bounds ~count ?sum () let histogram ~name ?description ?unit_ ?aggregation_temporality (l : histogram_data_point list) : t = let data = - Histogram (default_histogram ~data_points:l ?aggregation_temporality ()) + Histogram (make_histogram ~data_points:l ?aggregation_temporality ()) in - default_metric ~name ?description ?unit_ ~data () + make_metric ~name ?description ?unit_ ~data () (* TODO: exponential history *) (* TODO: summary *) @@ -1434,12 +1433,11 @@ module Metrics = struct let make_resource_metrics ?service_name ?attrs (l : t list) : resource_metrics = let lm = - default_scope_metrics ~scope:(Some Globals.instrumentation_library) - ~metrics:l () + make_scope_metrics ~scope:Globals.instrumentation_library ~metrics:l () in let attributes = Globals.mk_attributes ?service_name ?attrs () in - let resource = Proto.Resource.default_resource ~attributes () in - default_resource_metrics ~scope_metrics:[ lm ] ~resource:(Some resource) () + let resource = Proto.Resource.make_resource ~attributes () in + make_resource_metrics ~scope_metrics:[ lm ] ~resource () (** Emit some metrics to the collector (sync). This blocks until the backend has pushed the metrics into some internal queue, or discarded them. @@ -1543,9 +1541,9 @@ module Logs = struct let trace_id = Option.map Trace_id.to_bytes trace_id in let span_id = Option.map Span_id.to_bytes span_id in let body = _conv_value body in - default_log_record ~time_unix_nano ~observed_time_unix_nano + make_log_record ~time_unix_nano ~observed_time_unix_nano ?severity_number:severity ?severity_text:log_level ?flags ?trace_id - ?span_id ~body () + ?span_id ?body () (** Make a log entry whose body is a string *) let make_str ?time ?observed_time_unix_nano ?severity ?log_level ?flags @@ -1569,14 +1567,11 @@ module Logs = struct cause deadlocks. *) let emit ?service_name ?attrs (l : t list) : unit = let attributes = Globals.mk_attributes ?service_name ?attrs () in - let resource = Proto.Resource.default_resource ~attributes () in + let resource = Proto.Resource.make_resource ~attributes () in let ll = - default_scope_logs ~scope:(Some Globals.instrumentation_library) - ~log_records:l () - in - let rl = - default_resource_logs ~resource:(Some resource) ~scope_logs:[ ll ] () + make_scope_logs ~scope:Globals.instrumentation_library ~log_records:l () in + let rl = make_resource_logs ~resource ~scope_logs:[ ll ] () in Collector.send_logs [ rl ] ~ret:ignore end diff --git a/src/integrations/logs/opentelemetry_logs.ml b/src/integrations/logs/opentelemetry_logs.ml index 713d4e38..a06cf117 100644 --- a/src/integrations/logs/opentelemetry_logs.ml +++ b/src/integrations/logs/opentelemetry_logs.ml @@ -23,9 +23,6 @@ let log_level_to_severity (level : Logs.level) : Otel.Logs.severity = (* Logs Util *) (*****************************************************************************) -let create_tag (tag : string) : string Logs.Tag.def = - Logs.Tag.def tag Format.pp_print_string - let emit_telemetry_tag = Logs.Tag.def ~doc:"Whether or not to emit this log via telemetry" "emit_telemetry" Format.pp_print_bool diff --git a/src/proto/common.ml b/src/proto/common.ml index b0faafa5..d9cf40a4 100644 --- a/src/proto/common.ml +++ b/src/proto/common.ml @@ -1,4 +1,4 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type any_value = | String_value of string @@ -10,136 +10,194 @@ type any_value = | Bytes_value of bytes and array_value = { - values : any_value list; -} - -and key_value_list = { - values : key_value list; -} - -and key_value = { - key : string; - value : any_value option; -} - -type instrumentation_scope = { - name : string; - version : string; - attributes : key_value list; - dropped_attributes_count : int32; -} - -let rec default_any_value () : any_value = String_value ("") - -and default_array_value - ?values:((values:any_value list) = []) - () : array_value = { - values; -} - -and default_key_value_list - ?values:((values:key_value list) = []) - () : key_value_list = { - values; -} - -and default_key_value - ?key:((key:string) = "") - ?value:((value:any_value option) = None) - () : key_value = { - key; - value; -} - -let rec default_instrumentation_scope - ?name:((name:string) = "") - ?version:((version:string) = "") - ?attributes:((attributes:key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - () : instrumentation_scope = { - name; - version; - attributes; - dropped_attributes_count; -} - -type array_value_mutable = { mutable values : any_value list; } -let default_array_value_mutable () : array_value_mutable = { - values = []; -} - -type key_value_list_mutable = { +and key_value_list = { mutable values : key_value list; } -let default_key_value_list_mutable () : key_value_list_mutable = { - values = []; -} - -type key_value_mutable = { +and key_value = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable key : string; mutable value : any_value option; } -let default_key_value_mutable () : key_value_mutable = { - key = ""; - value = None; -} - -type instrumentation_scope_mutable = { +type instrumentation_scope = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) mutable name : string; mutable version : string; mutable attributes : key_value list; mutable dropped_attributes_count : int32; } -let default_instrumentation_scope_mutable () : instrumentation_scope_mutable = { - name = ""; - version = ""; - attributes = []; - dropped_attributes_count = 0l; +type entity_ref = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable schema_url : string; + mutable type_ : string; + mutable id_keys : string list; + mutable description_keys : string list; } +let default_any_value (): any_value = String_value ("") -(** {2 Make functions} *) - +let default_array_value (): array_value = +{ + values=[]; +} -let rec make_array_value - ~(values:any_value list) - () : array_value = { - values; +let default_key_value_list (): key_value_list = +{ + values=[]; } -and make_key_value_list - ~(values:key_value list) - () : key_value_list = { - values; +let default_key_value (): key_value = +{ + _presence=Pbrt.Bitfield.empty; + key=""; + value=None; } -and make_key_value - ~(key:string) - ?value:((value:any_value option) = None) - () : key_value = { - key; - value; +let default_instrumentation_scope (): instrumentation_scope = +{ + _presence=Pbrt.Bitfield.empty; + name=""; + version=""; + attributes=[]; + dropped_attributes_count=0l; } -let rec make_instrumentation_scope - ~(name:string) - ~(version:string) - ~(attributes:key_value list) - ~(dropped_attributes_count:int32) - () : instrumentation_scope = { - name; - version; - attributes; - dropped_attributes_count; +let default_entity_ref (): entity_ref = +{ + _presence=Pbrt.Bitfield.empty; + schema_url=""; + type_=""; + id_keys=[]; + description_keys=[]; } -[@@@ocaml.warning "-27-30-39"] + +(** {2 Make functions} *) + + +let[@inline] array_value_set_values (self:array_value) (x:any_value list) : unit = + self.values <- x + +let copy_array_value (self:array_value) : array_value = + { self with values = self.values } + +let make_array_value + ?(values=[]) + () : array_value = + let _res = default_array_value () in + array_value_set_values _res values; + _res + + +let[@inline] key_value_list_set_values (self:key_value_list) (x:key_value list) : unit = + self.values <- x + +let copy_key_value_list (self:key_value_list) : key_value_list = + { self with values = self.values } + +let make_key_value_list + ?(values=[]) + () : key_value_list = + let _res = default_key_value_list () in + key_value_list_set_values _res values; + _res + +let[@inline] key_value_has_key (self:key_value) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] key_value_set_key (self:key_value) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.key <- x +let[@inline] key_value_set_value (self:key_value) (x:any_value) : unit = + self.value <- Some x + +let copy_key_value (self:key_value) : key_value = + { self with key = self.key } + +let make_key_value + ?(key:string option) + ?(value:any_value option) + () : key_value = + let _res = default_key_value () in + (match key with + | None -> () + | Some v -> key_value_set_key _res v); + (match value with + | None -> () + | Some v -> key_value_set_value _res v); + _res + +let[@inline] instrumentation_scope_has_name (self:instrumentation_scope) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] instrumentation_scope_has_version (self:instrumentation_scope) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] instrumentation_scope_has_dropped_attributes_count (self:instrumentation_scope) : bool = (Pbrt.Bitfield.get self._presence 2) + +let[@inline] instrumentation_scope_set_name (self:instrumentation_scope) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.name <- x +let[@inline] instrumentation_scope_set_version (self:instrumentation_scope) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.version <- x +let[@inline] instrumentation_scope_set_attributes (self:instrumentation_scope) (x:key_value list) : unit = + self.attributes <- x +let[@inline] instrumentation_scope_set_dropped_attributes_count (self:instrumentation_scope) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.dropped_attributes_count <- x + +let copy_instrumentation_scope (self:instrumentation_scope) : instrumentation_scope = + { self with name = self.name } + +let make_instrumentation_scope + ?(name:string option) + ?(version:string option) + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + () : instrumentation_scope = + let _res = default_instrumentation_scope () in + (match name with + | None -> () + | Some v -> instrumentation_scope_set_name _res v); + (match version with + | None -> () + | Some v -> instrumentation_scope_set_version _res v); + instrumentation_scope_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> instrumentation_scope_set_dropped_attributes_count _res v); + _res + +let[@inline] entity_ref_has_schema_url (self:entity_ref) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] entity_ref_has_type_ (self:entity_ref) : bool = (Pbrt.Bitfield.get self._presence 1) + +let[@inline] entity_ref_set_schema_url (self:entity_ref) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x +let[@inline] entity_ref_set_type_ (self:entity_ref) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.type_ <- x +let[@inline] entity_ref_set_id_keys (self:entity_ref) (x:string list) : unit = + self.id_keys <- x +let[@inline] entity_ref_set_description_keys (self:entity_ref) (x:string list) : unit = + self.description_keys <- x + +let copy_entity_ref (self:entity_ref) : entity_ref = + { self with schema_url = self.schema_url } + +let make_entity_ref + ?(schema_url:string option) + ?(type_:string option) + ?(id_keys=[]) + ?(description_keys=[]) + () : entity_ref = + let _res = default_entity_ref () in + (match schema_url with + | None -> () + | Some v -> entity_ref_set_schema_url _res v); + (match type_ with + | None -> () + | Some v -> entity_ref_set_type_ _res v); + entity_ref_set_id_keys _res id_keys; + entity_ref_set_description_keys _res description_keys; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -167,21 +225,30 @@ and pp_key_value_list fmt (v:key_value_list) = and pp_key_value fmt (v:key_value) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "key" Pbrt.Pp.pp_string fmt v.key; + Pbrt.Pp.pp_record_field ~absent:(not (key_value_has_key v)) ~first:true "key" Pbrt.Pp.pp_string fmt v.key; Pbrt.Pp.pp_record_field ~first:false "value" (Pbrt.Pp.pp_option pp_any_value) fmt v.value; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_instrumentation_scope fmt (v:instrumentation_scope) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "name" Pbrt.Pp.pp_string fmt v.name; - Pbrt.Pp.pp_record_field ~first:false "version" Pbrt.Pp.pp_string fmt v.version; + Pbrt.Pp.pp_record_field ~absent:(not (instrumentation_scope_has_name v)) ~first:true "name" Pbrt.Pp.pp_string fmt v.name; + Pbrt.Pp.pp_record_field ~absent:(not (instrumentation_scope_has_version v)) ~first:false "version" Pbrt.Pp.pp_string fmt v.version; Pbrt.Pp.pp_record_field ~first:false "attributes" (Pbrt.Pp.pp_list pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (instrumentation_scope_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_entity_ref fmt (v:entity_ref) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~absent:(not (entity_ref_has_schema_url v)) ~first:true "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (entity_ref_has_type_ v)) ~first:false "type_" Pbrt.Pp.pp_string fmt v.type_; + Pbrt.Pp.pp_record_field ~first:false "id_keys" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.id_keys; + Pbrt.Pp.pp_record_field ~first:false "description_keys" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.description_keys; in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) @@ -211,22 +278,24 @@ let rec encode_pb_any_value (v:any_value) encoder = end and encode_pb_array_value (v:array_value) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_any_value x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.values encoder; () and encode_pb_key_value_list (v:key_value_list) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_key_value x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.values encoder; () and encode_pb_key_value (v:key_value) encoder = - Pbrt.Encoder.string v.key encoder; - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + if key_value_has_key v then ( + Pbrt.Encoder.string v.key encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); begin match v.value with | Some x -> Pbrt.Encoder.nested encode_pb_any_value x encoder; @@ -236,19 +305,44 @@ and encode_pb_key_value (v:key_value) encoder = () let rec encode_pb_instrumentation_scope (v:instrumentation_scope) encoder = - Pbrt.Encoder.string v.name encoder; - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.version encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if instrumentation_scope_has_name v then ( + Pbrt.Encoder.string v.name encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); + if instrumentation_scope_has_version v then ( + Pbrt.Encoder.string v.version encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_key_value x encoder; Pbrt.Encoder.key 3 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 4 Pbrt.Varint encoder; + if instrumentation_scope_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 4 Pbrt.Varint encoder; + ); () -[@@@ocaml.warning "-27-30-39"] +let rec encode_pb_entity_ref (v:entity_ref) encoder = + if entity_ref_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); + if entity_ref_has_type_ v then ( + Pbrt.Encoder.string v.type_ encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ) v.id_keys encoder; + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 4 Pbrt.Bytes encoder; + ) v.description_keys encoder; + () + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) @@ -273,100 +367,125 @@ let rec decode_pb_any_value d = loop () and decode_pb_array_value d = - let v = default_array_value_mutable () in + let v = default_array_value () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.values <- List.rev v.values; + (* put lists in the correct order *) + array_value_set_values v (List.rev v.values); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.values <- (decode_pb_any_value (Pbrt.Decoder.nested d)) :: v.values; + array_value_set_values v ((decode_pb_any_value (Pbrt.Decoder.nested d)) :: v.values); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(array_value), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "array_value" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - values = v.values; - } : array_value) + (v : array_value) and decode_pb_key_value_list d = - let v = default_key_value_list_mutable () in + let v = default_key_value_list () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.values <- List.rev v.values; + (* put lists in the correct order *) + key_value_list_set_values v (List.rev v.values); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.values <- (decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.values; + key_value_list_set_values v ((decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.values); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(key_value_list), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "key_value_list" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - values = v.values; - } : key_value_list) + (v : key_value_list) and decode_pb_key_value d = - let v = default_key_value_mutable () in + let v = default_key_value () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.key <- Pbrt.Decoder.string d; + key_value_set_key v (Pbrt.Decoder.string d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(key_value), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "key_value" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.value <- Some (decode_pb_any_value (Pbrt.Decoder.nested d)); + key_value_set_value v (decode_pb_any_value (Pbrt.Decoder.nested d)); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(key_value), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "key_value" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - key = v.key; - value = v.value; - } : key_value) + (v : key_value) let rec decode_pb_instrumentation_scope d = - let v = default_instrumentation_scope_mutable () in + let v = default_instrumentation_scope () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + instrumentation_scope_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.name <- Pbrt.Decoder.string d; + instrumentation_scope_set_name v (Pbrt.Decoder.string d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instrumentation_scope), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "instrumentation_scope" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.version <- Pbrt.Decoder.string d; + instrumentation_scope_set_version v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instrumentation_scope), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "instrumentation_scope" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.attributes <- (decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + instrumentation_scope_set_attributes v ((decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instrumentation_scope), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "instrumentation_scope" 3 pk | Some (4, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + instrumentation_scope_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); + end + | Some (4, pk) -> + Pbrt.Decoder.unexpected_payload_message "instrumentation_scope" 4 pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + (v : instrumentation_scope) + +let rec decode_pb_entity_ref d = + let v = default_entity_ref () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + (* put lists in the correct order *) + entity_ref_set_description_keys v (List.rev v.description_keys); + entity_ref_set_id_keys v (List.rev v.id_keys); + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + entity_ref_set_schema_url v (Pbrt.Decoder.string d); + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload_message "entity_ref" 1 pk + | Some (2, Pbrt.Bytes) -> begin + entity_ref_set_type_ v (Pbrt.Decoder.string d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload_message "entity_ref" 2 pk + | Some (3, Pbrt.Bytes) -> begin + entity_ref_set_id_keys v ((Pbrt.Decoder.string d) :: v.id_keys); + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload_message "entity_ref" 3 pk + | Some (4, Pbrt.Bytes) -> begin + entity_ref_set_description_keys v ((Pbrt.Decoder.string d) :: v.description_keys); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instrumentation_scope), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "entity_ref" 4 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - name = v.name; - version = v.version; - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - } : instrumentation_scope) + (v : entity_ref) diff --git a/src/proto/common.mli b/src/proto/common.mli index eb1114cd..04318fe7 100644 --- a/src/proto/common.mli +++ b/src/proto/common.mli @@ -16,92 +16,161 @@ type any_value = | Kvlist_value of key_value_list | Bytes_value of bytes -and array_value = { - values : any_value list; +and array_value = private { + mutable values : any_value list; } -and key_value_list = { - values : key_value list; +and key_value_list = private { + mutable values : key_value list; } -and key_value = { - key : string; - value : any_value option; +and key_value = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable key : string; + mutable value : any_value option; } -type instrumentation_scope = { - name : string; - version : string; - attributes : key_value list; - dropped_attributes_count : int32; +type instrumentation_scope = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) + mutable name : string; + mutable version : string; + mutable attributes : key_value list; + mutable dropped_attributes_count : int32; +} + +type entity_ref = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable schema_url : string; + mutable type_ : string; + mutable id_keys : string list; + mutable description_keys : string list; } (** {2 Basic values} *) val default_any_value : unit -> any_value -(** [default_any_value ()] is the default value for type [any_value] *) +(** [default_any_value ()] is a new empty value for type [any_value] *) -val default_array_value : - ?values:any_value list -> - unit -> - array_value -(** [default_array_value ()] is the default value for type [array_value] *) +val default_array_value : unit -> array_value +(** [default_array_value ()] is a new empty value for type [array_value] *) -val default_key_value_list : - ?values:key_value list -> - unit -> - key_value_list -(** [default_key_value_list ()] is the default value for type [key_value_list] *) +val default_key_value_list : unit -> key_value_list +(** [default_key_value_list ()] is a new empty value for type [key_value_list] *) -val default_key_value : - ?key:string -> - ?value:any_value option -> - unit -> - key_value -(** [default_key_value ()] is the default value for type [key_value] *) +val default_key_value : unit -> key_value +(** [default_key_value ()] is a new empty value for type [key_value] *) -val default_instrumentation_scope : - ?name:string -> - ?version:string -> - ?attributes:key_value list -> - ?dropped_attributes_count:int32 -> - unit -> - instrumentation_scope -(** [default_instrumentation_scope ()] is the default value for type [instrumentation_scope] *) +val default_instrumentation_scope : unit -> instrumentation_scope +(** [default_instrumentation_scope ()] is a new empty value for type [instrumentation_scope] *) +val default_entity_ref : unit -> entity_ref +(** [default_entity_ref ()] is a new empty value for type [entity_ref] *) -(** {2 Make functions} *) +(** {2 Make functions} *) val make_array_value : - values:any_value list -> + ?values:any_value list -> unit -> array_value (** [make_array_value … ()] is a builder for type [array_value] *) +val copy_array_value : array_value -> array_value + +val array_value_set_values : array_value -> any_value list -> unit + (** set field values in array_value *) + val make_key_value_list : - values:key_value list -> + ?values:key_value list -> unit -> key_value_list (** [make_key_value_list … ()] is a builder for type [key_value_list] *) +val copy_key_value_list : key_value_list -> key_value_list + +val key_value_list_set_values : key_value_list -> key_value list -> unit + (** set field values in key_value_list *) + val make_key_value : - key:string -> - ?value:any_value option -> + ?key:string -> + ?value:any_value -> unit -> key_value (** [make_key_value … ()] is a builder for type [key_value] *) +val copy_key_value : key_value -> key_value + +val key_value_has_key : key_value -> bool + (** presence of field "key" in [key_value] *) + +val key_value_set_key : key_value -> string -> unit + (** set field key in key_value *) + +val key_value_set_value : key_value -> any_value -> unit + (** set field value in key_value *) + val make_instrumentation_scope : - name:string -> - version:string -> - attributes:key_value list -> - dropped_attributes_count:int32 -> + ?name:string -> + ?version:string -> + ?attributes:key_value list -> + ?dropped_attributes_count:int32 -> unit -> instrumentation_scope (** [make_instrumentation_scope … ()] is a builder for type [instrumentation_scope] *) +val copy_instrumentation_scope : instrumentation_scope -> instrumentation_scope + +val instrumentation_scope_has_name : instrumentation_scope -> bool + (** presence of field "name" in [instrumentation_scope] *) + +val instrumentation_scope_set_name : instrumentation_scope -> string -> unit + (** set field name in instrumentation_scope *) + +val instrumentation_scope_has_version : instrumentation_scope -> bool + (** presence of field "version" in [instrumentation_scope] *) + +val instrumentation_scope_set_version : instrumentation_scope -> string -> unit + (** set field version in instrumentation_scope *) + +val instrumentation_scope_set_attributes : instrumentation_scope -> key_value list -> unit + (** set field attributes in instrumentation_scope *) + +val instrumentation_scope_has_dropped_attributes_count : instrumentation_scope -> bool + (** presence of field "dropped_attributes_count" in [instrumentation_scope] *) + +val instrumentation_scope_set_dropped_attributes_count : instrumentation_scope -> int32 -> unit + (** set field dropped_attributes_count in instrumentation_scope *) + +val make_entity_ref : + ?schema_url:string -> + ?type_:string -> + ?id_keys:string list -> + ?description_keys:string list -> + unit -> + entity_ref +(** [make_entity_ref … ()] is a builder for type [entity_ref] *) + +val copy_entity_ref : entity_ref -> entity_ref + +val entity_ref_has_schema_url : entity_ref -> bool + (** presence of field "schema_url" in [entity_ref] *) + +val entity_ref_set_schema_url : entity_ref -> string -> unit + (** set field schema_url in entity_ref *) + +val entity_ref_has_type_ : entity_ref -> bool + (** presence of field "type_" in [entity_ref] *) + +val entity_ref_set_type_ : entity_ref -> string -> unit + (** set field type_ in entity_ref *) + +val entity_ref_set_id_keys : entity_ref -> string list -> unit + (** set field id_keys in entity_ref *) + +val entity_ref_set_description_keys : entity_ref -> string list -> unit + (** set field description_keys in entity_ref *) + (** {2 Formatters} *) @@ -120,6 +189,9 @@ val pp_key_value : Format.formatter -> key_value -> unit val pp_instrumentation_scope : Format.formatter -> instrumentation_scope -> unit (** [pp_instrumentation_scope v] formats v *) +val pp_entity_ref : Format.formatter -> entity_ref -> unit +(** [pp_entity_ref v] formats v *) + (** {2 Protobuf Encoding} *) @@ -138,6 +210,9 @@ val encode_pb_key_value : key_value -> Pbrt.Encoder.t -> unit val encode_pb_instrumentation_scope : instrumentation_scope -> Pbrt.Encoder.t -> unit (** [encode_pb_instrumentation_scope v encoder] encodes [v] with the given [encoder] *) +val encode_pb_entity_ref : entity_ref -> Pbrt.Encoder.t -> unit +(** [encode_pb_entity_ref v encoder] encodes [v] with the given [encoder] *) + (** {2 Protobuf Decoding} *) @@ -155,3 +230,6 @@ val decode_pb_key_value : Pbrt.Decoder.t -> key_value val decode_pb_instrumentation_scope : Pbrt.Decoder.t -> instrumentation_scope (** [decode_pb_instrumentation_scope decoder] decodes a [instrumentation_scope] binary value from [decoder] *) + +val decode_pb_entity_ref : Pbrt.Decoder.t -> entity_ref +(** [decode_pb_entity_ref decoder] decodes a [entity_ref] binary value from [decoder] *) diff --git a/src/proto/logs.ml b/src/proto/logs.ml index 37509420..6916c264 100644 --- a/src/proto/logs.ml +++ b/src/proto/logs.ml @@ -1,4 +1,4 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type severity_number = | Severity_number_unspecified @@ -28,93 +28,7 @@ type severity_number = | Severity_number_fatal4 type log_record = { - time_unix_nano : int64; - observed_time_unix_nano : int64; - severity_number : severity_number; - severity_text : string; - body : Common.any_value option; - attributes : Common.key_value list; - dropped_attributes_count : int32; - flags : int32; - trace_id : bytes; - span_id : bytes; -} - -type scope_logs = { - scope : Common.instrumentation_scope option; - log_records : log_record list; - schema_url : string; -} - -type resource_logs = { - resource : Resource.resource option; - scope_logs : scope_logs list; - schema_url : string; -} - -type logs_data = { - resource_logs : resource_logs list; -} - -type log_record_flags = - | Log_record_flags_do_not_use - | Log_record_flags_trace_flags_mask - -let rec default_severity_number () = (Severity_number_unspecified:severity_number) - -let rec default_log_record - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?observed_time_unix_nano:((observed_time_unix_nano:int64) = 0L) - ?severity_number:((severity_number:severity_number) = default_severity_number ()) - ?severity_text:((severity_text:string) = "") - ?body:((body:Common.any_value option) = None) - ?attributes:((attributes:Common.key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - ?flags:((flags:int32) = 0l) - ?trace_id:((trace_id:bytes) = Bytes.create 0) - ?span_id:((span_id:bytes) = Bytes.create 0) - () : log_record = { - time_unix_nano; - observed_time_unix_nano; - severity_number; - severity_text; - body; - attributes; - dropped_attributes_count; - flags; - trace_id; - span_id; -} - -let rec default_scope_logs - ?scope:((scope:Common.instrumentation_scope option) = None) - ?log_records:((log_records:log_record list) = []) - ?schema_url:((schema_url:string) = "") - () : scope_logs = { - scope; - log_records; - schema_url; -} - -let rec default_resource_logs - ?resource:((resource:Resource.resource option) = None) - ?scope_logs:((scope_logs:scope_logs list) = []) - ?schema_url:((schema_url:string) = "") - () : resource_logs = { - resource; - scope_logs; - schema_url; -} - -let rec default_logs_data - ?resource_logs:((resource_logs:resource_logs list) = []) - () : logs_data = { - resource_logs; -} - -let rec default_log_record_flags () = (Log_record_flags_do_not_use:log_record_flags) - -type log_record_mutable = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 9 fields *) mutable time_unix_nano : int64; mutable observed_time_unix_nano : int64; mutable severity_number : severity_number; @@ -125,109 +39,227 @@ type log_record_mutable = { mutable flags : int32; mutable trace_id : bytes; mutable span_id : bytes; + mutable event_name : string; } -let default_log_record_mutable () : log_record_mutable = { - time_unix_nano = 0L; - observed_time_unix_nano = 0L; - severity_number = default_severity_number (); - severity_text = ""; - body = None; - attributes = []; - dropped_attributes_count = 0l; - flags = 0l; - trace_id = Bytes.create 0; - span_id = Bytes.create 0; -} - -type scope_logs_mutable = { +type scope_logs = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable scope : Common.instrumentation_scope option; mutable log_records : log_record list; mutable schema_url : string; } -let default_scope_logs_mutable () : scope_logs_mutable = { - scope = None; - log_records = []; - schema_url = ""; -} - -type resource_logs_mutable = { +type resource_logs = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable resource : Resource.resource option; mutable scope_logs : scope_logs list; mutable schema_url : string; } -let default_resource_logs_mutable () : resource_logs_mutable = { - resource = None; - scope_logs = []; - schema_url = ""; -} - -type logs_data_mutable = { +type logs_data = { mutable resource_logs : resource_logs list; } -let default_logs_data_mutable () : logs_data_mutable = { - resource_logs = []; -} - - -(** {2 Make functions} *) - +type log_record_flags = + | Log_record_flags_do_not_use + | Log_record_flags_trace_flags_mask -let rec make_log_record - ~(time_unix_nano:int64) - ~(observed_time_unix_nano:int64) - ~(severity_number:severity_number) - ~(severity_text:string) - ?body:((body:Common.any_value option) = None) - ~(attributes:Common.key_value list) - ~(dropped_attributes_count:int32) - ~(flags:int32) - ~(trace_id:bytes) - ~(span_id:bytes) - () : log_record = { - time_unix_nano; - observed_time_unix_nano; - severity_number; - severity_text; - body; - attributes; - dropped_attributes_count; - flags; - trace_id; - span_id; +let default_severity_number () = (Severity_number_unspecified:severity_number) + +let default_log_record (): log_record = +{ + _presence=Pbrt.Bitfield.empty; + time_unix_nano=0L; + observed_time_unix_nano=0L; + severity_number=default_severity_number (); + severity_text=""; + body=None; + attributes=[]; + dropped_attributes_count=0l; + flags=0l; + trace_id=Bytes.create 0; + span_id=Bytes.create 0; + event_name=""; } -let rec make_scope_logs - ?scope:((scope:Common.instrumentation_scope option) = None) - ~(log_records:log_record list) - ~(schema_url:string) - () : scope_logs = { - scope; - log_records; - schema_url; +let default_scope_logs (): scope_logs = +{ + _presence=Pbrt.Bitfield.empty; + scope=None; + log_records=[]; + schema_url=""; } -let rec make_resource_logs - ?resource:((resource:Resource.resource option) = None) - ~(scope_logs:scope_logs list) - ~(schema_url:string) - () : resource_logs = { - resource; - scope_logs; - schema_url; +let default_resource_logs (): resource_logs = +{ + _presence=Pbrt.Bitfield.empty; + resource=None; + scope_logs=[]; + schema_url=""; } -let rec make_logs_data - ~(resource_logs:resource_logs list) - () : logs_data = { - resource_logs; +let default_logs_data (): logs_data = +{ + resource_logs=[]; } +let default_log_record_flags () = (Log_record_flags_do_not_use:log_record_flags) + -[@@@ocaml.warning "-27-30-39"] +(** {2 Make functions} *) + +let[@inline] log_record_has_time_unix_nano (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] log_record_has_observed_time_unix_nano (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] log_record_has_severity_number (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] log_record_has_severity_text (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] log_record_has_dropped_attributes_count (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 4) +let[@inline] log_record_has_flags (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 5) +let[@inline] log_record_has_trace_id (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 6) +let[@inline] log_record_has_span_id (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 7) +let[@inline] log_record_has_event_name (self:log_record) : bool = (Pbrt.Bitfield.get self._presence 8) + +let[@inline] log_record_set_time_unix_nano (self:log_record) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.time_unix_nano <- x +let[@inline] log_record_set_observed_time_unix_nano (self:log_record) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.observed_time_unix_nano <- x +let[@inline] log_record_set_severity_number (self:log_record) (x:severity_number) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.severity_number <- x +let[@inline] log_record_set_severity_text (self:log_record) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.severity_text <- x +let[@inline] log_record_set_body (self:log_record) (x:Common.any_value) : unit = + self.body <- Some x +let[@inline] log_record_set_attributes (self:log_record) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] log_record_set_dropped_attributes_count (self:log_record) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.dropped_attributes_count <- x +let[@inline] log_record_set_flags (self:log_record) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 5); self.flags <- x +let[@inline] log_record_set_trace_id (self:log_record) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 6); self.trace_id <- x +let[@inline] log_record_set_span_id (self:log_record) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 7); self.span_id <- x +let[@inline] log_record_set_event_name (self:log_record) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 8); self.event_name <- x + +let copy_log_record (self:log_record) : log_record = + { self with time_unix_nano = self.time_unix_nano } + +let make_log_record + ?(time_unix_nano:int64 option) + ?(observed_time_unix_nano:int64 option) + ?(severity_number:severity_number option) + ?(severity_text:string option) + ?(body:Common.any_value option) + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + ?(flags:int32 option) + ?(trace_id:bytes option) + ?(span_id:bytes option) + ?(event_name:string option) + () : log_record = + let _res = default_log_record () in + (match time_unix_nano with + | None -> () + | Some v -> log_record_set_time_unix_nano _res v); + (match observed_time_unix_nano with + | None -> () + | Some v -> log_record_set_observed_time_unix_nano _res v); + (match severity_number with + | None -> () + | Some v -> log_record_set_severity_number _res v); + (match severity_text with + | None -> () + | Some v -> log_record_set_severity_text _res v); + (match body with + | None -> () + | Some v -> log_record_set_body _res v); + log_record_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> log_record_set_dropped_attributes_count _res v); + (match flags with + | None -> () + | Some v -> log_record_set_flags _res v); + (match trace_id with + | None -> () + | Some v -> log_record_set_trace_id _res v); + (match span_id with + | None -> () + | Some v -> log_record_set_span_id _res v); + (match event_name with + | None -> () + | Some v -> log_record_set_event_name _res v); + _res + +let[@inline] scope_logs_has_schema_url (self:scope_logs) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] scope_logs_set_scope (self:scope_logs) (x:Common.instrumentation_scope) : unit = + self.scope <- Some x +let[@inline] scope_logs_set_log_records (self:scope_logs) (x:log_record list) : unit = + self.log_records <- x +let[@inline] scope_logs_set_schema_url (self:scope_logs) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_scope_logs (self:scope_logs) : scope_logs = + { self with scope = self.scope } + +let make_scope_logs + ?(scope:Common.instrumentation_scope option) + ?(log_records=[]) + ?(schema_url:string option) + () : scope_logs = + let _res = default_scope_logs () in + (match scope with + | None -> () + | Some v -> scope_logs_set_scope _res v); + scope_logs_set_log_records _res log_records; + (match schema_url with + | None -> () + | Some v -> scope_logs_set_schema_url _res v); + _res + +let[@inline] resource_logs_has_schema_url (self:resource_logs) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] resource_logs_set_resource (self:resource_logs) (x:Resource.resource) : unit = + self.resource <- Some x +let[@inline] resource_logs_set_scope_logs (self:resource_logs) (x:scope_logs list) : unit = + self.scope_logs <- x +let[@inline] resource_logs_set_schema_url (self:resource_logs) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_resource_logs (self:resource_logs) : resource_logs = + { self with resource = self.resource } + +let make_resource_logs + ?(resource:Resource.resource option) + ?(scope_logs=[]) + ?(schema_url:string option) + () : resource_logs = + let _res = default_resource_logs () in + (match resource with + | None -> () + | Some v -> resource_logs_set_resource _res v); + resource_logs_set_scope_logs _res scope_logs; + (match schema_url with + | None -> () + | Some v -> resource_logs_set_schema_url _res v); + _res + + +let[@inline] logs_data_set_resource_logs (self:logs_data) (x:resource_logs list) : unit = + self.resource_logs <- x + +let copy_logs_data (self:logs_data) : logs_data = + { self with resource_logs = self.resource_logs } + +let make_logs_data + ?(resource_logs=[]) + () : logs_data = + let _res = default_logs_data () in + logs_data_set_resource_logs _res resource_logs; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -261,16 +293,17 @@ let rec pp_severity_number fmt (v:severity_number) = let rec pp_log_record fmt (v:log_record) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "observed_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.observed_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "severity_number" pp_severity_number fmt v.severity_number; - Pbrt.Pp.pp_record_field ~first:false "severity_text" Pbrt.Pp.pp_string fmt v.severity_text; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_time_unix_nano v)) ~first:true "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_observed_time_unix_nano v)) ~first:false "observed_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.observed_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_severity_number v)) ~first:false "severity_number" pp_severity_number fmt v.severity_number; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_severity_text v)) ~first:false "severity_text" Pbrt.Pp.pp_string fmt v.severity_text; Pbrt.Pp.pp_record_field ~first:false "body" (Pbrt.Pp.pp_option Common.pp_any_value) fmt v.body; Pbrt.Pp.pp_record_field ~first:false "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; - Pbrt.Pp.pp_record_field ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; - Pbrt.Pp.pp_record_field ~first:false "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; - Pbrt.Pp.pp_record_field ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_trace_id v)) ~first:false "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_span_id v)) ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; + Pbrt.Pp.pp_record_field ~absent:(not (log_record_has_event_name v)) ~first:false "event_name" Pbrt.Pp.pp_string fmt v.event_name; in Pbrt.Pp.pp_brk pp_i fmt () @@ -278,7 +311,7 @@ let rec pp_scope_logs fmt (v:scope_logs) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "scope" (Pbrt.Pp.pp_option Common.pp_instrumentation_scope) fmt v.scope; Pbrt.Pp.pp_record_field ~first:false "log_records" (Pbrt.Pp.pp_list pp_log_record) fmt v.log_records; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (scope_logs_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -286,7 +319,7 @@ let rec pp_resource_logs fmt (v:resource_logs) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "resource" (Pbrt.Pp.pp_option Resource.pp_resource) fmt v.resource; Pbrt.Pp.pp_record_field ~first:false "scope_logs" (Pbrt.Pp.pp_list pp_scope_logs) fmt v.scope_logs; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (resource_logs_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -301,7 +334,7 @@ let rec pp_log_record_flags fmt (v:log_record_flags) = | Log_record_flags_do_not_use -> Format.fprintf fmt "Log_record_flags_do_not_use" | Log_record_flags_trace_flags_mask -> Format.fprintf fmt "Log_record_flags_trace_flags_mask" -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) @@ -334,32 +367,52 @@ let rec encode_pb_severity_number (v:severity_number) encoder = | Severity_number_fatal4 -> Pbrt.Encoder.int_as_varint 24 encoder let rec encode_pb_log_record (v:log_record) encoder = - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.observed_time_unix_nano encoder; - Pbrt.Encoder.key 11 Pbrt.Bits64 encoder; - encode_pb_severity_number v.severity_number encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - Pbrt.Encoder.string v.severity_text encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if log_record_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; + ); + if log_record_has_observed_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.observed_time_unix_nano encoder; + Pbrt.Encoder.key 11 Pbrt.Bits64 encoder; + ); + if log_record_has_severity_number v then ( + encode_pb_severity_number v.severity_number encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + ); + if log_record_has_severity_text v then ( + Pbrt.Encoder.string v.severity_text encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); begin match v.body with | Some x -> Pbrt.Encoder.nested Common.encode_pb_any_value x encoder; Pbrt.Encoder.key 5 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 6 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 7 Pbrt.Varint encoder; - Pbrt.Encoder.int32_as_bits32 v.flags encoder; - Pbrt.Encoder.key 8 Pbrt.Bits32 encoder; - Pbrt.Encoder.bytes v.trace_id encoder; - Pbrt.Encoder.key 9 Pbrt.Bytes encoder; - Pbrt.Encoder.bytes v.span_id encoder; - Pbrt.Encoder.key 10 Pbrt.Bytes encoder; + if log_record_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 7 Pbrt.Varint encoder; + ); + if log_record_has_flags v then ( + Pbrt.Encoder.int32_as_bits32 v.flags encoder; + Pbrt.Encoder.key 8 Pbrt.Bits32 encoder; + ); + if log_record_has_trace_id v then ( + Pbrt.Encoder.bytes v.trace_id encoder; + Pbrt.Encoder.key 9 Pbrt.Bytes encoder; + ); + if log_record_has_span_id v then ( + Pbrt.Encoder.bytes v.span_id encoder; + Pbrt.Encoder.key 10 Pbrt.Bytes encoder; + ); + if log_record_has_event_name v then ( + Pbrt.Encoder.string v.event_name encoder; + Pbrt.Encoder.key 12 Pbrt.Bytes encoder; + ); () let rec encode_pb_scope_logs (v:scope_logs) encoder = @@ -369,12 +422,14 @@ let rec encode_pb_scope_logs (v:scope_logs) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_log_record x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.log_records encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if scope_logs_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_resource_logs (v:resource_logs) encoder = @@ -384,16 +439,18 @@ let rec encode_pb_resource_logs (v:resource_logs) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_scope_logs x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.scope_logs encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if resource_logs_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_logs_data (v:logs_data) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_resource_logs x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_logs encoder; @@ -404,195 +461,183 @@ let rec encode_pb_log_record_flags (v:log_record_flags) encoder = | Log_record_flags_do_not_use -> Pbrt.Encoder.int_as_varint (0) encoder | Log_record_flags_trace_flags_mask -> Pbrt.Encoder.int_as_varint 255 encoder -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) -let rec decode_pb_severity_number d = +let rec decode_pb_severity_number d : severity_number = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Severity_number_unspecified:severity_number) - | 1 -> (Severity_number_trace:severity_number) - | 2 -> (Severity_number_trace2:severity_number) - | 3 -> (Severity_number_trace3:severity_number) - | 4 -> (Severity_number_trace4:severity_number) - | 5 -> (Severity_number_debug:severity_number) - | 6 -> (Severity_number_debug2:severity_number) - | 7 -> (Severity_number_debug3:severity_number) - | 8 -> (Severity_number_debug4:severity_number) - | 9 -> (Severity_number_info:severity_number) - | 10 -> (Severity_number_info2:severity_number) - | 11 -> (Severity_number_info3:severity_number) - | 12 -> (Severity_number_info4:severity_number) - | 13 -> (Severity_number_warn:severity_number) - | 14 -> (Severity_number_warn2:severity_number) - | 15 -> (Severity_number_warn3:severity_number) - | 16 -> (Severity_number_warn4:severity_number) - | 17 -> (Severity_number_error:severity_number) - | 18 -> (Severity_number_error2:severity_number) - | 19 -> (Severity_number_error3:severity_number) - | 20 -> (Severity_number_error4:severity_number) - | 21 -> (Severity_number_fatal:severity_number) - | 22 -> (Severity_number_fatal2:severity_number) - | 23 -> (Severity_number_fatal3:severity_number) - | 24 -> (Severity_number_fatal4:severity_number) + | 0 -> Severity_number_unspecified + | 1 -> Severity_number_trace + | 2 -> Severity_number_trace2 + | 3 -> Severity_number_trace3 + | 4 -> Severity_number_trace4 + | 5 -> Severity_number_debug + | 6 -> Severity_number_debug2 + | 7 -> Severity_number_debug3 + | 8 -> Severity_number_debug4 + | 9 -> Severity_number_info + | 10 -> Severity_number_info2 + | 11 -> Severity_number_info3 + | 12 -> Severity_number_info4 + | 13 -> Severity_number_warn + | 14 -> Severity_number_warn2 + | 15 -> Severity_number_warn3 + | 16 -> Severity_number_warn4 + | 17 -> Severity_number_error + | 18 -> Severity_number_error2 + | 19 -> Severity_number_error3 + | 20 -> Severity_number_error4 + | 21 -> Severity_number_fatal + | 22 -> Severity_number_fatal2 + | 23 -> Severity_number_fatal3 + | 24 -> Severity_number_fatal4 | _ -> Pbrt.Decoder.malformed_variant "severity_number" let rec decode_pb_log_record d = - let v = default_log_record_mutable () in + let v = default_log_record () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + log_record_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + log_record_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 1 pk | Some (11, Pbrt.Bits64) -> begin - v.observed_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + log_record_set_observed_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(11)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 11 pk | Some (2, Pbrt.Varint) -> begin - v.severity_number <- decode_pb_severity_number d; + log_record_set_severity_number v (decode_pb_severity_number d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.severity_text <- Pbrt.Decoder.string d; + log_record_set_severity_text v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 3 pk | Some (5, Pbrt.Bytes) -> begin - v.body <- Some (Common.decode_pb_any_value (Pbrt.Decoder.nested d)); + log_record_set_body v (Common.decode_pb_any_value (Pbrt.Decoder.nested d)); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 5 pk | Some (6, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + log_record_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 6 pk | Some (7, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + log_record_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 7 pk | Some (8, Pbrt.Bits32) -> begin - v.flags <- Pbrt.Decoder.int32_as_bits32 d; + log_record_set_flags v (Pbrt.Decoder.int32_as_bits32 d); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 8 pk | Some (9, Pbrt.Bytes) -> begin - v.trace_id <- Pbrt.Decoder.bytes d; + log_record_set_trace_id v (Pbrt.Decoder.bytes d); end | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(9)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 9 pk | Some (10, Pbrt.Bytes) -> begin - v.span_id <- Pbrt.Decoder.bytes d; + log_record_set_span_id v (Pbrt.Decoder.bytes d); end | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(log_record), field(10)" pk + Pbrt.Decoder.unexpected_payload_message "log_record" 10 pk + | Some (12, Pbrt.Bytes) -> begin + log_record_set_event_name v (Pbrt.Decoder.string d); + end + | Some (12, pk) -> + Pbrt.Decoder.unexpected_payload_message "log_record" 12 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - time_unix_nano = v.time_unix_nano; - observed_time_unix_nano = v.observed_time_unix_nano; - severity_number = v.severity_number; - severity_text = v.severity_text; - body = v.body; - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - flags = v.flags; - trace_id = v.trace_id; - span_id = v.span_id; - } : log_record) + (v : log_record) let rec decode_pb_scope_logs d = - let v = default_scope_logs_mutable () in + let v = default_scope_logs () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.log_records <- List.rev v.log_records; + (* put lists in the correct order *) + scope_logs_set_log_records v (List.rev v.log_records); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.scope <- Some (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); + scope_logs_set_scope v (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_logs), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "scope_logs" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.log_records <- (decode_pb_log_record (Pbrt.Decoder.nested d)) :: v.log_records; + scope_logs_set_log_records v ((decode_pb_log_record (Pbrt.Decoder.nested d)) :: v.log_records); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_logs), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "scope_logs" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + scope_logs_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_logs), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "scope_logs" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - scope = v.scope; - log_records = v.log_records; - schema_url = v.schema_url; - } : scope_logs) + (v : scope_logs) let rec decode_pb_resource_logs d = - let v = default_resource_logs_mutable () in + let v = default_resource_logs () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.scope_logs <- List.rev v.scope_logs; + (* put lists in the correct order *) + resource_logs_set_scope_logs v (List.rev v.scope_logs); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource <- Some (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); + resource_logs_set_resource v (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_logs), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "resource_logs" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.scope_logs <- (decode_pb_scope_logs (Pbrt.Decoder.nested d)) :: v.scope_logs; + resource_logs_set_scope_logs v ((decode_pb_scope_logs (Pbrt.Decoder.nested d)) :: v.scope_logs); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_logs), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "resource_logs" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + resource_logs_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_logs), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "resource_logs" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource = v.resource; - scope_logs = v.scope_logs; - schema_url = v.schema_url; - } : resource_logs) + (v : resource_logs) let rec decode_pb_logs_data d = - let v = default_logs_data_mutable () in + let v = default_logs_data () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_logs <- List.rev v.resource_logs; + (* put lists in the correct order *) + logs_data_set_resource_logs v (List.rev v.resource_logs); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_logs <- (decode_pb_resource_logs (Pbrt.Decoder.nested d)) :: v.resource_logs; + logs_data_set_resource_logs v ((decode_pb_resource_logs (Pbrt.Decoder.nested d)) :: v.resource_logs); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(logs_data), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "logs_data" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_logs = v.resource_logs; - } : logs_data) + (v : logs_data) -let rec decode_pb_log_record_flags d = +let rec decode_pb_log_record_flags d : log_record_flags = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Log_record_flags_do_not_use:log_record_flags) - | 255 -> (Log_record_flags_trace_flags_mask:log_record_flags) + | 0 -> Log_record_flags_do_not_use + | 255 -> Log_record_flags_trace_flags_mask | _ -> Pbrt.Decoder.malformed_variant "log_record_flags" diff --git a/src/proto/logs.mli b/src/proto/logs.mli index 84dd9c0c..c291480b 100644 --- a/src/proto/logs.mli +++ b/src/proto/logs.mli @@ -34,33 +34,37 @@ type severity_number = | Severity_number_fatal3 | Severity_number_fatal4 -type log_record = { - time_unix_nano : int64; - observed_time_unix_nano : int64; - severity_number : severity_number; - severity_text : string; - body : Common.any_value option; - attributes : Common.key_value list; - dropped_attributes_count : int32; - flags : int32; - trace_id : bytes; - span_id : bytes; +type log_record = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 9 fields *) + mutable time_unix_nano : int64; + mutable observed_time_unix_nano : int64; + mutable severity_number : severity_number; + mutable severity_text : string; + mutable body : Common.any_value option; + mutable attributes : Common.key_value list; + mutable dropped_attributes_count : int32; + mutable flags : int32; + mutable trace_id : bytes; + mutable span_id : bytes; + mutable event_name : string; } -type scope_logs = { - scope : Common.instrumentation_scope option; - log_records : log_record list; - schema_url : string; +type scope_logs = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable scope : Common.instrumentation_scope option; + mutable log_records : log_record list; + mutable schema_url : string; } -type resource_logs = { - resource : Resource.resource option; - scope_logs : scope_logs list; - schema_url : string; +type resource_logs = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable resource : Resource.resource option; + mutable scope_logs : scope_logs list; + mutable schema_url : string; } -type logs_data = { - resource_logs : resource_logs list; +type logs_data = private { + mutable resource_logs : resource_logs list; } type log_record_flags = @@ -71,89 +75,158 @@ type log_record_flags = (** {2 Basic values} *) val default_severity_number : unit -> severity_number -(** [default_severity_number ()] is the default value for type [severity_number] *) +(** [default_severity_number ()] is a new empty value for type [severity_number] *) -val default_log_record : +val default_log_record : unit -> log_record +(** [default_log_record ()] is a new empty value for type [log_record] *) + +val default_scope_logs : unit -> scope_logs +(** [default_scope_logs ()] is a new empty value for type [scope_logs] *) + +val default_resource_logs : unit -> resource_logs +(** [default_resource_logs ()] is a new empty value for type [resource_logs] *) + +val default_logs_data : unit -> logs_data +(** [default_logs_data ()] is a new empty value for type [logs_data] *) + +val default_log_record_flags : unit -> log_record_flags +(** [default_log_record_flags ()] is a new empty value for type [log_record_flags] *) + + +(** {2 Make functions} *) + +val make_log_record : ?time_unix_nano:int64 -> ?observed_time_unix_nano:int64 -> ?severity_number:severity_number -> ?severity_text:string -> - ?body:Common.any_value option -> + ?body:Common.any_value -> ?attributes:Common.key_value list -> ?dropped_attributes_count:int32 -> ?flags:int32 -> ?trace_id:bytes -> ?span_id:bytes -> + ?event_name:string -> unit -> log_record -(** [default_log_record ()] is the default value for type [log_record] *) +(** [make_log_record … ()] is a builder for type [log_record] *) -val default_scope_logs : - ?scope:Common.instrumentation_scope option -> - ?log_records:log_record list -> - ?schema_url:string -> - unit -> - scope_logs -(** [default_scope_logs ()] is the default value for type [scope_logs] *) +val copy_log_record : log_record -> log_record -val default_resource_logs : - ?resource:Resource.resource option -> - ?scope_logs:scope_logs list -> - ?schema_url:string -> - unit -> - resource_logs -(** [default_resource_logs ()] is the default value for type [resource_logs] *) +val log_record_has_time_unix_nano : log_record -> bool + (** presence of field "time_unix_nano" in [log_record] *) -val default_logs_data : - ?resource_logs:resource_logs list -> - unit -> - logs_data -(** [default_logs_data ()] is the default value for type [logs_data] *) +val log_record_set_time_unix_nano : log_record -> int64 -> unit + (** set field time_unix_nano in log_record *) -val default_log_record_flags : unit -> log_record_flags -(** [default_log_record_flags ()] is the default value for type [log_record_flags] *) +val log_record_has_observed_time_unix_nano : log_record -> bool + (** presence of field "observed_time_unix_nano" in [log_record] *) +val log_record_set_observed_time_unix_nano : log_record -> int64 -> unit + (** set field observed_time_unix_nano in log_record *) -(** {2 Make functions} *) +val log_record_has_severity_number : log_record -> bool + (** presence of field "severity_number" in [log_record] *) +val log_record_set_severity_number : log_record -> severity_number -> unit + (** set field severity_number in log_record *) -val make_log_record : - time_unix_nano:int64 -> - observed_time_unix_nano:int64 -> - severity_number:severity_number -> - severity_text:string -> - ?body:Common.any_value option -> - attributes:Common.key_value list -> - dropped_attributes_count:int32 -> - flags:int32 -> - trace_id:bytes -> - span_id:bytes -> - unit -> - log_record -(** [make_log_record … ()] is a builder for type [log_record] *) +val log_record_has_severity_text : log_record -> bool + (** presence of field "severity_text" in [log_record] *) + +val log_record_set_severity_text : log_record -> string -> unit + (** set field severity_text in log_record *) + +val log_record_set_body : log_record -> Common.any_value -> unit + (** set field body in log_record *) + +val log_record_set_attributes : log_record -> Common.key_value list -> unit + (** set field attributes in log_record *) + +val log_record_has_dropped_attributes_count : log_record -> bool + (** presence of field "dropped_attributes_count" in [log_record] *) + +val log_record_set_dropped_attributes_count : log_record -> int32 -> unit + (** set field dropped_attributes_count in log_record *) + +val log_record_has_flags : log_record -> bool + (** presence of field "flags" in [log_record] *) + +val log_record_set_flags : log_record -> int32 -> unit + (** set field flags in log_record *) + +val log_record_has_trace_id : log_record -> bool + (** presence of field "trace_id" in [log_record] *) + +val log_record_set_trace_id : log_record -> bytes -> unit + (** set field trace_id in log_record *) + +val log_record_has_span_id : log_record -> bool + (** presence of field "span_id" in [log_record] *) + +val log_record_set_span_id : log_record -> bytes -> unit + (** set field span_id in log_record *) + +val log_record_has_event_name : log_record -> bool + (** presence of field "event_name" in [log_record] *) + +val log_record_set_event_name : log_record -> string -> unit + (** set field event_name in log_record *) val make_scope_logs : - ?scope:Common.instrumentation_scope option -> - log_records:log_record list -> - schema_url:string -> + ?scope:Common.instrumentation_scope -> + ?log_records:log_record list -> + ?schema_url:string -> unit -> scope_logs (** [make_scope_logs … ()] is a builder for type [scope_logs] *) +val copy_scope_logs : scope_logs -> scope_logs + +val scope_logs_set_scope : scope_logs -> Common.instrumentation_scope -> unit + (** set field scope in scope_logs *) + +val scope_logs_set_log_records : scope_logs -> log_record list -> unit + (** set field log_records in scope_logs *) + +val scope_logs_has_schema_url : scope_logs -> bool + (** presence of field "schema_url" in [scope_logs] *) + +val scope_logs_set_schema_url : scope_logs -> string -> unit + (** set field schema_url in scope_logs *) + val make_resource_logs : - ?resource:Resource.resource option -> - scope_logs:scope_logs list -> - schema_url:string -> + ?resource:Resource.resource -> + ?scope_logs:scope_logs list -> + ?schema_url:string -> unit -> resource_logs (** [make_resource_logs … ()] is a builder for type [resource_logs] *) +val copy_resource_logs : resource_logs -> resource_logs + +val resource_logs_set_resource : resource_logs -> Resource.resource -> unit + (** set field resource in resource_logs *) + +val resource_logs_set_scope_logs : resource_logs -> scope_logs list -> unit + (** set field scope_logs in resource_logs *) + +val resource_logs_has_schema_url : resource_logs -> bool + (** presence of field "schema_url" in [resource_logs] *) + +val resource_logs_set_schema_url : resource_logs -> string -> unit + (** set field schema_url in resource_logs *) + val make_logs_data : - resource_logs:resource_logs list -> + ?resource_logs:resource_logs list -> unit -> logs_data (** [make_logs_data … ()] is a builder for type [logs_data] *) +val copy_logs_data : logs_data -> logs_data + +val logs_data_set_resource_logs : logs_data -> resource_logs list -> unit + (** set field resource_logs in logs_data *) (** {2 Formatters} *) diff --git a/src/proto/logs_service.ml b/src/proto/logs_service.ml index 8e271c59..d7050174 100644 --- a/src/proto/logs_service.ml +++ b/src/proto/logs_service.ml @@ -1,88 +1,94 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type export_logs_service_request = { - resource_logs : Logs.resource_logs list; + mutable resource_logs : Logs.resource_logs list; } type export_logs_partial_success = { - rejected_log_records : int64; - error_message : string; + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_log_records : int64; + mutable error_message : string; } type export_logs_service_response = { - partial_success : export_logs_partial_success option; + mutable partial_success : export_logs_partial_success option; } -let rec default_export_logs_service_request - ?resource_logs:((resource_logs:Logs.resource_logs list) = []) - () : export_logs_service_request = { - resource_logs; +let default_export_logs_service_request (): export_logs_service_request = +{ + resource_logs=[]; } -let rec default_export_logs_partial_success - ?rejected_log_records:((rejected_log_records:int64) = 0L) - ?error_message:((error_message:string) = "") - () : export_logs_partial_success = { - rejected_log_records; - error_message; +let default_export_logs_partial_success (): export_logs_partial_success = +{ + _presence=Pbrt.Bitfield.empty; + rejected_log_records=0L; + error_message=""; } -let rec default_export_logs_service_response - ?partial_success:((partial_success:export_logs_partial_success option) = None) - () : export_logs_service_response = { - partial_success; +let default_export_logs_service_response (): export_logs_service_response = +{ + partial_success=None; } -type export_logs_service_request_mutable = { - mutable resource_logs : Logs.resource_logs list; -} -let default_export_logs_service_request_mutable () : export_logs_service_request_mutable = { - resource_logs = []; -} +(** {2 Make functions} *) -type export_logs_partial_success_mutable = { - mutable rejected_log_records : int64; - mutable error_message : string; -} -let default_export_logs_partial_success_mutable () : export_logs_partial_success_mutable = { - rejected_log_records = 0L; - error_message = ""; -} +let[@inline] export_logs_service_request_set_resource_logs (self:export_logs_service_request) (x:Logs.resource_logs list) : unit = + self.resource_logs <- x -type export_logs_service_response_mutable = { - mutable partial_success : export_logs_partial_success option; -} +let copy_export_logs_service_request (self:export_logs_service_request) : export_logs_service_request = + { self with resource_logs = self.resource_logs } -let default_export_logs_service_response_mutable () : export_logs_service_response_mutable = { - partial_success = None; -} +let make_export_logs_service_request + ?(resource_logs=[]) + () : export_logs_service_request = + let _res = default_export_logs_service_request () in + export_logs_service_request_set_resource_logs _res resource_logs; + _res +let[@inline] export_logs_partial_success_has_rejected_log_records (self:export_logs_partial_success) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] export_logs_partial_success_has_error_message (self:export_logs_partial_success) : bool = (Pbrt.Bitfield.get self._presence 1) -(** {2 Make functions} *) +let[@inline] export_logs_partial_success_set_rejected_log_records (self:export_logs_partial_success) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.rejected_log_records <- x +let[@inline] export_logs_partial_success_set_error_message (self:export_logs_partial_success) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.error_message <- x -let rec make_export_logs_service_request - ~(resource_logs:Logs.resource_logs list) - () : export_logs_service_request = { - resource_logs; -} +let copy_export_logs_partial_success (self:export_logs_partial_success) : export_logs_partial_success = + { self with rejected_log_records = self.rejected_log_records } -let rec make_export_logs_partial_success - ~(rejected_log_records:int64) - ~(error_message:string) - () : export_logs_partial_success = { - rejected_log_records; - error_message; -} +let make_export_logs_partial_success + ?(rejected_log_records:int64 option) + ?(error_message:string option) + () : export_logs_partial_success = + let _res = default_export_logs_partial_success () in + (match rejected_log_records with + | None -> () + | Some v -> export_logs_partial_success_set_rejected_log_records _res v); + (match error_message with + | None -> () + | Some v -> export_logs_partial_success_set_error_message _res v); + _res -let rec make_export_logs_service_response - ?partial_success:((partial_success:export_logs_partial_success option) = None) - () : export_logs_service_response = { - partial_success; -} -[@@@ocaml.warning "-27-30-39"] +let[@inline] export_logs_service_response_set_partial_success (self:export_logs_service_response) (x:export_logs_partial_success) : unit = + self.partial_success <- Some x + +let copy_export_logs_service_response (self:export_logs_service_response) : export_logs_service_response = + { self with partial_success = self.partial_success } + +let make_export_logs_service_response + ?(partial_success:export_logs_partial_success option) + () : export_logs_service_response = + let _res = default_export_logs_service_response () in + (match partial_success with + | None -> () + | Some v -> export_logs_service_response_set_partial_success _res v); + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -94,8 +100,8 @@ let rec pp_export_logs_service_request fmt (v:export_logs_service_request) = let rec pp_export_logs_partial_success fmt (v:export_logs_partial_success) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "rejected_log_records" Pbrt.Pp.pp_int64 fmt v.rejected_log_records; - Pbrt.Pp.pp_record_field ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; + Pbrt.Pp.pp_record_field ~absent:(not (export_logs_partial_success_has_rejected_log_records v)) ~first:true "rejected_log_records" Pbrt.Pp.pp_int64 fmt v.rejected_log_records; + Pbrt.Pp.pp_record_field ~absent:(not (export_logs_partial_success_has_error_message v)) ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; in Pbrt.Pp.pp_brk pp_i fmt () @@ -105,22 +111,26 @@ let rec pp_export_logs_service_response fmt (v:export_logs_service_response) = in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) let rec encode_pb_export_logs_service_request (v:export_logs_service_request) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Logs.encode_pb_resource_logs x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_logs encoder; () let rec encode_pb_export_logs_partial_success (v:export_logs_partial_success) encoder = - Pbrt.Encoder.int64_as_varint v.rejected_log_records encoder; - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.string v.error_message encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + if export_logs_partial_success_has_rejected_log_records v then ( + Pbrt.Encoder.int64_as_varint v.rejected_log_records encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + ); + if export_logs_partial_success_has_error_message v then ( + Pbrt.Encoder.string v.error_message encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); () let rec encode_pb_export_logs_service_response (v:export_logs_service_response) encoder = @@ -132,67 +142,61 @@ let rec encode_pb_export_logs_service_response (v:export_logs_service_response) end; () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) let rec decode_pb_export_logs_service_request d = - let v = default_export_logs_service_request_mutable () in + let v = default_export_logs_service_request () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_logs <- List.rev v.resource_logs; + (* put lists in the correct order *) + export_logs_service_request_set_resource_logs v (List.rev v.resource_logs); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_logs <- (Logs.decode_pb_resource_logs (Pbrt.Decoder.nested d)) :: v.resource_logs; + export_logs_service_request_set_resource_logs v ((Logs.decode_pb_resource_logs (Pbrt.Decoder.nested d)) :: v.resource_logs); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_logs_service_request), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_logs_service_request" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_logs = v.resource_logs; - } : export_logs_service_request) + (v : export_logs_service_request) let rec decode_pb_export_logs_partial_success d = - let v = default_export_logs_partial_success_mutable () in + let v = default_export_logs_partial_success () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.rejected_log_records <- Pbrt.Decoder.int64_as_varint d; + export_logs_partial_success_set_rejected_log_records v (Pbrt.Decoder.int64_as_varint d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_logs_partial_success), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_logs_partial_success" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.error_message <- Pbrt.Decoder.string d; + export_logs_partial_success_set_error_message v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_logs_partial_success), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "export_logs_partial_success" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - rejected_log_records = v.rejected_log_records; - error_message = v.error_message; - } : export_logs_partial_success) + (v : export_logs_partial_success) let rec decode_pb_export_logs_service_response d = - let v = default_export_logs_service_response_mutable () in + let v = default_export_logs_service_response () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.partial_success <- Some (decode_pb_export_logs_partial_success (Pbrt.Decoder.nested d)); + export_logs_service_response_set_partial_success v (decode_pb_export_logs_partial_success (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_logs_service_response), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_logs_service_response" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - partial_success = v.partial_success; - } : export_logs_service_response) + (v : export_logs_service_response) diff --git a/src/proto/logs_service.mli b/src/proto/logs_service.mli index 5e3f24d9..4ba05f0d 100644 --- a/src/proto/logs_service.mli +++ b/src/proto/logs_service.mli @@ -7,63 +7,78 @@ (** {2 Types} *) -type export_logs_service_request = { - resource_logs : Logs.resource_logs list; +type export_logs_service_request = private { + mutable resource_logs : Logs.resource_logs list; } -type export_logs_partial_success = { - rejected_log_records : int64; - error_message : string; +type export_logs_partial_success = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_log_records : int64; + mutable error_message : string; } -type export_logs_service_response = { - partial_success : export_logs_partial_success option; +type export_logs_service_response = private { + mutable partial_success : export_logs_partial_success option; } (** {2 Basic values} *) -val default_export_logs_service_request : - ?resource_logs:Logs.resource_logs list -> - unit -> - export_logs_service_request -(** [default_export_logs_service_request ()] is the default value for type [export_logs_service_request] *) +val default_export_logs_service_request : unit -> export_logs_service_request +(** [default_export_logs_service_request ()] is a new empty value for type [export_logs_service_request] *) -val default_export_logs_partial_success : - ?rejected_log_records:int64 -> - ?error_message:string -> - unit -> - export_logs_partial_success -(** [default_export_logs_partial_success ()] is the default value for type [export_logs_partial_success] *) +val default_export_logs_partial_success : unit -> export_logs_partial_success +(** [default_export_logs_partial_success ()] is a new empty value for type [export_logs_partial_success] *) -val default_export_logs_service_response : - ?partial_success:export_logs_partial_success option -> - unit -> - export_logs_service_response -(** [default_export_logs_service_response ()] is the default value for type [export_logs_service_response] *) +val default_export_logs_service_response : unit -> export_logs_service_response +(** [default_export_logs_service_response ()] is a new empty value for type [export_logs_service_response] *) (** {2 Make functions} *) val make_export_logs_service_request : - resource_logs:Logs.resource_logs list -> + ?resource_logs:Logs.resource_logs list -> unit -> export_logs_service_request (** [make_export_logs_service_request … ()] is a builder for type [export_logs_service_request] *) +val copy_export_logs_service_request : export_logs_service_request -> export_logs_service_request + +val export_logs_service_request_set_resource_logs : export_logs_service_request -> Logs.resource_logs list -> unit + (** set field resource_logs in export_logs_service_request *) + val make_export_logs_partial_success : - rejected_log_records:int64 -> - error_message:string -> + ?rejected_log_records:int64 -> + ?error_message:string -> unit -> export_logs_partial_success (** [make_export_logs_partial_success … ()] is a builder for type [export_logs_partial_success] *) +val copy_export_logs_partial_success : export_logs_partial_success -> export_logs_partial_success + +val export_logs_partial_success_has_rejected_log_records : export_logs_partial_success -> bool + (** presence of field "rejected_log_records" in [export_logs_partial_success] *) + +val export_logs_partial_success_set_rejected_log_records : export_logs_partial_success -> int64 -> unit + (** set field rejected_log_records in export_logs_partial_success *) + +val export_logs_partial_success_has_error_message : export_logs_partial_success -> bool + (** presence of field "error_message" in [export_logs_partial_success] *) + +val export_logs_partial_success_set_error_message : export_logs_partial_success -> string -> unit + (** set field error_message in export_logs_partial_success *) + val make_export_logs_service_response : - ?partial_success:export_logs_partial_success option -> + ?partial_success:export_logs_partial_success -> unit -> export_logs_service_response (** [make_export_logs_service_response … ()] is a builder for type [export_logs_service_response] *) +val copy_export_logs_service_response : export_logs_service_response -> export_logs_service_response + +val export_logs_service_response_set_partial_success : export_logs_service_response -> export_logs_partial_success -> unit + (** set field partial_success in export_logs_service_response *) + (** {2 Formatters} *) diff --git a/src/proto/metrics.ml b/src/proto/metrics.ml index a829c10b..df9093b2 100644 --- a/src/proto/metrics.ml +++ b/src/proto/metrics.ml @@ -1,509 +1,107 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type exemplar_value = | As_double of float | As_int of int64 and exemplar = { - filtered_attributes : Common.key_value list; - time_unix_nano : int64; - value : exemplar_value; - span_id : bytes; - trace_id : bytes; -} - -type number_data_point_value = - | As_double of float - | As_int of int64 - -and number_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - value : number_data_point_value; - exemplars : exemplar list; - flags : int32; -} - -type gauge = { - data_points : number_data_point list; -} - -type aggregation_temporality = - | Aggregation_temporality_unspecified - | Aggregation_temporality_delta - | Aggregation_temporality_cumulative - -type sum = { - data_points : number_data_point list; - aggregation_temporality : aggregation_temporality; - is_monotonic : bool; -} - -type histogram_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float option; - bucket_counts : int64 list; - explicit_bounds : float list; - exemplars : exemplar list; - flags : int32; - min : float option; - max : float option; -} - -type histogram = { - data_points : histogram_data_point list; - aggregation_temporality : aggregation_temporality; -} - -type exponential_histogram_data_point_buckets = { - offset : int32; - bucket_counts : int64 list; -} - -type exponential_histogram_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float option; - scale : int32; - zero_count : int64; - positive : exponential_histogram_data_point_buckets option; - negative : exponential_histogram_data_point_buckets option; - flags : int32; - exemplars : exemplar list; - min : float option; - max : float option; - zero_threshold : float; -} - -type exponential_histogram = { - data_points : exponential_histogram_data_point list; - aggregation_temporality : aggregation_temporality; -} - -type summary_data_point_value_at_quantile = { - quantile : float; - value : float; -} - -type summary_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float; - quantile_values : summary_data_point_value_at_quantile list; - flags : int32; -} - -type summary = { - data_points : summary_data_point list; -} - -type metric_data = - | Gauge of gauge - | Sum of sum - | Histogram of histogram - | Exponential_histogram of exponential_histogram - | Summary of summary - -and metric = { - name : string; - description : string; - unit_ : string; - data : metric_data; -} - -type scope_metrics = { - scope : Common.instrumentation_scope option; - metrics : metric list; - schema_url : string; -} - -type resource_metrics = { - resource : Resource.resource option; - scope_metrics : scope_metrics list; - schema_url : string; -} - -type metrics_data = { - resource_metrics : resource_metrics list; -} - -type data_point_flags = - | Data_point_flags_do_not_use - | Data_point_flags_no_recorded_value_mask - -let rec default_exemplar_value () : exemplar_value = As_double (0.) - -and default_exemplar - ?filtered_attributes:((filtered_attributes:Common.key_value list) = []) - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?value:((value:exemplar_value) = As_double (0.)) - ?span_id:((span_id:bytes) = Bytes.create 0) - ?trace_id:((trace_id:bytes) = Bytes.create 0) - () : exemplar = { - filtered_attributes; - time_unix_nano; - value; - span_id; - trace_id; -} - -let rec default_number_data_point_value () : number_data_point_value = As_double (0.) - -and default_number_data_point - ?attributes:((attributes:Common.key_value list) = []) - ?start_time_unix_nano:((start_time_unix_nano:int64) = 0L) - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?value:((value:number_data_point_value) = As_double (0.)) - ?exemplars:((exemplars:exemplar list) = []) - ?flags:((flags:int32) = 0l) - () : number_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - value; - exemplars; - flags; -} - -let rec default_gauge - ?data_points:((data_points:number_data_point list) = []) - () : gauge = { - data_points; -} - -let rec default_aggregation_temporality () = (Aggregation_temporality_unspecified:aggregation_temporality) - -let rec default_sum - ?data_points:((data_points:number_data_point list) = []) - ?aggregation_temporality:((aggregation_temporality:aggregation_temporality) = default_aggregation_temporality ()) - ?is_monotonic:((is_monotonic:bool) = false) - () : sum = { - data_points; - aggregation_temporality; - is_monotonic; -} - -let rec default_histogram_data_point - ?attributes:((attributes:Common.key_value list) = []) - ?start_time_unix_nano:((start_time_unix_nano:int64) = 0L) - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?count:((count:int64) = 0L) - ?sum:((sum:float option) = None) - ?bucket_counts:((bucket_counts:int64 list) = []) - ?explicit_bounds:((explicit_bounds:float list) = []) - ?exemplars:((exemplars:exemplar list) = []) - ?flags:((flags:int32) = 0l) - ?min:((min:float option) = None) - ?max:((max:float option) = None) - () : histogram_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - bucket_counts; - explicit_bounds; - exemplars; - flags; - min; - max; -} - -let rec default_histogram - ?data_points:((data_points:histogram_data_point list) = []) - ?aggregation_temporality:((aggregation_temporality:aggregation_temporality) = default_aggregation_temporality ()) - () : histogram = { - data_points; - aggregation_temporality; -} - -let rec default_exponential_histogram_data_point_buckets - ?offset:((offset:int32) = 0l) - ?bucket_counts:((bucket_counts:int64 list) = []) - () : exponential_histogram_data_point_buckets = { - offset; - bucket_counts; -} - -let rec default_exponential_histogram_data_point - ?attributes:((attributes:Common.key_value list) = []) - ?start_time_unix_nano:((start_time_unix_nano:int64) = 0L) - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?count:((count:int64) = 0L) - ?sum:((sum:float option) = None) - ?scale:((scale:int32) = 0l) - ?zero_count:((zero_count:int64) = 0L) - ?positive:((positive:exponential_histogram_data_point_buckets option) = None) - ?negative:((negative:exponential_histogram_data_point_buckets option) = None) - ?flags:((flags:int32) = 0l) - ?exemplars:((exemplars:exemplar list) = []) - ?min:((min:float option) = None) - ?max:((max:float option) = None) - ?zero_threshold:((zero_threshold:float) = 0.) - () : exponential_histogram_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - scale; - zero_count; - positive; - negative; - flags; - exemplars; - min; - max; - zero_threshold; -} - -let rec default_exponential_histogram - ?data_points:((data_points:exponential_histogram_data_point list) = []) - ?aggregation_temporality:((aggregation_temporality:aggregation_temporality) = default_aggregation_temporality ()) - () : exponential_histogram = { - data_points; - aggregation_temporality; -} - -let rec default_summary_data_point_value_at_quantile - ?quantile:((quantile:float) = 0.) - ?value:((value:float) = 0.) - () : summary_data_point_value_at_quantile = { - quantile; - value; -} - -let rec default_summary_data_point - ?attributes:((attributes:Common.key_value list) = []) - ?start_time_unix_nano:((start_time_unix_nano:int64) = 0L) - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?count:((count:int64) = 0L) - ?sum:((sum:float) = 0.) - ?quantile_values:((quantile_values:summary_data_point_value_at_quantile list) = []) - ?flags:((flags:int32) = 0l) - () : summary_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - quantile_values; - flags; -} - -let rec default_summary - ?data_points:((data_points:summary_data_point list) = []) - () : summary = { - data_points; -} - -let rec default_metric_data () : metric_data = Gauge (default_gauge ()) - -and default_metric - ?name:((name:string) = "") - ?description:((description:string) = "") - ?unit_:((unit_:string) = "") - ?data:((data:metric_data) = Gauge (default_gauge ())) - () : metric = { - name; - description; - unit_; - data; -} - -let rec default_scope_metrics - ?scope:((scope:Common.instrumentation_scope option) = None) - ?metrics:((metrics:metric list) = []) - ?schema_url:((schema_url:string) = "") - () : scope_metrics = { - scope; - metrics; - schema_url; -} - -let rec default_resource_metrics - ?resource:((resource:Resource.resource option) = None) - ?scope_metrics:((scope_metrics:scope_metrics list) = []) - ?schema_url:((schema_url:string) = "") - () : resource_metrics = { - resource; - scope_metrics; - schema_url; -} - -let rec default_metrics_data - ?resource_metrics:((resource_metrics:resource_metrics list) = []) - () : metrics_data = { - resource_metrics; -} - -let rec default_data_point_flags () = (Data_point_flags_do_not_use:data_point_flags) - -type exemplar_mutable = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) mutable filtered_attributes : Common.key_value list; mutable time_unix_nano : int64; - mutable value : exemplar_value; + mutable value : exemplar_value option; mutable span_id : bytes; mutable trace_id : bytes; } -let default_exemplar_mutable () : exemplar_mutable = { - filtered_attributes = []; - time_unix_nano = 0L; - value = As_double (0.); - span_id = Bytes.create 0; - trace_id = Bytes.create 0; -} +type number_data_point_value = + | As_double of float + | As_int of int64 -type number_data_point_mutable = { +and number_data_point = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) mutable attributes : Common.key_value list; mutable start_time_unix_nano : int64; mutable time_unix_nano : int64; - mutable value : number_data_point_value; + mutable value : number_data_point_value option; mutable exemplars : exemplar list; mutable flags : int32; } -let default_number_data_point_mutable () : number_data_point_mutable = { - attributes = []; - start_time_unix_nano = 0L; - time_unix_nano = 0L; - value = As_double (0.); - exemplars = []; - flags = 0l; -} - -type gauge_mutable = { +type gauge = { mutable data_points : number_data_point list; } -let default_gauge_mutable () : gauge_mutable = { - data_points = []; -} +type aggregation_temporality = + | Aggregation_temporality_unspecified + | Aggregation_temporality_delta + | Aggregation_temporality_cumulative -type sum_mutable = { +type sum = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) mutable data_points : number_data_point list; mutable aggregation_temporality : aggregation_temporality; mutable is_monotonic : bool; } -let default_sum_mutable () : sum_mutable = { - data_points = []; - aggregation_temporality = default_aggregation_temporality (); - is_monotonic = false; -} - -type histogram_data_point_mutable = { +type histogram_data_point = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 7 fields *) mutable attributes : Common.key_value list; mutable start_time_unix_nano : int64; mutable time_unix_nano : int64; mutable count : int64; - mutable sum : float option; + mutable sum : float; mutable bucket_counts : int64 list; mutable explicit_bounds : float list; mutable exemplars : exemplar list; mutable flags : int32; - mutable min : float option; - mutable max : float option; + mutable min : float; + mutable max : float; } -let default_histogram_data_point_mutable () : histogram_data_point_mutable = { - attributes = []; - start_time_unix_nano = 0L; - time_unix_nano = 0L; - count = 0L; - sum = None; - bucket_counts = []; - explicit_bounds = []; - exemplars = []; - flags = 0l; - min = None; - max = None; -} - -type histogram_mutable = { +type histogram = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable data_points : histogram_data_point list; mutable aggregation_temporality : aggregation_temporality; } -let default_histogram_mutable () : histogram_mutable = { - data_points = []; - aggregation_temporality = default_aggregation_temporality (); -} - -type exponential_histogram_data_point_buckets_mutable = { +type exponential_histogram_data_point_buckets = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable offset : int32; mutable bucket_counts : int64 list; } -let default_exponential_histogram_data_point_buckets_mutable () : exponential_histogram_data_point_buckets_mutable = { - offset = 0l; - bucket_counts = []; -} - -type exponential_histogram_data_point_mutable = { +type exponential_histogram_data_point = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 10 fields *) mutable attributes : Common.key_value list; mutable start_time_unix_nano : int64; mutable time_unix_nano : int64; mutable count : int64; - mutable sum : float option; + mutable sum : float; mutable scale : int32; mutable zero_count : int64; mutable positive : exponential_histogram_data_point_buckets option; mutable negative : exponential_histogram_data_point_buckets option; mutable flags : int32; mutable exemplars : exemplar list; - mutable min : float option; - mutable max : float option; + mutable min : float; + mutable max : float; mutable zero_threshold : float; } -let default_exponential_histogram_data_point_mutable () : exponential_histogram_data_point_mutable = { - attributes = []; - start_time_unix_nano = 0L; - time_unix_nano = 0L; - count = 0L; - sum = None; - scale = 0l; - zero_count = 0L; - positive = None; - negative = None; - flags = 0l; - exemplars = []; - min = None; - max = None; - zero_threshold = 0.; -} - -type exponential_histogram_mutable = { +type exponential_histogram = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable data_points : exponential_histogram_data_point list; mutable aggregation_temporality : aggregation_temporality; } -let default_exponential_histogram_mutable () : exponential_histogram_mutable = { - data_points = []; - aggregation_temporality = default_aggregation_temporality (); -} - -type summary_data_point_value_at_quantile_mutable = { +type summary_data_point_value_at_quantile = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) mutable quantile : float; mutable value : float; } -let default_summary_data_point_value_at_quantile_mutable () : summary_data_point_value_at_quantile_mutable = { - quantile = 0.; - value = 0.; -} - -type summary_data_point_mutable = { +type summary_data_point = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 5 fields *) mutable attributes : Common.key_value list; mutable start_time_unix_nano : int64; mutable time_unix_nano : int64; @@ -513,277 +111,773 @@ type summary_data_point_mutable = { mutable flags : int32; } -let default_summary_data_point_mutable () : summary_data_point_mutable = { - attributes = []; - start_time_unix_nano = 0L; - time_unix_nano = 0L; - count = 0L; - sum = 0.; - quantile_values = []; - flags = 0l; -} - -type summary_mutable = { +type summary = { mutable data_points : summary_data_point list; } -let default_summary_mutable () : summary_mutable = { - data_points = []; -} +type metric_data = + | Gauge of gauge + | Sum of sum + | Histogram of histogram + | Exponential_histogram of exponential_histogram + | Summary of summary -type metric_mutable = { +and metric = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) mutable name : string; mutable description : string; mutable unit_ : string; - mutable data : metric_data; -} - -let default_metric_mutable () : metric_mutable = { - name = ""; - description = ""; - unit_ = ""; - data = Gauge (default_gauge ()); + mutable data : metric_data option; + mutable metadata : Common.key_value list; } -type scope_metrics_mutable = { +type scope_metrics = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable scope : Common.instrumentation_scope option; mutable metrics : metric list; mutable schema_url : string; } -let default_scope_metrics_mutable () : scope_metrics_mutable = { - scope = None; - metrics = []; - schema_url = ""; -} - -type resource_metrics_mutable = { +type resource_metrics = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable resource : Resource.resource option; mutable scope_metrics : scope_metrics list; mutable schema_url : string; } -let default_resource_metrics_mutable () : resource_metrics_mutable = { - resource = None; - scope_metrics = []; - schema_url = ""; -} - -type metrics_data_mutable = { +type metrics_data = { mutable resource_metrics : resource_metrics list; } -let default_metrics_data_mutable () : metrics_data_mutable = { - resource_metrics = []; -} - - -(** {2 Make functions} *) - - -let rec make_exemplar - ~(filtered_attributes:Common.key_value list) - ~(time_unix_nano:int64) - ~(value:exemplar_value) - ~(span_id:bytes) - ~(trace_id:bytes) - () : exemplar = { - filtered_attributes; - time_unix_nano; - value; - span_id; - trace_id; -} - - -let rec make_number_data_point - ~(attributes:Common.key_value list) - ~(start_time_unix_nano:int64) - ~(time_unix_nano:int64) - ~(value:number_data_point_value) - ~(exemplars:exemplar list) - ~(flags:int32) - () : number_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - value; - exemplars; - flags; -} - -let rec make_gauge - ~(data_points:number_data_point list) - () : gauge = { - data_points; -} +type data_point_flags = + | Data_point_flags_do_not_use + | Data_point_flags_no_recorded_value_mask +let default_exemplar_value (): exemplar_value = As_double (0.) + +let default_exemplar (): exemplar = +{ + _presence=Pbrt.Bitfield.empty; + filtered_attributes=[]; + time_unix_nano=0L; + value=None; + span_id=Bytes.create 0; + trace_id=Bytes.create 0; +} + +let default_number_data_point_value (): number_data_point_value = As_double (0.) + +let default_number_data_point (): number_data_point = +{ + _presence=Pbrt.Bitfield.empty; + attributes=[]; + start_time_unix_nano=0L; + time_unix_nano=0L; + value=None; + exemplars=[]; + flags=0l; +} + +let default_gauge (): gauge = +{ + data_points=[]; +} + +let default_aggregation_temporality () = (Aggregation_temporality_unspecified:aggregation_temporality) + +let default_sum (): sum = +{ + _presence=Pbrt.Bitfield.empty; + data_points=[]; + aggregation_temporality=default_aggregation_temporality (); + is_monotonic=false; +} + +let default_histogram_data_point (): histogram_data_point = +{ + _presence=Pbrt.Bitfield.empty; + attributes=[]; + start_time_unix_nano=0L; + time_unix_nano=0L; + count=0L; + sum=0.; + bucket_counts=[]; + explicit_bounds=[]; + exemplars=[]; + flags=0l; + min=0.; + max=0.; +} -let rec make_sum - ~(data_points:number_data_point list) - ~(aggregation_temporality:aggregation_temporality) - ~(is_monotonic:bool) - () : sum = { - data_points; - aggregation_temporality; - is_monotonic; +let default_histogram (): histogram = +{ + _presence=Pbrt.Bitfield.empty; + data_points=[]; + aggregation_temporality=default_aggregation_temporality (); } -let rec make_histogram_data_point - ~(attributes:Common.key_value list) - ~(start_time_unix_nano:int64) - ~(time_unix_nano:int64) - ~(count:int64) - ?sum:((sum:float option) = None) - ~(bucket_counts:int64 list) - ~(explicit_bounds:float list) - ~(exemplars:exemplar list) - ~(flags:int32) - ?min:((min:float option) = None) - ?max:((max:float option) = None) - () : histogram_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - bucket_counts; - explicit_bounds; - exemplars; - flags; - min; - max; +let default_exponential_histogram_data_point_buckets (): exponential_histogram_data_point_buckets = +{ + _presence=Pbrt.Bitfield.empty; + offset=0l; + bucket_counts=[]; } -let rec make_histogram - ~(data_points:histogram_data_point list) - ~(aggregation_temporality:aggregation_temporality) - () : histogram = { - data_points; - aggregation_temporality; +let default_exponential_histogram_data_point (): exponential_histogram_data_point = +{ + _presence=Pbrt.Bitfield.empty; + attributes=[]; + start_time_unix_nano=0L; + time_unix_nano=0L; + count=0L; + sum=0.; + scale=0l; + zero_count=0L; + positive=None; + negative=None; + flags=0l; + exemplars=[]; + min=0.; + max=0.; + zero_threshold=0.; } -let rec make_exponential_histogram_data_point_buckets - ~(offset:int32) - ~(bucket_counts:int64 list) - () : exponential_histogram_data_point_buckets = { - offset; - bucket_counts; +let default_exponential_histogram (): exponential_histogram = +{ + _presence=Pbrt.Bitfield.empty; + data_points=[]; + aggregation_temporality=default_aggregation_temporality (); } -let rec make_exponential_histogram_data_point - ~(attributes:Common.key_value list) - ~(start_time_unix_nano:int64) - ~(time_unix_nano:int64) - ~(count:int64) - ?sum:((sum:float option) = None) - ~(scale:int32) - ~(zero_count:int64) - ?positive:((positive:exponential_histogram_data_point_buckets option) = None) - ?negative:((negative:exponential_histogram_data_point_buckets option) = None) - ~(flags:int32) - ~(exemplars:exemplar list) - ?min:((min:float option) = None) - ?max:((max:float option) = None) - ~(zero_threshold:float) - () : exponential_histogram_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - scale; - zero_count; - positive; - negative; - flags; - exemplars; - min; - max; - zero_threshold; +let default_summary_data_point_value_at_quantile (): summary_data_point_value_at_quantile = +{ + _presence=Pbrt.Bitfield.empty; + quantile=0.; + value=0.; } - -let rec make_exponential_histogram - ~(data_points:exponential_histogram_data_point list) - ~(aggregation_temporality:aggregation_temporality) - () : exponential_histogram = { - data_points; - aggregation_temporality; + +let default_summary_data_point (): summary_data_point = +{ + _presence=Pbrt.Bitfield.empty; + attributes=[]; + start_time_unix_nano=0L; + time_unix_nano=0L; + count=0L; + sum=0.; + quantile_values=[]; + flags=0l; } - -let rec make_summary_data_point_value_at_quantile - ~(quantile:float) - ~(value:float) - () : summary_data_point_value_at_quantile = { - quantile; - value; + +let default_summary (): summary = +{ + data_points=[]; } -let rec make_summary_data_point - ~(attributes:Common.key_value list) - ~(start_time_unix_nano:int64) - ~(time_unix_nano:int64) - ~(count:int64) - ~(sum:float) - ~(quantile_values:summary_data_point_value_at_quantile list) - ~(flags:int32) - () : summary_data_point = { - attributes; - start_time_unix_nano; - time_unix_nano; - count; - sum; - quantile_values; - flags; -} +let default_metric_data (): metric_data = Gauge (default_gauge ()) -let rec make_summary - ~(data_points:summary_data_point list) - () : summary = { - data_points; +let default_metric (): metric = +{ + _presence=Pbrt.Bitfield.empty; + name=""; + description=""; + unit_=""; + data=None; + metadata=[]; +} + +let default_scope_metrics (): scope_metrics = +{ + _presence=Pbrt.Bitfield.empty; + scope=None; + metrics=[]; + schema_url=""; } - - -let rec make_metric - ~(name:string) - ~(description:string) - ~(unit_:string) - ~(data:metric_data) - () : metric = { - name; - description; - unit_; - data; + +let default_resource_metrics (): resource_metrics = +{ + _presence=Pbrt.Bitfield.empty; + resource=None; + scope_metrics=[]; + schema_url=""; } -let rec make_scope_metrics - ?scope:((scope:Common.instrumentation_scope option) = None) - ~(metrics:metric list) - ~(schema_url:string) - () : scope_metrics = { - scope; - metrics; - schema_url; +let default_metrics_data (): metrics_data = +{ + resource_metrics=[]; } -let rec make_resource_metrics - ?resource:((resource:Resource.resource option) = None) - ~(scope_metrics:scope_metrics list) - ~(schema_url:string) - () : resource_metrics = { - resource; - scope_metrics; - schema_url; -} +let default_data_point_flags () = (Data_point_flags_do_not_use:data_point_flags) -let rec make_metrics_data - ~(resource_metrics:resource_metrics list) - () : metrics_data = { - resource_metrics; -} +(** {2 Make functions} *) -[@@@ocaml.warning "-27-30-39"] +let[@inline] exemplar_has_time_unix_nano (self:exemplar) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] exemplar_has_span_id (self:exemplar) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] exemplar_has_trace_id (self:exemplar) : bool = (Pbrt.Bitfield.get self._presence 2) + +let[@inline] exemplar_set_filtered_attributes (self:exemplar) (x:Common.key_value list) : unit = + self.filtered_attributes <- x +let[@inline] exemplar_set_time_unix_nano (self:exemplar) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.time_unix_nano <- x +let[@inline] exemplar_set_value (self:exemplar) (x:exemplar_value) : unit = + self.value <- Some x +let[@inline] exemplar_set_span_id (self:exemplar) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.span_id <- x +let[@inline] exemplar_set_trace_id (self:exemplar) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.trace_id <- x + +let copy_exemplar (self:exemplar) : exemplar = + { self with filtered_attributes = self.filtered_attributes } + +let make_exemplar + ?(filtered_attributes=[]) + ?(time_unix_nano:int64 option) + ?(value:exemplar_value option) + ?(span_id:bytes option) + ?(trace_id:bytes option) + () : exemplar = + let _res = default_exemplar () in + exemplar_set_filtered_attributes _res filtered_attributes; + (match time_unix_nano with + | None -> () + | Some v -> exemplar_set_time_unix_nano _res v); + (match value with + | None -> () + | Some v -> exemplar_set_value _res v); + (match span_id with + | None -> () + | Some v -> exemplar_set_span_id _res v); + (match trace_id with + | None -> () + | Some v -> exemplar_set_trace_id _res v); + _res + +let[@inline] number_data_point_has_start_time_unix_nano (self:number_data_point) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] number_data_point_has_time_unix_nano (self:number_data_point) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] number_data_point_has_flags (self:number_data_point) : bool = (Pbrt.Bitfield.get self._presence 2) + +let[@inline] number_data_point_set_attributes (self:number_data_point) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] number_data_point_set_start_time_unix_nano (self:number_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.start_time_unix_nano <- x +let[@inline] number_data_point_set_time_unix_nano (self:number_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.time_unix_nano <- x +let[@inline] number_data_point_set_value (self:number_data_point) (x:number_data_point_value) : unit = + self.value <- Some x +let[@inline] number_data_point_set_exemplars (self:number_data_point) (x:exemplar list) : unit = + self.exemplars <- x +let[@inline] number_data_point_set_flags (self:number_data_point) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.flags <- x + +let copy_number_data_point (self:number_data_point) : number_data_point = + { self with attributes = self.attributes } + +let make_number_data_point + ?(attributes=[]) + ?(start_time_unix_nano:int64 option) + ?(time_unix_nano:int64 option) + ?(value:number_data_point_value option) + ?(exemplars=[]) + ?(flags:int32 option) + () : number_data_point = + let _res = default_number_data_point () in + number_data_point_set_attributes _res attributes; + (match start_time_unix_nano with + | None -> () + | Some v -> number_data_point_set_start_time_unix_nano _res v); + (match time_unix_nano with + | None -> () + | Some v -> number_data_point_set_time_unix_nano _res v); + (match value with + | None -> () + | Some v -> number_data_point_set_value _res v); + number_data_point_set_exemplars _res exemplars; + (match flags with + | None -> () + | Some v -> number_data_point_set_flags _res v); + _res + + +let[@inline] gauge_set_data_points (self:gauge) (x:number_data_point list) : unit = + self.data_points <- x + +let copy_gauge (self:gauge) : gauge = + { self with data_points = self.data_points } + +let make_gauge + ?(data_points=[]) + () : gauge = + let _res = default_gauge () in + gauge_set_data_points _res data_points; + _res + +let[@inline] sum_has_aggregation_temporality (self:sum) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] sum_has_is_monotonic (self:sum) : bool = (Pbrt.Bitfield.get self._presence 1) + +let[@inline] sum_set_data_points (self:sum) (x:number_data_point list) : unit = + self.data_points <- x +let[@inline] sum_set_aggregation_temporality (self:sum) (x:aggregation_temporality) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.aggregation_temporality <- x +let[@inline] sum_set_is_monotonic (self:sum) (x:bool) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.is_monotonic <- x + +let copy_sum (self:sum) : sum = + { self with data_points = self.data_points } + +let make_sum + ?(data_points=[]) + ?(aggregation_temporality:aggregation_temporality option) + ?(is_monotonic:bool option) + () : sum = + let _res = default_sum () in + sum_set_data_points _res data_points; + (match aggregation_temporality with + | None -> () + | Some v -> sum_set_aggregation_temporality _res v); + (match is_monotonic with + | None -> () + | Some v -> sum_set_is_monotonic _res v); + _res + +let[@inline] histogram_data_point_has_start_time_unix_nano (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] histogram_data_point_has_time_unix_nano (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] histogram_data_point_has_count (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] histogram_data_point_has_sum (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] histogram_data_point_has_flags (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 4) +let[@inline] histogram_data_point_has_min (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 5) +let[@inline] histogram_data_point_has_max (self:histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 6) + +let[@inline] histogram_data_point_set_attributes (self:histogram_data_point) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] histogram_data_point_set_start_time_unix_nano (self:histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.start_time_unix_nano <- x +let[@inline] histogram_data_point_set_time_unix_nano (self:histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.time_unix_nano <- x +let[@inline] histogram_data_point_set_count (self:histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.count <- x +let[@inline] histogram_data_point_set_sum (self:histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.sum <- x +let[@inline] histogram_data_point_set_bucket_counts (self:histogram_data_point) (x:int64 list) : unit = + self.bucket_counts <- x +let[@inline] histogram_data_point_set_explicit_bounds (self:histogram_data_point) (x:float list) : unit = + self.explicit_bounds <- x +let[@inline] histogram_data_point_set_exemplars (self:histogram_data_point) (x:exemplar list) : unit = + self.exemplars <- x +let[@inline] histogram_data_point_set_flags (self:histogram_data_point) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.flags <- x +let[@inline] histogram_data_point_set_min (self:histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 5); self.min <- x +let[@inline] histogram_data_point_set_max (self:histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 6); self.max <- x + +let copy_histogram_data_point (self:histogram_data_point) : histogram_data_point = + { self with attributes = self.attributes } + +let make_histogram_data_point + ?(attributes=[]) + ?(start_time_unix_nano:int64 option) + ?(time_unix_nano:int64 option) + ?(count:int64 option) + ?(sum:float option) + ?(bucket_counts=[]) + ?(explicit_bounds=[]) + ?(exemplars=[]) + ?(flags:int32 option) + ?(min:float option) + ?(max:float option) + () : histogram_data_point = + let _res = default_histogram_data_point () in + histogram_data_point_set_attributes _res attributes; + (match start_time_unix_nano with + | None -> () + | Some v -> histogram_data_point_set_start_time_unix_nano _res v); + (match time_unix_nano with + | None -> () + | Some v -> histogram_data_point_set_time_unix_nano _res v); + (match count with + | None -> () + | Some v -> histogram_data_point_set_count _res v); + (match sum with + | None -> () + | Some v -> histogram_data_point_set_sum _res v); + histogram_data_point_set_bucket_counts _res bucket_counts; + histogram_data_point_set_explicit_bounds _res explicit_bounds; + histogram_data_point_set_exemplars _res exemplars; + (match flags with + | None -> () + | Some v -> histogram_data_point_set_flags _res v); + (match min with + | None -> () + | Some v -> histogram_data_point_set_min _res v); + (match max with + | None -> () + | Some v -> histogram_data_point_set_max _res v); + _res + +let[@inline] histogram_has_aggregation_temporality (self:histogram) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] histogram_set_data_points (self:histogram) (x:histogram_data_point list) : unit = + self.data_points <- x +let[@inline] histogram_set_aggregation_temporality (self:histogram) (x:aggregation_temporality) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.aggregation_temporality <- x + +let copy_histogram (self:histogram) : histogram = + { self with data_points = self.data_points } + +let make_histogram + ?(data_points=[]) + ?(aggregation_temporality:aggregation_temporality option) + () : histogram = + let _res = default_histogram () in + histogram_set_data_points _res data_points; + (match aggregation_temporality with + | None -> () + | Some v -> histogram_set_aggregation_temporality _res v); + _res + +let[@inline] exponential_histogram_data_point_buckets_has_offset (self:exponential_histogram_data_point_buckets) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] exponential_histogram_data_point_buckets_set_offset (self:exponential_histogram_data_point_buckets) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.offset <- x +let[@inline] exponential_histogram_data_point_buckets_set_bucket_counts (self:exponential_histogram_data_point_buckets) (x:int64 list) : unit = + self.bucket_counts <- x + +let copy_exponential_histogram_data_point_buckets (self:exponential_histogram_data_point_buckets) : exponential_histogram_data_point_buckets = + { self with offset = self.offset } + +let make_exponential_histogram_data_point_buckets + ?(offset:int32 option) + ?(bucket_counts=[]) + () : exponential_histogram_data_point_buckets = + let _res = default_exponential_histogram_data_point_buckets () in + (match offset with + | None -> () + | Some v -> exponential_histogram_data_point_buckets_set_offset _res v); + exponential_histogram_data_point_buckets_set_bucket_counts _res bucket_counts; + _res + +let[@inline] exponential_histogram_data_point_has_start_time_unix_nano (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] exponential_histogram_data_point_has_time_unix_nano (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] exponential_histogram_data_point_has_count (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] exponential_histogram_data_point_has_sum (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] exponential_histogram_data_point_has_scale (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 4) +let[@inline] exponential_histogram_data_point_has_zero_count (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 5) +let[@inline] exponential_histogram_data_point_has_flags (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 6) +let[@inline] exponential_histogram_data_point_has_min (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 7) +let[@inline] exponential_histogram_data_point_has_max (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 8) +let[@inline] exponential_histogram_data_point_has_zero_threshold (self:exponential_histogram_data_point) : bool = (Pbrt.Bitfield.get self._presence 9) + +let[@inline] exponential_histogram_data_point_set_attributes (self:exponential_histogram_data_point) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] exponential_histogram_data_point_set_start_time_unix_nano (self:exponential_histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.start_time_unix_nano <- x +let[@inline] exponential_histogram_data_point_set_time_unix_nano (self:exponential_histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.time_unix_nano <- x +let[@inline] exponential_histogram_data_point_set_count (self:exponential_histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.count <- x +let[@inline] exponential_histogram_data_point_set_sum (self:exponential_histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.sum <- x +let[@inline] exponential_histogram_data_point_set_scale (self:exponential_histogram_data_point) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.scale <- x +let[@inline] exponential_histogram_data_point_set_zero_count (self:exponential_histogram_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 5); self.zero_count <- x +let[@inline] exponential_histogram_data_point_set_positive (self:exponential_histogram_data_point) (x:exponential_histogram_data_point_buckets) : unit = + self.positive <- Some x +let[@inline] exponential_histogram_data_point_set_negative (self:exponential_histogram_data_point) (x:exponential_histogram_data_point_buckets) : unit = + self.negative <- Some x +let[@inline] exponential_histogram_data_point_set_flags (self:exponential_histogram_data_point) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 6); self.flags <- x +let[@inline] exponential_histogram_data_point_set_exemplars (self:exponential_histogram_data_point) (x:exemplar list) : unit = + self.exemplars <- x +let[@inline] exponential_histogram_data_point_set_min (self:exponential_histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 7); self.min <- x +let[@inline] exponential_histogram_data_point_set_max (self:exponential_histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 8); self.max <- x +let[@inline] exponential_histogram_data_point_set_zero_threshold (self:exponential_histogram_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 9); self.zero_threshold <- x + +let copy_exponential_histogram_data_point (self:exponential_histogram_data_point) : exponential_histogram_data_point = + { self with attributes = self.attributes } + +let make_exponential_histogram_data_point + ?(attributes=[]) + ?(start_time_unix_nano:int64 option) + ?(time_unix_nano:int64 option) + ?(count:int64 option) + ?(sum:float option) + ?(scale:int32 option) + ?(zero_count:int64 option) + ?(positive:exponential_histogram_data_point_buckets option) + ?(negative:exponential_histogram_data_point_buckets option) + ?(flags:int32 option) + ?(exemplars=[]) + ?(min:float option) + ?(max:float option) + ?(zero_threshold:float option) + () : exponential_histogram_data_point = + let _res = default_exponential_histogram_data_point () in + exponential_histogram_data_point_set_attributes _res attributes; + (match start_time_unix_nano with + | None -> () + | Some v -> exponential_histogram_data_point_set_start_time_unix_nano _res v); + (match time_unix_nano with + | None -> () + | Some v -> exponential_histogram_data_point_set_time_unix_nano _res v); + (match count with + | None -> () + | Some v -> exponential_histogram_data_point_set_count _res v); + (match sum with + | None -> () + | Some v -> exponential_histogram_data_point_set_sum _res v); + (match scale with + | None -> () + | Some v -> exponential_histogram_data_point_set_scale _res v); + (match zero_count with + | None -> () + | Some v -> exponential_histogram_data_point_set_zero_count _res v); + (match positive with + | None -> () + | Some v -> exponential_histogram_data_point_set_positive _res v); + (match negative with + | None -> () + | Some v -> exponential_histogram_data_point_set_negative _res v); + (match flags with + | None -> () + | Some v -> exponential_histogram_data_point_set_flags _res v); + exponential_histogram_data_point_set_exemplars _res exemplars; + (match min with + | None -> () + | Some v -> exponential_histogram_data_point_set_min _res v); + (match max with + | None -> () + | Some v -> exponential_histogram_data_point_set_max _res v); + (match zero_threshold with + | None -> () + | Some v -> exponential_histogram_data_point_set_zero_threshold _res v); + _res + +let[@inline] exponential_histogram_has_aggregation_temporality (self:exponential_histogram) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] exponential_histogram_set_data_points (self:exponential_histogram) (x:exponential_histogram_data_point list) : unit = + self.data_points <- x +let[@inline] exponential_histogram_set_aggregation_temporality (self:exponential_histogram) (x:aggregation_temporality) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.aggregation_temporality <- x + +let copy_exponential_histogram (self:exponential_histogram) : exponential_histogram = + { self with data_points = self.data_points } + +let make_exponential_histogram + ?(data_points=[]) + ?(aggregation_temporality:aggregation_temporality option) + () : exponential_histogram = + let _res = default_exponential_histogram () in + exponential_histogram_set_data_points _res data_points; + (match aggregation_temporality with + | None -> () + | Some v -> exponential_histogram_set_aggregation_temporality _res v); + _res + +let[@inline] summary_data_point_value_at_quantile_has_quantile (self:summary_data_point_value_at_quantile) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] summary_data_point_value_at_quantile_has_value (self:summary_data_point_value_at_quantile) : bool = (Pbrt.Bitfield.get self._presence 1) + +let[@inline] summary_data_point_value_at_quantile_set_quantile (self:summary_data_point_value_at_quantile) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.quantile <- x +let[@inline] summary_data_point_value_at_quantile_set_value (self:summary_data_point_value_at_quantile) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.value <- x + +let copy_summary_data_point_value_at_quantile (self:summary_data_point_value_at_quantile) : summary_data_point_value_at_quantile = + { self with quantile = self.quantile } + +let make_summary_data_point_value_at_quantile + ?(quantile:float option) + ?(value:float option) + () : summary_data_point_value_at_quantile = + let _res = default_summary_data_point_value_at_quantile () in + (match quantile with + | None -> () + | Some v -> summary_data_point_value_at_quantile_set_quantile _res v); + (match value with + | None -> () + | Some v -> summary_data_point_value_at_quantile_set_value _res v); + _res + +let[@inline] summary_data_point_has_start_time_unix_nano (self:summary_data_point) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] summary_data_point_has_time_unix_nano (self:summary_data_point) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] summary_data_point_has_count (self:summary_data_point) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] summary_data_point_has_sum (self:summary_data_point) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] summary_data_point_has_flags (self:summary_data_point) : bool = (Pbrt.Bitfield.get self._presence 4) + +let[@inline] summary_data_point_set_attributes (self:summary_data_point) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] summary_data_point_set_start_time_unix_nano (self:summary_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.start_time_unix_nano <- x +let[@inline] summary_data_point_set_time_unix_nano (self:summary_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.time_unix_nano <- x +let[@inline] summary_data_point_set_count (self:summary_data_point) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.count <- x +let[@inline] summary_data_point_set_sum (self:summary_data_point) (x:float) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.sum <- x +let[@inline] summary_data_point_set_quantile_values (self:summary_data_point) (x:summary_data_point_value_at_quantile list) : unit = + self.quantile_values <- x +let[@inline] summary_data_point_set_flags (self:summary_data_point) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.flags <- x + +let copy_summary_data_point (self:summary_data_point) : summary_data_point = + { self with attributes = self.attributes } + +let make_summary_data_point + ?(attributes=[]) + ?(start_time_unix_nano:int64 option) + ?(time_unix_nano:int64 option) + ?(count:int64 option) + ?(sum:float option) + ?(quantile_values=[]) + ?(flags:int32 option) + () : summary_data_point = + let _res = default_summary_data_point () in + summary_data_point_set_attributes _res attributes; + (match start_time_unix_nano with + | None -> () + | Some v -> summary_data_point_set_start_time_unix_nano _res v); + (match time_unix_nano with + | None -> () + | Some v -> summary_data_point_set_time_unix_nano _res v); + (match count with + | None -> () + | Some v -> summary_data_point_set_count _res v); + (match sum with + | None -> () + | Some v -> summary_data_point_set_sum _res v); + summary_data_point_set_quantile_values _res quantile_values; + (match flags with + | None -> () + | Some v -> summary_data_point_set_flags _res v); + _res + + +let[@inline] summary_set_data_points (self:summary) (x:summary_data_point list) : unit = + self.data_points <- x + +let copy_summary (self:summary) : summary = + { self with data_points = self.data_points } + +let make_summary + ?(data_points=[]) + () : summary = + let _res = default_summary () in + summary_set_data_points _res data_points; + _res + +let[@inline] metric_has_name (self:metric) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] metric_has_description (self:metric) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] metric_has_unit_ (self:metric) : bool = (Pbrt.Bitfield.get self._presence 2) + +let[@inline] metric_set_name (self:metric) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.name <- x +let[@inline] metric_set_description (self:metric) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.description <- x +let[@inline] metric_set_unit_ (self:metric) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.unit_ <- x +let[@inline] metric_set_data (self:metric) (x:metric_data) : unit = + self.data <- Some x +let[@inline] metric_set_metadata (self:metric) (x:Common.key_value list) : unit = + self.metadata <- x + +let copy_metric (self:metric) : metric = + { self with name = self.name } + +let make_metric + ?(name:string option) + ?(description:string option) + ?(unit_:string option) + ?(data:metric_data option) + ?(metadata=[]) + () : metric = + let _res = default_metric () in + (match name with + | None -> () + | Some v -> metric_set_name _res v); + (match description with + | None -> () + | Some v -> metric_set_description _res v); + (match unit_ with + | None -> () + | Some v -> metric_set_unit_ _res v); + (match data with + | None -> () + | Some v -> metric_set_data _res v); + metric_set_metadata _res metadata; + _res + +let[@inline] scope_metrics_has_schema_url (self:scope_metrics) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] scope_metrics_set_scope (self:scope_metrics) (x:Common.instrumentation_scope) : unit = + self.scope <- Some x +let[@inline] scope_metrics_set_metrics (self:scope_metrics) (x:metric list) : unit = + self.metrics <- x +let[@inline] scope_metrics_set_schema_url (self:scope_metrics) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_scope_metrics (self:scope_metrics) : scope_metrics = + { self with scope = self.scope } + +let make_scope_metrics + ?(scope:Common.instrumentation_scope option) + ?(metrics=[]) + ?(schema_url:string option) + () : scope_metrics = + let _res = default_scope_metrics () in + (match scope with + | None -> () + | Some v -> scope_metrics_set_scope _res v); + scope_metrics_set_metrics _res metrics; + (match schema_url with + | None -> () + | Some v -> scope_metrics_set_schema_url _res v); + _res + +let[@inline] resource_metrics_has_schema_url (self:resource_metrics) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] resource_metrics_set_resource (self:resource_metrics) (x:Resource.resource) : unit = + self.resource <- Some x +let[@inline] resource_metrics_set_scope_metrics (self:resource_metrics) (x:scope_metrics list) : unit = + self.scope_metrics <- x +let[@inline] resource_metrics_set_schema_url (self:resource_metrics) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_resource_metrics (self:resource_metrics) : resource_metrics = + { self with resource = self.resource } + +let make_resource_metrics + ?(resource:Resource.resource option) + ?(scope_metrics=[]) + ?(schema_url:string option) + () : resource_metrics = + let _res = default_resource_metrics () in + (match resource with + | None -> () + | Some v -> resource_metrics_set_resource _res v); + resource_metrics_set_scope_metrics _res scope_metrics; + (match schema_url with + | None -> () + | Some v -> resource_metrics_set_schema_url _res v); + _res + + +let[@inline] metrics_data_set_resource_metrics (self:metrics_data) (x:resource_metrics list) : unit = + self.resource_metrics <- x + +let copy_metrics_data (self:metrics_data) : metrics_data = + { self with resource_metrics = self.resource_metrics } + +let make_metrics_data + ?(resource_metrics=[]) + () : metrics_data = + let _res = default_metrics_data () in + metrics_data_set_resource_metrics _res resource_metrics; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -795,10 +889,10 @@ let rec pp_exemplar_value fmt (v:exemplar_value) = and pp_exemplar fmt (v:exemplar) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "filtered_attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.filtered_attributes; - Pbrt.Pp.pp_record_field ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "value" pp_exemplar_value fmt v.value; - Pbrt.Pp.pp_record_field ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; - Pbrt.Pp.pp_record_field ~first:false "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; + Pbrt.Pp.pp_record_field ~absent:(not (exemplar_has_time_unix_nano v)) ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~first:false "value" (Pbrt.Pp.pp_option pp_exemplar_value) fmt v.value; + Pbrt.Pp.pp_record_field ~absent:(not (exemplar_has_span_id v)) ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; + Pbrt.Pp.pp_record_field ~absent:(not (exemplar_has_trace_id v)) ~first:false "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; in Pbrt.Pp.pp_brk pp_i fmt () @@ -810,11 +904,11 @@ let rec pp_number_data_point_value fmt (v:number_data_point_value) = and pp_number_data_point fmt (v:number_data_point) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "value" pp_number_data_point_value fmt v.value; + Pbrt.Pp.pp_record_field ~absent:(not (number_data_point_has_start_time_unix_nano v)) ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (number_data_point_has_time_unix_nano v)) ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~first:false "value" (Pbrt.Pp.pp_option pp_number_data_point_value) fmt v.value; Pbrt.Pp.pp_record_field ~first:false "exemplars" (Pbrt.Pp.pp_list pp_exemplar) fmt v.exemplars; - Pbrt.Pp.pp_record_field ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (number_data_point_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; in Pbrt.Pp.pp_brk pp_i fmt () @@ -833,37 +927,37 @@ let rec pp_aggregation_temporality fmt (v:aggregation_temporality) = let rec pp_sum fmt (v:sum) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "data_points" (Pbrt.Pp.pp_list pp_number_data_point) fmt v.data_points; - Pbrt.Pp.pp_record_field ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; - Pbrt.Pp.pp_record_field ~first:false "is_monotonic" Pbrt.Pp.pp_bool fmt v.is_monotonic; + Pbrt.Pp.pp_record_field ~absent:(not (sum_has_aggregation_temporality v)) ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; + Pbrt.Pp.pp_record_field ~absent:(not (sum_has_is_monotonic v)) ~first:false "is_monotonic" Pbrt.Pp.pp_bool fmt v.is_monotonic; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_histogram_data_point fmt (v:histogram_data_point) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; - Pbrt.Pp.pp_record_field ~first:false "sum" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.sum; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_start_time_unix_nano v)) ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_time_unix_nano v)) ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_count v)) ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_sum v)) ~first:false "sum" Pbrt.Pp.pp_float fmt v.sum; Pbrt.Pp.pp_record_field ~first:false "bucket_counts" (Pbrt.Pp.pp_list Pbrt.Pp.pp_int64) fmt v.bucket_counts; Pbrt.Pp.pp_record_field ~first:false "explicit_bounds" (Pbrt.Pp.pp_list Pbrt.Pp.pp_float) fmt v.explicit_bounds; Pbrt.Pp.pp_record_field ~first:false "exemplars" (Pbrt.Pp.pp_list pp_exemplar) fmt v.exemplars; - Pbrt.Pp.pp_record_field ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; - Pbrt.Pp.pp_record_field ~first:false "min" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.min; - Pbrt.Pp.pp_record_field ~first:false "max" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.max; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_min v)) ~first:false "min" Pbrt.Pp.pp_float fmt v.min; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_data_point_has_max v)) ~first:false "max" Pbrt.Pp.pp_float fmt v.max; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_histogram fmt (v:histogram) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "data_points" (Pbrt.Pp.pp_list pp_histogram_data_point) fmt v.data_points; - Pbrt.Pp.pp_record_field ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; + Pbrt.Pp.pp_record_field ~absent:(not (histogram_has_aggregation_temporality v)) ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_exponential_histogram_data_point_buckets fmt (v:exponential_histogram_data_point_buckets) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "offset" Pbrt.Pp.pp_int32 fmt v.offset; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_buckets_has_offset v)) ~first:true "offset" Pbrt.Pp.pp_int32 fmt v.offset; Pbrt.Pp.pp_record_field ~first:false "bucket_counts" (Pbrt.Pp.pp_list Pbrt.Pp.pp_int64) fmt v.bucket_counts; in Pbrt.Pp.pp_brk pp_i fmt () @@ -871,45 +965,45 @@ let rec pp_exponential_histogram_data_point_buckets fmt (v:exponential_histogram let rec pp_exponential_histogram_data_point fmt (v:exponential_histogram_data_point) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; - Pbrt.Pp.pp_record_field ~first:false "sum" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.sum; - Pbrt.Pp.pp_record_field ~first:false "scale" Pbrt.Pp.pp_int32 fmt v.scale; - Pbrt.Pp.pp_record_field ~first:false "zero_count" Pbrt.Pp.pp_int64 fmt v.zero_count; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_start_time_unix_nano v)) ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_time_unix_nano v)) ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_count v)) ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_sum v)) ~first:false "sum" Pbrt.Pp.pp_float fmt v.sum; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_scale v)) ~first:false "scale" Pbrt.Pp.pp_int32 fmt v.scale; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_zero_count v)) ~first:false "zero_count" Pbrt.Pp.pp_int64 fmt v.zero_count; Pbrt.Pp.pp_record_field ~first:false "positive" (Pbrt.Pp.pp_option pp_exponential_histogram_data_point_buckets) fmt v.positive; Pbrt.Pp.pp_record_field ~first:false "negative" (Pbrt.Pp.pp_option pp_exponential_histogram_data_point_buckets) fmt v.negative; - Pbrt.Pp.pp_record_field ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; Pbrt.Pp.pp_record_field ~first:false "exemplars" (Pbrt.Pp.pp_list pp_exemplar) fmt v.exemplars; - Pbrt.Pp.pp_record_field ~first:false "min" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.min; - Pbrt.Pp.pp_record_field ~first:false "max" (Pbrt.Pp.pp_option Pbrt.Pp.pp_float) fmt v.max; - Pbrt.Pp.pp_record_field ~first:false "zero_threshold" Pbrt.Pp.pp_float fmt v.zero_threshold; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_min v)) ~first:false "min" Pbrt.Pp.pp_float fmt v.min; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_max v)) ~first:false "max" Pbrt.Pp.pp_float fmt v.max; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_data_point_has_zero_threshold v)) ~first:false "zero_threshold" Pbrt.Pp.pp_float fmt v.zero_threshold; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_exponential_histogram fmt (v:exponential_histogram) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "data_points" (Pbrt.Pp.pp_list pp_exponential_histogram_data_point) fmt v.data_points; - Pbrt.Pp.pp_record_field ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; + Pbrt.Pp.pp_record_field ~absent:(not (exponential_histogram_has_aggregation_temporality v)) ~first:false "aggregation_temporality" pp_aggregation_temporality fmt v.aggregation_temporality; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_summary_data_point_value_at_quantile fmt (v:summary_data_point_value_at_quantile) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "quantile" Pbrt.Pp.pp_float fmt v.quantile; - Pbrt.Pp.pp_record_field ~first:false "value" Pbrt.Pp.pp_float fmt v.value; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_value_at_quantile_has_quantile v)) ~first:true "quantile" Pbrt.Pp.pp_float fmt v.quantile; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_value_at_quantile_has_value v)) ~first:false "value" Pbrt.Pp.pp_float fmt v.value; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_summary_data_point fmt (v:summary_data_point) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; - Pbrt.Pp.pp_record_field ~first:false "sum" Pbrt.Pp.pp_float fmt v.sum; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_has_start_time_unix_nano v)) ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_has_time_unix_nano v)) ~first:false "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_has_count v)) ~first:false "count" Pbrt.Pp.pp_int64 fmt v.count; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_has_sum v)) ~first:false "sum" Pbrt.Pp.pp_float fmt v.sum; Pbrt.Pp.pp_record_field ~first:false "quantile_values" (Pbrt.Pp.pp_list pp_summary_data_point_value_at_quantile) fmt v.quantile_values; - Pbrt.Pp.pp_record_field ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (summary_data_point_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; in Pbrt.Pp.pp_brk pp_i fmt () @@ -929,10 +1023,11 @@ let rec pp_metric_data fmt (v:metric_data) = and pp_metric fmt (v:metric) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "name" Pbrt.Pp.pp_string fmt v.name; - Pbrt.Pp.pp_record_field ~first:false "description" Pbrt.Pp.pp_string fmt v.description; - Pbrt.Pp.pp_record_field ~first:false "unit_" Pbrt.Pp.pp_string fmt v.unit_; - Pbrt.Pp.pp_record_field ~first:false "data" pp_metric_data fmt v.data; + Pbrt.Pp.pp_record_field ~absent:(not (metric_has_name v)) ~first:true "name" Pbrt.Pp.pp_string fmt v.name; + Pbrt.Pp.pp_record_field ~absent:(not (metric_has_description v)) ~first:false "description" Pbrt.Pp.pp_string fmt v.description; + Pbrt.Pp.pp_record_field ~absent:(not (metric_has_unit_ v)) ~first:false "unit_" Pbrt.Pp.pp_string fmt v.unit_; + Pbrt.Pp.pp_record_field ~first:false "data" (Pbrt.Pp.pp_option pp_metric_data) fmt v.data; + Pbrt.Pp.pp_record_field ~first:false "metadata" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.metadata; in Pbrt.Pp.pp_brk pp_i fmt () @@ -940,7 +1035,7 @@ let rec pp_scope_metrics fmt (v:scope_metrics) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "scope" (Pbrt.Pp.pp_option Common.pp_instrumentation_scope) fmt v.scope; Pbrt.Pp.pp_record_field ~first:false "metrics" (Pbrt.Pp.pp_list pp_metric) fmt v.metrics; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (scope_metrics_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -948,7 +1043,7 @@ let rec pp_resource_metrics fmt (v:resource_metrics) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "resource" (Pbrt.Pp.pp_option Resource.pp_resource) fmt v.resource; Pbrt.Pp.pp_record_field ~first:false "scope_metrics" (Pbrt.Pp.pp_list pp_scope_metrics) fmt v.scope_metrics; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (resource_metrics_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -963,7 +1058,7 @@ let rec pp_data_point_flags fmt (v:data_point_flags) = | Data_point_flags_do_not_use -> Format.fprintf fmt "Data_point_flags_do_not_use" | Data_point_flags_no_recorded_value_mask -> Format.fprintf fmt "Data_point_flags_no_recorded_value_mask" -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) @@ -978,24 +1073,31 @@ let rec encode_pb_exemplar_value (v:exemplar_value) encoder = end and encode_pb_exemplar (v:exemplar) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 7 Pbrt.Bytes encoder; ) v.filtered_attributes encoder; - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + if exemplar_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); begin match v.value with - | As_double x -> + | None -> () + | Some (As_double x) -> Pbrt.Encoder.float_as_bits64 x encoder; Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; - | As_int x -> + | Some (As_int x) -> Pbrt.Encoder.int64_as_bits64 x encoder; Pbrt.Encoder.key 6 Pbrt.Bits64 encoder; end; - Pbrt.Encoder.bytes v.span_id encoder; - Pbrt.Encoder.key 4 Pbrt.Bytes encoder; - Pbrt.Encoder.bytes v.trace_id encoder; - Pbrt.Encoder.key 5 Pbrt.Bytes encoder; + if exemplar_has_span_id v then ( + Pbrt.Encoder.bytes v.span_id encoder; + Pbrt.Encoder.key 4 Pbrt.Bytes encoder; + ); + if exemplar_has_trace_id v then ( + Pbrt.Encoder.bytes v.trace_id encoder; + Pbrt.Encoder.key 5 Pbrt.Bytes encoder; + ); () let rec encode_pb_number_data_point_value (v:number_data_point_value) encoder = @@ -1009,32 +1111,39 @@ let rec encode_pb_number_data_point_value (v:number_data_point_value) encoder = end and encode_pb_number_data_point (v:number_data_point) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 7 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; + if number_data_point_has_start_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); + if number_data_point_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; + ); begin match v.value with - | As_double x -> + | None -> () + | Some (As_double x) -> Pbrt.Encoder.float_as_bits64 x encoder; Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; - | As_int x -> + | Some (As_int x) -> Pbrt.Encoder.int64_as_bits64 x encoder; Pbrt.Encoder.key 6 Pbrt.Bits64 encoder; end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_exemplar x encoder; Pbrt.Encoder.key 5 Pbrt.Bytes encoder; ) v.exemplars encoder; - Pbrt.Encoder.int32_as_varint v.flags encoder; - Pbrt.Encoder.key 8 Pbrt.Varint encoder; + if number_data_point_has_flags v then ( + Pbrt.Encoder.int32_as_varint v.flags encoder; + Pbrt.Encoder.key 8 Pbrt.Varint encoder; + ); () let rec encode_pb_gauge (v:gauge) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_number_data_point x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.data_points encoder; @@ -1047,79 +1156,89 @@ let rec encode_pb_aggregation_temporality (v:aggregation_temporality) encoder = | Aggregation_temporality_cumulative -> Pbrt.Encoder.int_as_varint 2 encoder let rec encode_pb_sum (v:sum) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_number_data_point x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.data_points encoder; - encode_pb_aggregation_temporality v.aggregation_temporality encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - Pbrt.Encoder.bool v.is_monotonic encoder; - Pbrt.Encoder.key 3 Pbrt.Varint encoder; + if sum_has_aggregation_temporality v then ( + encode_pb_aggregation_temporality v.aggregation_temporality encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + ); + if sum_has_is_monotonic v then ( + Pbrt.Encoder.bool v.is_monotonic encoder; + Pbrt.Encoder.key 3 Pbrt.Varint encoder; + ); () let rec encode_pb_histogram_data_point (v:histogram_data_point) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 9 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.count encoder; - Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; - begin match v.sum with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + if histogram_data_point_has_start_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); + if histogram_data_point_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; + ); + if histogram_data_point_has_count v then ( + Pbrt.Encoder.int64_as_bits64 v.count encoder; + Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; + ); + if histogram_data_point_has_sum v then ( + Pbrt.Encoder.float_as_bits64 v.sum encoder; Pbrt.Encoder.key 5 Pbrt.Bits64 encoder; - | None -> (); - end; + ); Pbrt.Encoder.nested (fun lst encoder -> - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.int64_as_bits64 x encoder; ) lst encoder; ) v.bucket_counts encoder; Pbrt.Encoder.key 6 Pbrt.Bytes encoder; Pbrt.Encoder.nested (fun lst encoder -> - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.float_as_bits64 x encoder; ) lst encoder; ) v.explicit_bounds encoder; Pbrt.Encoder.key 7 Pbrt.Bytes encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_exemplar x encoder; Pbrt.Encoder.key 8 Pbrt.Bytes encoder; ) v.exemplars encoder; - Pbrt.Encoder.int32_as_varint v.flags encoder; - Pbrt.Encoder.key 10 Pbrt.Varint encoder; - begin match v.min with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + if histogram_data_point_has_flags v then ( + Pbrt.Encoder.int32_as_varint v.flags encoder; + Pbrt.Encoder.key 10 Pbrt.Varint encoder; + ); + if histogram_data_point_has_min v then ( + Pbrt.Encoder.float_as_bits64 v.min encoder; Pbrt.Encoder.key 11 Pbrt.Bits64 encoder; - | None -> (); - end; - begin match v.max with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + ); + if histogram_data_point_has_max v then ( + Pbrt.Encoder.float_as_bits64 v.max encoder; Pbrt.Encoder.key 12 Pbrt.Bits64 encoder; - | None -> (); - end; + ); () let rec encode_pb_histogram (v:histogram) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_histogram_data_point x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.data_points encoder; - encode_pb_aggregation_temporality v.aggregation_temporality encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; + if histogram_has_aggregation_temporality v then ( + encode_pb_aggregation_temporality v.aggregation_temporality encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + ); () let rec encode_pb_exponential_histogram_data_point_buckets (v:exponential_histogram_data_point_buckets) encoder = - Pbrt.Encoder.int32_as_zigzag v.offset encoder; - Pbrt.Encoder.key 1 Pbrt.Varint encoder; + if exponential_histogram_data_point_buckets_has_offset v then ( + Pbrt.Encoder.int32_as_zigzag v.offset encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + ); Pbrt.Encoder.nested (fun lst encoder -> - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.int64_as_varint x encoder; ) lst encoder; ) v.bucket_counts encoder; @@ -1127,26 +1246,34 @@ let rec encode_pb_exponential_histogram_data_point_buckets (v:exponential_histog () let rec encode_pb_exponential_histogram_data_point (v:exponential_histogram_data_point) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.count encoder; - Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; - begin match v.sum with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + if exponential_histogram_data_point_has_start_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); + if exponential_histogram_data_point_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; + ); + if exponential_histogram_data_point_has_count v then ( + Pbrt.Encoder.int64_as_bits64 v.count encoder; + Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; + ); + if exponential_histogram_data_point_has_sum v then ( + Pbrt.Encoder.float_as_bits64 v.sum encoder; Pbrt.Encoder.key 5 Pbrt.Bits64 encoder; - | None -> (); - end; - Pbrt.Encoder.int32_as_zigzag v.scale encoder; - Pbrt.Encoder.key 6 Pbrt.Varint encoder; - Pbrt.Encoder.int64_as_bits64 v.zero_count encoder; - Pbrt.Encoder.key 7 Pbrt.Bits64 encoder; + ); + if exponential_histogram_data_point_has_scale v then ( + Pbrt.Encoder.int32_as_zigzag v.scale encoder; + Pbrt.Encoder.key 6 Pbrt.Varint encoder; + ); + if exponential_histogram_data_point_has_zero_count v then ( + Pbrt.Encoder.int64_as_bits64 v.zero_count encoder; + Pbrt.Encoder.key 7 Pbrt.Bits64 encoder; + ); begin match v.positive with | Some x -> Pbrt.Encoder.nested encode_pb_exponential_histogram_data_point_buckets x encoder; @@ -1159,67 +1286,83 @@ let rec encode_pb_exponential_histogram_data_point (v:exponential_histogram_data Pbrt.Encoder.key 9 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.Encoder.int32_as_varint v.flags encoder; - Pbrt.Encoder.key 10 Pbrt.Varint encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if exponential_histogram_data_point_has_flags v then ( + Pbrt.Encoder.int32_as_varint v.flags encoder; + Pbrt.Encoder.key 10 Pbrt.Varint encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_exemplar x encoder; Pbrt.Encoder.key 11 Pbrt.Bytes encoder; ) v.exemplars encoder; - begin match v.min with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + if exponential_histogram_data_point_has_min v then ( + Pbrt.Encoder.float_as_bits64 v.min encoder; Pbrt.Encoder.key 12 Pbrt.Bits64 encoder; - | None -> (); - end; - begin match v.max with - | Some x -> - Pbrt.Encoder.float_as_bits64 x encoder; + ); + if exponential_histogram_data_point_has_max v then ( + Pbrt.Encoder.float_as_bits64 v.max encoder; Pbrt.Encoder.key 13 Pbrt.Bits64 encoder; - | None -> (); - end; - Pbrt.Encoder.float_as_bits64 v.zero_threshold encoder; - Pbrt.Encoder.key 14 Pbrt.Bits64 encoder; + ); + if exponential_histogram_data_point_has_zero_threshold v then ( + Pbrt.Encoder.float_as_bits64 v.zero_threshold encoder; + Pbrt.Encoder.key 14 Pbrt.Bits64 encoder; + ); () let rec encode_pb_exponential_histogram (v:exponential_histogram) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_exponential_histogram_data_point x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.data_points encoder; - encode_pb_aggregation_temporality v.aggregation_temporality encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; + if exponential_histogram_has_aggregation_temporality v then ( + encode_pb_aggregation_temporality v.aggregation_temporality encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + ); () let rec encode_pb_summary_data_point_value_at_quantile (v:summary_data_point_value_at_quantile) encoder = - Pbrt.Encoder.float_as_bits64 v.quantile encoder; - Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; - Pbrt.Encoder.float_as_bits64 v.value encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + if summary_data_point_value_at_quantile_has_quantile v then ( + Pbrt.Encoder.float_as_bits64 v.quantile encoder; + Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; + ); + if summary_data_point_value_at_quantile_has_value v then ( + Pbrt.Encoder.float_as_bits64 v.value encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); () let rec encode_pb_summary_data_point (v:summary_data_point) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 7 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; - Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.count encoder; - Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; - Pbrt.Encoder.float_as_bits64 v.sum encoder; - Pbrt.Encoder.key 5 Pbrt.Bits64 encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if summary_data_point_has_start_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; + Pbrt.Encoder.key 2 Pbrt.Bits64 encoder; + ); + if summary_data_point_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 3 Pbrt.Bits64 encoder; + ); + if summary_data_point_has_count v then ( + Pbrt.Encoder.int64_as_bits64 v.count encoder; + Pbrt.Encoder.key 4 Pbrt.Bits64 encoder; + ); + if summary_data_point_has_sum v then ( + Pbrt.Encoder.float_as_bits64 v.sum encoder; + Pbrt.Encoder.key 5 Pbrt.Bits64 encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_summary_data_point_value_at_quantile x encoder; Pbrt.Encoder.key 6 Pbrt.Bytes encoder; ) v.quantile_values encoder; - Pbrt.Encoder.int32_as_varint v.flags encoder; - Pbrt.Encoder.key 8 Pbrt.Varint encoder; + if summary_data_point_has_flags v then ( + Pbrt.Encoder.int32_as_varint v.flags encoder; + Pbrt.Encoder.key 8 Pbrt.Varint encoder; + ); () let rec encode_pb_summary (v:summary) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_summary_data_point x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.data_points encoder; @@ -1245,29 +1388,40 @@ let rec encode_pb_metric_data (v:metric_data) encoder = end and encode_pb_metric (v:metric) encoder = - Pbrt.Encoder.string v.name encoder; - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.description encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.unit_ encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if metric_has_name v then ( + Pbrt.Encoder.string v.name encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); + if metric_has_description v then ( + Pbrt.Encoder.string v.description encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + if metric_has_unit_ v then ( + Pbrt.Encoder.string v.unit_ encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); begin match v.data with - | Gauge x -> + | None -> () + | Some (Gauge x) -> Pbrt.Encoder.nested encode_pb_gauge x encoder; Pbrt.Encoder.key 5 Pbrt.Bytes encoder; - | Sum x -> + | Some (Sum x) -> Pbrt.Encoder.nested encode_pb_sum x encoder; Pbrt.Encoder.key 7 Pbrt.Bytes encoder; - | Histogram x -> + | Some (Histogram x) -> Pbrt.Encoder.nested encode_pb_histogram x encoder; Pbrt.Encoder.key 9 Pbrt.Bytes encoder; - | Exponential_histogram x -> + | Some (Exponential_histogram x) -> Pbrt.Encoder.nested encode_pb_exponential_histogram x encoder; Pbrt.Encoder.key 10 Pbrt.Bytes encoder; - | Summary x -> + | Some (Summary x) -> Pbrt.Encoder.nested encode_pb_summary x encoder; Pbrt.Encoder.key 11 Pbrt.Bytes encoder; end; + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; + Pbrt.Encoder.key 12 Pbrt.Bytes encoder; + ) v.metadata encoder; () let rec encode_pb_scope_metrics (v:scope_metrics) encoder = @@ -1277,12 +1431,14 @@ let rec encode_pb_scope_metrics (v:scope_metrics) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_metric x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.metrics encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if scope_metrics_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_resource_metrics (v:resource_metrics) encoder = @@ -1292,16 +1448,18 @@ let rec encode_pb_resource_metrics (v:resource_metrics) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_scope_metrics x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.scope_metrics encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if resource_metrics_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_metrics_data (v:metrics_data) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_resource_metrics x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_metrics encoder; @@ -1312,7 +1470,7 @@ let rec encode_pb_data_point_flags (v:data_point_flags) encoder = | Data_point_flags_do_not_use -> Pbrt.Encoder.int_as_varint (0) encoder | Data_point_flags_no_recorded_value_mask -> Pbrt.Encoder.int_as_varint 1 encoder -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) @@ -1332,52 +1490,47 @@ let rec decode_pb_exemplar_value d = loop () and decode_pb_exemplar d = - let v = default_exemplar_mutable () in + let v = default_exemplar () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.filtered_attributes <- List.rev v.filtered_attributes; + (* put lists in the correct order *) + exemplar_set_filtered_attributes v (List.rev v.filtered_attributes); ); continue__ := false | Some (7, Pbrt.Bytes) -> begin - v.filtered_attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.filtered_attributes; + exemplar_set_filtered_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.filtered_attributes); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 7 pk | Some (2, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + exemplar_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 2 pk | Some (3, Pbrt.Bits64) -> begin - v.value <- As_double (Pbrt.Decoder.float_as_bits64 d); + exemplar_set_value v (As_double (Pbrt.Decoder.float_as_bits64 d)); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 3 pk | Some (6, Pbrt.Bits64) -> begin - v.value <- As_int (Pbrt.Decoder.int64_as_bits64 d); + exemplar_set_value v (As_int (Pbrt.Decoder.int64_as_bits64 d)); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 6 pk | Some (4, Pbrt.Bytes) -> begin - v.span_id <- Pbrt.Decoder.bytes d; + exemplar_set_span_id v (Pbrt.Decoder.bytes d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 4 pk | Some (5, Pbrt.Bytes) -> begin - v.trace_id <- Pbrt.Decoder.bytes d; + exemplar_set_trace_id v (Pbrt.Decoder.bytes d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exemplar), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "exemplar" 5 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - filtered_attributes = v.filtered_attributes; - time_unix_nano = v.time_unix_nano; - value = v.value; - span_id = v.span_id; - trace_id = v.trace_id; - } : exemplar) + (v : exemplar) let rec decode_pb_number_data_point_value d = let rec loop () = @@ -1395,470 +1548,418 @@ let rec decode_pb_number_data_point_value d = loop () and decode_pb_number_data_point d = - let v = default_number_data_point_mutable () in + let v = default_number_data_point () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.exemplars <- List.rev v.exemplars; - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + number_data_point_set_exemplars v (List.rev v.exemplars); + number_data_point_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (7, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + number_data_point_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 7 pk | Some (2, Pbrt.Bits64) -> begin - v.start_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + number_data_point_set_start_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 2 pk | Some (3, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + number_data_point_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 3 pk | Some (4, Pbrt.Bits64) -> begin - v.value <- As_double (Pbrt.Decoder.float_as_bits64 d); + number_data_point_set_value v (As_double (Pbrt.Decoder.float_as_bits64 d)); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 4 pk | Some (6, Pbrt.Bits64) -> begin - v.value <- As_int (Pbrt.Decoder.int64_as_bits64 d); + number_data_point_set_value v (As_int (Pbrt.Decoder.int64_as_bits64 d)); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 6 pk | Some (5, Pbrt.Bytes) -> begin - v.exemplars <- (decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars; + number_data_point_set_exemplars v ((decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 5 pk | Some (8, Pbrt.Varint) -> begin - v.flags <- Pbrt.Decoder.int32_as_varint d; + number_data_point_set_flags v (Pbrt.Decoder.int32_as_varint d); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(number_data_point), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "number_data_point" 8 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - attributes = v.attributes; - start_time_unix_nano = v.start_time_unix_nano; - time_unix_nano = v.time_unix_nano; - value = v.value; - exemplars = v.exemplars; - flags = v.flags; - } : number_data_point) + (v : number_data_point) let rec decode_pb_gauge d = - let v = default_gauge_mutable () in + let v = default_gauge () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.data_points <- List.rev v.data_points; + (* put lists in the correct order *) + gauge_set_data_points v (List.rev v.data_points); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.data_points <- (decode_pb_number_data_point (Pbrt.Decoder.nested d)) :: v.data_points; + gauge_set_data_points v ((decode_pb_number_data_point (Pbrt.Decoder.nested d)) :: v.data_points); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(gauge), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "gauge" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - data_points = v.data_points; - } : gauge) + (v : gauge) -let rec decode_pb_aggregation_temporality d = +let rec decode_pb_aggregation_temporality d : aggregation_temporality = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Aggregation_temporality_unspecified:aggregation_temporality) - | 1 -> (Aggregation_temporality_delta:aggregation_temporality) - | 2 -> (Aggregation_temporality_cumulative:aggregation_temporality) + | 0 -> Aggregation_temporality_unspecified + | 1 -> Aggregation_temporality_delta + | 2 -> Aggregation_temporality_cumulative | _ -> Pbrt.Decoder.malformed_variant "aggregation_temporality" let rec decode_pb_sum d = - let v = default_sum_mutable () in + let v = default_sum () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.data_points <- List.rev v.data_points; + (* put lists in the correct order *) + sum_set_data_points v (List.rev v.data_points); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.data_points <- (decode_pb_number_data_point (Pbrt.Decoder.nested d)) :: v.data_points; + sum_set_data_points v ((decode_pb_number_data_point (Pbrt.Decoder.nested d)) :: v.data_points); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(sum), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "sum" 1 pk | Some (2, Pbrt.Varint) -> begin - v.aggregation_temporality <- decode_pb_aggregation_temporality d; + sum_set_aggregation_temporality v (decode_pb_aggregation_temporality d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(sum), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "sum" 2 pk | Some (3, Pbrt.Varint) -> begin - v.is_monotonic <- Pbrt.Decoder.bool d; + sum_set_is_monotonic v (Pbrt.Decoder.bool d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(sum), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "sum" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - data_points = v.data_points; - aggregation_temporality = v.aggregation_temporality; - is_monotonic = v.is_monotonic; - } : sum) + (v : sum) let rec decode_pb_histogram_data_point d = - let v = default_histogram_data_point_mutable () in + let v = default_histogram_data_point () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.exemplars <- List.rev v.exemplars; - v.explicit_bounds <- List.rev v.explicit_bounds; - v.bucket_counts <- List.rev v.bucket_counts; - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + histogram_data_point_set_exemplars v (List.rev v.exemplars); + histogram_data_point_set_explicit_bounds v (List.rev v.explicit_bounds); + histogram_data_point_set_bucket_counts v (List.rev v.bucket_counts); + histogram_data_point_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (9, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + histogram_data_point_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(9)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 9 pk | Some (2, Pbrt.Bits64) -> begin - v.start_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + histogram_data_point_set_start_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 2 pk | Some (3, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + histogram_data_point_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 3 pk | Some (4, Pbrt.Bits64) -> begin - v.count <- Pbrt.Decoder.int64_as_bits64 d; + histogram_data_point_set_count v (Pbrt.Decoder.int64_as_bits64 d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 4 pk | Some (5, Pbrt.Bits64) -> begin - v.sum <- Some (Pbrt.Decoder.float_as_bits64 d); + histogram_data_point_set_sum v (Pbrt.Decoder.float_as_bits64 d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 5 pk | Some (6, Pbrt.Bytes) -> begin - v.bucket_counts <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.int64_as_bits64 d)::l) [] d; + histogram_data_point_set_bucket_counts v @@ Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.int64_as_bits64 d)::l) [] d; end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 6 pk | Some (7, Pbrt.Bytes) -> begin - v.explicit_bounds <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.float_as_bits64 d)::l) [] d; + histogram_data_point_set_explicit_bounds v @@ Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.float_as_bits64 d)::l) [] d; end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 7 pk | Some (8, Pbrt.Bytes) -> begin - v.exemplars <- (decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars; + histogram_data_point_set_exemplars v ((decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 8 pk | Some (10, Pbrt.Varint) -> begin - v.flags <- Pbrt.Decoder.int32_as_varint d; + histogram_data_point_set_flags v (Pbrt.Decoder.int32_as_varint d); end | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(10)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 10 pk | Some (11, Pbrt.Bits64) -> begin - v.min <- Some (Pbrt.Decoder.float_as_bits64 d); + histogram_data_point_set_min v (Pbrt.Decoder.float_as_bits64 d); end | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(11)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 11 pk | Some (12, Pbrt.Bits64) -> begin - v.max <- Some (Pbrt.Decoder.float_as_bits64 d); + histogram_data_point_set_max v (Pbrt.Decoder.float_as_bits64 d); end | Some (12, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram_data_point), field(12)" pk + Pbrt.Decoder.unexpected_payload_message "histogram_data_point" 12 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - attributes = v.attributes; - start_time_unix_nano = v.start_time_unix_nano; - time_unix_nano = v.time_unix_nano; - count = v.count; - sum = v.sum; - bucket_counts = v.bucket_counts; - explicit_bounds = v.explicit_bounds; - exemplars = v.exemplars; - flags = v.flags; - min = v.min; - max = v.max; - } : histogram_data_point) + (v : histogram_data_point) let rec decode_pb_histogram d = - let v = default_histogram_mutable () in + let v = default_histogram () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.data_points <- List.rev v.data_points; + (* put lists in the correct order *) + histogram_set_data_points v (List.rev v.data_points); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.data_points <- (decode_pb_histogram_data_point (Pbrt.Decoder.nested d)) :: v.data_points; + histogram_set_data_points v ((decode_pb_histogram_data_point (Pbrt.Decoder.nested d)) :: v.data_points); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "histogram" 1 pk | Some (2, Pbrt.Varint) -> begin - v.aggregation_temporality <- decode_pb_aggregation_temporality d; + histogram_set_aggregation_temporality v (decode_pb_aggregation_temporality d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(histogram), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "histogram" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - data_points = v.data_points; - aggregation_temporality = v.aggregation_temporality; - } : histogram) + (v : histogram) let rec decode_pb_exponential_histogram_data_point_buckets d = - let v = default_exponential_histogram_data_point_buckets_mutable () in + let v = default_exponential_histogram_data_point_buckets () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.bucket_counts <- List.rev v.bucket_counts; + (* put lists in the correct order *) + exponential_histogram_data_point_buckets_set_bucket_counts v (List.rev v.bucket_counts); ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.offset <- Pbrt.Decoder.int32_as_zigzag d; + exponential_histogram_data_point_buckets_set_offset v (Pbrt.Decoder.int32_as_zigzag d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point_buckets), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point_buckets" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.bucket_counts <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.int64_as_varint d)::l) [] d; + exponential_histogram_data_point_buckets_set_bucket_counts v @@ Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.int64_as_varint d)::l) [] d; end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point_buckets), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point_buckets" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - offset = v.offset; - bucket_counts = v.bucket_counts; - } : exponential_histogram_data_point_buckets) + (v : exponential_histogram_data_point_buckets) let rec decode_pb_exponential_histogram_data_point d = - let v = default_exponential_histogram_data_point_mutable () in + let v = default_exponential_histogram_data_point () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.exemplars <- List.rev v.exemplars; - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + exponential_histogram_data_point_set_exemplars v (List.rev v.exemplars); + exponential_histogram_data_point_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + exponential_histogram_data_point_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 1 pk | Some (2, Pbrt.Bits64) -> begin - v.start_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + exponential_histogram_data_point_set_start_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 2 pk | Some (3, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + exponential_histogram_data_point_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 3 pk | Some (4, Pbrt.Bits64) -> begin - v.count <- Pbrt.Decoder.int64_as_bits64 d; + exponential_histogram_data_point_set_count v (Pbrt.Decoder.int64_as_bits64 d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 4 pk | Some (5, Pbrt.Bits64) -> begin - v.sum <- Some (Pbrt.Decoder.float_as_bits64 d); + exponential_histogram_data_point_set_sum v (Pbrt.Decoder.float_as_bits64 d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 5 pk | Some (6, Pbrt.Varint) -> begin - v.scale <- Pbrt.Decoder.int32_as_zigzag d; + exponential_histogram_data_point_set_scale v (Pbrt.Decoder.int32_as_zigzag d); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 6 pk | Some (7, Pbrt.Bits64) -> begin - v.zero_count <- Pbrt.Decoder.int64_as_bits64 d; + exponential_histogram_data_point_set_zero_count v (Pbrt.Decoder.int64_as_bits64 d); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 7 pk | Some (8, Pbrt.Bytes) -> begin - v.positive <- Some (decode_pb_exponential_histogram_data_point_buckets (Pbrt.Decoder.nested d)); + exponential_histogram_data_point_set_positive v (decode_pb_exponential_histogram_data_point_buckets (Pbrt.Decoder.nested d)); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 8 pk | Some (9, Pbrt.Bytes) -> begin - v.negative <- Some (decode_pb_exponential_histogram_data_point_buckets (Pbrt.Decoder.nested d)); + exponential_histogram_data_point_set_negative v (decode_pb_exponential_histogram_data_point_buckets (Pbrt.Decoder.nested d)); end | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(9)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 9 pk | Some (10, Pbrt.Varint) -> begin - v.flags <- Pbrt.Decoder.int32_as_varint d; + exponential_histogram_data_point_set_flags v (Pbrt.Decoder.int32_as_varint d); end | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(10)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 10 pk | Some (11, Pbrt.Bytes) -> begin - v.exemplars <- (decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars; + exponential_histogram_data_point_set_exemplars v ((decode_pb_exemplar (Pbrt.Decoder.nested d)) :: v.exemplars); end | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(11)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 11 pk | Some (12, Pbrt.Bits64) -> begin - v.min <- Some (Pbrt.Decoder.float_as_bits64 d); + exponential_histogram_data_point_set_min v (Pbrt.Decoder.float_as_bits64 d); end | Some (12, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(12)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 12 pk | Some (13, Pbrt.Bits64) -> begin - v.max <- Some (Pbrt.Decoder.float_as_bits64 d); + exponential_histogram_data_point_set_max v (Pbrt.Decoder.float_as_bits64 d); end | Some (13, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(13)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 13 pk | Some (14, Pbrt.Bits64) -> begin - v.zero_threshold <- Pbrt.Decoder.float_as_bits64 d; + exponential_histogram_data_point_set_zero_threshold v (Pbrt.Decoder.float_as_bits64 d); end | Some (14, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram_data_point), field(14)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram_data_point" 14 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - attributes = v.attributes; - start_time_unix_nano = v.start_time_unix_nano; - time_unix_nano = v.time_unix_nano; - count = v.count; - sum = v.sum; - scale = v.scale; - zero_count = v.zero_count; - positive = v.positive; - negative = v.negative; - flags = v.flags; - exemplars = v.exemplars; - min = v.min; - max = v.max; - zero_threshold = v.zero_threshold; - } : exponential_histogram_data_point) + (v : exponential_histogram_data_point) let rec decode_pb_exponential_histogram d = - let v = default_exponential_histogram_mutable () in + let v = default_exponential_histogram () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.data_points <- List.rev v.data_points; + (* put lists in the correct order *) + exponential_histogram_set_data_points v (List.rev v.data_points); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.data_points <- (decode_pb_exponential_histogram_data_point (Pbrt.Decoder.nested d)) :: v.data_points; + exponential_histogram_set_data_points v ((decode_pb_exponential_histogram_data_point (Pbrt.Decoder.nested d)) :: v.data_points); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram" 1 pk | Some (2, Pbrt.Varint) -> begin - v.aggregation_temporality <- decode_pb_aggregation_temporality d; + exponential_histogram_set_aggregation_temporality v (decode_pb_aggregation_temporality d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(exponential_histogram), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "exponential_histogram" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - data_points = v.data_points; - aggregation_temporality = v.aggregation_temporality; - } : exponential_histogram) + (v : exponential_histogram) let rec decode_pb_summary_data_point_value_at_quantile d = - let v = default_summary_data_point_value_at_quantile_mutable () in + let v = default_summary_data_point_value_at_quantile () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Bits64) -> begin - v.quantile <- Pbrt.Decoder.float_as_bits64 d; + summary_data_point_value_at_quantile_set_quantile v (Pbrt.Decoder.float_as_bits64 d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point_value_at_quantile), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point_value_at_quantile" 1 pk | Some (2, Pbrt.Bits64) -> begin - v.value <- Pbrt.Decoder.float_as_bits64 d; + summary_data_point_value_at_quantile_set_value v (Pbrt.Decoder.float_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point_value_at_quantile), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point_value_at_quantile" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - quantile = v.quantile; - value = v.value; - } : summary_data_point_value_at_quantile) + (v : summary_data_point_value_at_quantile) let rec decode_pb_summary_data_point d = - let v = default_summary_data_point_mutable () in + let v = default_summary_data_point () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.quantile_values <- List.rev v.quantile_values; - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + summary_data_point_set_quantile_values v (List.rev v.quantile_values); + summary_data_point_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (7, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + summary_data_point_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 7 pk | Some (2, Pbrt.Bits64) -> begin - v.start_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + summary_data_point_set_start_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 2 pk | Some (3, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + summary_data_point_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 3 pk | Some (4, Pbrt.Bits64) -> begin - v.count <- Pbrt.Decoder.int64_as_bits64 d; + summary_data_point_set_count v (Pbrt.Decoder.int64_as_bits64 d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 4 pk | Some (5, Pbrt.Bits64) -> begin - v.sum <- Pbrt.Decoder.float_as_bits64 d; + summary_data_point_set_sum v (Pbrt.Decoder.float_as_bits64 d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 5 pk | Some (6, Pbrt.Bytes) -> begin - v.quantile_values <- (decode_pb_summary_data_point_value_at_quantile (Pbrt.Decoder.nested d)) :: v.quantile_values; + summary_data_point_set_quantile_values v ((decode_pb_summary_data_point_value_at_quantile (Pbrt.Decoder.nested d)) :: v.quantile_values); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 6 pk | Some (8, Pbrt.Varint) -> begin - v.flags <- Pbrt.Decoder.int32_as_varint d; + summary_data_point_set_flags v (Pbrt.Decoder.int32_as_varint d); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary_data_point), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "summary_data_point" 8 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - attributes = v.attributes; - start_time_unix_nano = v.start_time_unix_nano; - time_unix_nano = v.time_unix_nano; - count = v.count; - sum = v.sum; - quantile_values = v.quantile_values; - flags = v.flags; - } : summary_data_point) + (v : summary_data_point) let rec decode_pb_summary d = - let v = default_summary_mutable () in + let v = default_summary () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.data_points <- List.rev v.data_points; + (* put lists in the correct order *) + summary_set_data_points v (List.rev v.data_points); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.data_points <- (decode_pb_summary_data_point (Pbrt.Decoder.nested d)) :: v.data_points; + summary_set_data_points v ((decode_pb_summary_data_point (Pbrt.Decoder.nested d)) :: v.data_points); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(summary), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "summary" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - data_points = v.data_points; - } : summary) + (v : summary) let rec decode_pb_metric_data d = let rec loop () = @@ -1879,144 +1980,139 @@ let rec decode_pb_metric_data d = loop () and decode_pb_metric d = - let v = default_metric_mutable () in + let v = default_metric () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( + (* put lists in the correct order *) + metric_set_metadata v (List.rev v.metadata); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.name <- Pbrt.Decoder.string d; + metric_set_name v (Pbrt.Decoder.string d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.description <- Pbrt.Decoder.string d; + metric_set_description v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.unit_ <- Pbrt.Decoder.string d; + metric_set_unit_ v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 3 pk | Some (5, Pbrt.Bytes) -> begin - v.data <- Gauge (decode_pb_gauge (Pbrt.Decoder.nested d)); + metric_set_data v (Gauge (decode_pb_gauge (Pbrt.Decoder.nested d))); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 5 pk | Some (7, Pbrt.Bytes) -> begin - v.data <- Sum (decode_pb_sum (Pbrt.Decoder.nested d)); + metric_set_data v (Sum (decode_pb_sum (Pbrt.Decoder.nested d))); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 7 pk | Some (9, Pbrt.Bytes) -> begin - v.data <- Histogram (decode_pb_histogram (Pbrt.Decoder.nested d)); + metric_set_data v (Histogram (decode_pb_histogram (Pbrt.Decoder.nested d))); end | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(9)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 9 pk | Some (10, Pbrt.Bytes) -> begin - v.data <- Exponential_histogram (decode_pb_exponential_histogram (Pbrt.Decoder.nested d)); + metric_set_data v (Exponential_histogram (decode_pb_exponential_histogram (Pbrt.Decoder.nested d))); end | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(10)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 10 pk | Some (11, Pbrt.Bytes) -> begin - v.data <- Summary (decode_pb_summary (Pbrt.Decoder.nested d)); + metric_set_data v (Summary (decode_pb_summary (Pbrt.Decoder.nested d))); end | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metric), field(11)" pk + Pbrt.Decoder.unexpected_payload_message "metric" 11 pk + | Some (12, Pbrt.Bytes) -> begin + metric_set_metadata v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.metadata); + end + | Some (12, pk) -> + Pbrt.Decoder.unexpected_payload_message "metric" 12 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - name = v.name; - description = v.description; - unit_ = v.unit_; - data = v.data; - } : metric) + (v : metric) let rec decode_pb_scope_metrics d = - let v = default_scope_metrics_mutable () in + let v = default_scope_metrics () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.metrics <- List.rev v.metrics; + (* put lists in the correct order *) + scope_metrics_set_metrics v (List.rev v.metrics); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.scope <- Some (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); + scope_metrics_set_scope v (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_metrics), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "scope_metrics" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.metrics <- (decode_pb_metric (Pbrt.Decoder.nested d)) :: v.metrics; + scope_metrics_set_metrics v ((decode_pb_metric (Pbrt.Decoder.nested d)) :: v.metrics); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_metrics), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "scope_metrics" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + scope_metrics_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_metrics), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "scope_metrics" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - scope = v.scope; - metrics = v.metrics; - schema_url = v.schema_url; - } : scope_metrics) + (v : scope_metrics) let rec decode_pb_resource_metrics d = - let v = default_resource_metrics_mutable () in + let v = default_resource_metrics () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.scope_metrics <- List.rev v.scope_metrics; + (* put lists in the correct order *) + resource_metrics_set_scope_metrics v (List.rev v.scope_metrics); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource <- Some (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); + resource_metrics_set_resource v (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_metrics), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "resource_metrics" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.scope_metrics <- (decode_pb_scope_metrics (Pbrt.Decoder.nested d)) :: v.scope_metrics; + resource_metrics_set_scope_metrics v ((decode_pb_scope_metrics (Pbrt.Decoder.nested d)) :: v.scope_metrics); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_metrics), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "resource_metrics" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + resource_metrics_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_metrics), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "resource_metrics" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource = v.resource; - scope_metrics = v.scope_metrics; - schema_url = v.schema_url; - } : resource_metrics) + (v : resource_metrics) let rec decode_pb_metrics_data d = - let v = default_metrics_data_mutable () in + let v = default_metrics_data () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_metrics <- List.rev v.resource_metrics; + (* put lists in the correct order *) + metrics_data_set_resource_metrics v (List.rev v.resource_metrics); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_metrics <- (decode_pb_resource_metrics (Pbrt.Decoder.nested d)) :: v.resource_metrics; + metrics_data_set_resource_metrics v ((decode_pb_resource_metrics (Pbrt.Decoder.nested d)) :: v.resource_metrics); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(metrics_data), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "metrics_data" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_metrics = v.resource_metrics; - } : metrics_data) + (v : metrics_data) -let rec decode_pb_data_point_flags d = +let rec decode_pb_data_point_flags d : data_point_flags = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Data_point_flags_do_not_use:data_point_flags) - | 1 -> (Data_point_flags_no_recorded_value_mask:data_point_flags) + | 0 -> Data_point_flags_do_not_use + | 1 -> Data_point_flags_no_recorded_value_mask | _ -> Pbrt.Decoder.malformed_variant "data_point_flags" diff --git a/src/proto/metrics.mli b/src/proto/metrics.mli index d9626883..92c678a2 100644 --- a/src/proto/metrics.mli +++ b/src/proto/metrics.mli @@ -11,29 +11,31 @@ type exemplar_value = | As_double of float | As_int of int64 -and exemplar = { - filtered_attributes : Common.key_value list; - time_unix_nano : int64; - value : exemplar_value; - span_id : bytes; - trace_id : bytes; +and exemplar = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) + mutable filtered_attributes : Common.key_value list; + mutable time_unix_nano : int64; + mutable value : exemplar_value option; + mutable span_id : bytes; + mutable trace_id : bytes; } type number_data_point_value = | As_double of float | As_int of int64 -and number_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - value : number_data_point_value; - exemplars : exemplar list; - flags : int32; +and number_data_point = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) + mutable attributes : Common.key_value list; + mutable start_time_unix_nano : int64; + mutable time_unix_nano : int64; + mutable value : number_data_point_value option; + mutable exemplars : exemplar list; + mutable flags : int32; } -type gauge = { - data_points : number_data_point list; +type gauge = private { + mutable data_points : number_data_point list; } type aggregation_temporality = @@ -41,75 +43,83 @@ type aggregation_temporality = | Aggregation_temporality_delta | Aggregation_temporality_cumulative -type sum = { - data_points : number_data_point list; - aggregation_temporality : aggregation_temporality; - is_monotonic : bool; +type sum = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable data_points : number_data_point list; + mutable aggregation_temporality : aggregation_temporality; + mutable is_monotonic : bool; } -type histogram_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float option; - bucket_counts : int64 list; - explicit_bounds : float list; - exemplars : exemplar list; - flags : int32; - min : float option; - max : float option; +type histogram_data_point = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 7 fields *) + mutable attributes : Common.key_value list; + mutable start_time_unix_nano : int64; + mutable time_unix_nano : int64; + mutable count : int64; + mutable sum : float; + mutable bucket_counts : int64 list; + mutable explicit_bounds : float list; + mutable exemplars : exemplar list; + mutable flags : int32; + mutable min : float; + mutable max : float; } -type histogram = { - data_points : histogram_data_point list; - aggregation_temporality : aggregation_temporality; +type histogram = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable data_points : histogram_data_point list; + mutable aggregation_temporality : aggregation_temporality; } -type exponential_histogram_data_point_buckets = { - offset : int32; - bucket_counts : int64 list; +type exponential_histogram_data_point_buckets = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable offset : int32; + mutable bucket_counts : int64 list; } -type exponential_histogram_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float option; - scale : int32; - zero_count : int64; - positive : exponential_histogram_data_point_buckets option; - negative : exponential_histogram_data_point_buckets option; - flags : int32; - exemplars : exemplar list; - min : float option; - max : float option; - zero_threshold : float; +type exponential_histogram_data_point = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 10 fields *) + mutable attributes : Common.key_value list; + mutable start_time_unix_nano : int64; + mutable time_unix_nano : int64; + mutable count : int64; + mutable sum : float; + mutable scale : int32; + mutable zero_count : int64; + mutable positive : exponential_histogram_data_point_buckets option; + mutable negative : exponential_histogram_data_point_buckets option; + mutable flags : int32; + mutable exemplars : exemplar list; + mutable min : float; + mutable max : float; + mutable zero_threshold : float; } -type exponential_histogram = { - data_points : exponential_histogram_data_point list; - aggregation_temporality : aggregation_temporality; +type exponential_histogram = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable data_points : exponential_histogram_data_point list; + mutable aggregation_temporality : aggregation_temporality; } -type summary_data_point_value_at_quantile = { - quantile : float; - value : float; +type summary_data_point_value_at_quantile = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable quantile : float; + mutable value : float; } -type summary_data_point = { - attributes : Common.key_value list; - start_time_unix_nano : int64; - time_unix_nano : int64; - count : int64; - sum : float; - quantile_values : summary_data_point_value_at_quantile list; - flags : int32; +type summary_data_point = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 5 fields *) + mutable attributes : Common.key_value list; + mutable start_time_unix_nano : int64; + mutable time_unix_nano : int64; + mutable count : int64; + mutable sum : float; + mutable quantile_values : summary_data_point_value_at_quantile list; + mutable flags : int32; } -type summary = { - data_points : summary_data_point list; +type summary = private { + mutable data_points : summary_data_point list; } type metric_data = @@ -119,27 +129,31 @@ type metric_data = | Exponential_histogram of exponential_histogram | Summary of summary -and metric = { - name : string; - description : string; - unit_ : string; - data : metric_data; +and metric = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) + mutable name : string; + mutable description : string; + mutable unit_ : string; + mutable data : metric_data option; + mutable metadata : Common.key_value list; } -type scope_metrics = { - scope : Common.instrumentation_scope option; - metrics : metric list; - schema_url : string; +type scope_metrics = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable scope : Common.instrumentation_scope option; + mutable metrics : metric list; + mutable schema_url : string; } -type resource_metrics = { - resource : Resource.resource option; - scope_metrics : scope_metrics list; - schema_url : string; +type resource_metrics = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable resource : Resource.resource option; + mutable scope_metrics : scope_metrics list; + mutable schema_url : string; } -type metrics_data = { - resource_metrics : resource_metrics list; +type metrics_data = private { + mutable resource_metrics : resource_metrics list; } type data_point_flags = @@ -150,9 +164,72 @@ type data_point_flags = (** {2 Basic values} *) val default_exemplar_value : unit -> exemplar_value -(** [default_exemplar_value ()] is the default value for type [exemplar_value] *) +(** [default_exemplar_value ()] is a new empty value for type [exemplar_value] *) -val default_exemplar : +val default_exemplar : unit -> exemplar +(** [default_exemplar ()] is a new empty value for type [exemplar] *) + +val default_number_data_point_value : unit -> number_data_point_value +(** [default_number_data_point_value ()] is a new empty value for type [number_data_point_value] *) + +val default_number_data_point : unit -> number_data_point +(** [default_number_data_point ()] is a new empty value for type [number_data_point] *) + +val default_gauge : unit -> gauge +(** [default_gauge ()] is a new empty value for type [gauge] *) + +val default_aggregation_temporality : unit -> aggregation_temporality +(** [default_aggregation_temporality ()] is a new empty value for type [aggregation_temporality] *) + +val default_sum : unit -> sum +(** [default_sum ()] is a new empty value for type [sum] *) + +val default_histogram_data_point : unit -> histogram_data_point +(** [default_histogram_data_point ()] is a new empty value for type [histogram_data_point] *) + +val default_histogram : unit -> histogram +(** [default_histogram ()] is a new empty value for type [histogram] *) + +val default_exponential_histogram_data_point_buckets : unit -> exponential_histogram_data_point_buckets +(** [default_exponential_histogram_data_point_buckets ()] is a new empty value for type [exponential_histogram_data_point_buckets] *) + +val default_exponential_histogram_data_point : unit -> exponential_histogram_data_point +(** [default_exponential_histogram_data_point ()] is a new empty value for type [exponential_histogram_data_point] *) + +val default_exponential_histogram : unit -> exponential_histogram +(** [default_exponential_histogram ()] is a new empty value for type [exponential_histogram] *) + +val default_summary_data_point_value_at_quantile : unit -> summary_data_point_value_at_quantile +(** [default_summary_data_point_value_at_quantile ()] is a new empty value for type [summary_data_point_value_at_quantile] *) + +val default_summary_data_point : unit -> summary_data_point +(** [default_summary_data_point ()] is a new empty value for type [summary_data_point] *) + +val default_summary : unit -> summary +(** [default_summary ()] is a new empty value for type [summary] *) + +val default_metric_data : unit -> metric_data +(** [default_metric_data ()] is a new empty value for type [metric_data] *) + +val default_metric : unit -> metric +(** [default_metric ()] is a new empty value for type [metric] *) + +val default_scope_metrics : unit -> scope_metrics +(** [default_scope_metrics ()] is a new empty value for type [scope_metrics] *) + +val default_resource_metrics : unit -> resource_metrics +(** [default_resource_metrics ()] is a new empty value for type [resource_metrics] *) + +val default_metrics_data : unit -> metrics_data +(** [default_metrics_data ()] is a new empty value for type [metrics_data] *) + +val default_data_point_flags : unit -> data_point_flags +(** [default_data_point_flags ()] is a new empty value for type [data_point_flags] *) + + +(** {2 Make functions} *) + +val make_exemplar : ?filtered_attributes:Common.key_value list -> ?time_unix_nano:int64 -> ?value:exemplar_value -> @@ -160,12 +237,35 @@ val default_exemplar : ?trace_id:bytes -> unit -> exemplar -(** [default_exemplar ()] is the default value for type [exemplar] *) +(** [make_exemplar … ()] is a builder for type [exemplar] *) -val default_number_data_point_value : unit -> number_data_point_value -(** [default_number_data_point_value ()] is the default value for type [number_data_point_value] *) +val copy_exemplar : exemplar -> exemplar -val default_number_data_point : +val exemplar_set_filtered_attributes : exemplar -> Common.key_value list -> unit + (** set field filtered_attributes in exemplar *) + +val exemplar_has_time_unix_nano : exemplar -> bool + (** presence of field "time_unix_nano" in [exemplar] *) + +val exemplar_set_time_unix_nano : exemplar -> int64 -> unit + (** set field time_unix_nano in exemplar *) + +val exemplar_set_value : exemplar -> exemplar_value -> unit + (** set field value in exemplar *) + +val exemplar_has_span_id : exemplar -> bool + (** presence of field "span_id" in [exemplar] *) + +val exemplar_set_span_id : exemplar -> bytes -> unit + (** set field span_id in exemplar *) + +val exemplar_has_trace_id : exemplar -> bool + (** presence of field "trace_id" in [exemplar] *) + +val exemplar_set_trace_id : exemplar -> bytes -> unit + (** set field trace_id in exemplar *) + +val make_number_data_point : ?attributes:Common.key_value list -> ?start_time_unix_nano:int64 -> ?time_unix_nano:int64 -> @@ -174,297 +274,464 @@ val default_number_data_point : ?flags:int32 -> unit -> number_data_point -(** [default_number_data_point ()] is the default value for type [number_data_point] *) +(** [make_number_data_point … ()] is a builder for type [number_data_point] *) + +val copy_number_data_point : number_data_point -> number_data_point + +val number_data_point_set_attributes : number_data_point -> Common.key_value list -> unit + (** set field attributes in number_data_point *) + +val number_data_point_has_start_time_unix_nano : number_data_point -> bool + (** presence of field "start_time_unix_nano" in [number_data_point] *) + +val number_data_point_set_start_time_unix_nano : number_data_point -> int64 -> unit + (** set field start_time_unix_nano in number_data_point *) + +val number_data_point_has_time_unix_nano : number_data_point -> bool + (** presence of field "time_unix_nano" in [number_data_point] *) -val default_gauge : +val number_data_point_set_time_unix_nano : number_data_point -> int64 -> unit + (** set field time_unix_nano in number_data_point *) + +val number_data_point_set_value : number_data_point -> number_data_point_value -> unit + (** set field value in number_data_point *) + +val number_data_point_set_exemplars : number_data_point -> exemplar list -> unit + (** set field exemplars in number_data_point *) + +val number_data_point_has_flags : number_data_point -> bool + (** presence of field "flags" in [number_data_point] *) + +val number_data_point_set_flags : number_data_point -> int32 -> unit + (** set field flags in number_data_point *) + +val make_gauge : ?data_points:number_data_point list -> unit -> gauge -(** [default_gauge ()] is the default value for type [gauge] *) +(** [make_gauge … ()] is a builder for type [gauge] *) -val default_aggregation_temporality : unit -> aggregation_temporality -(** [default_aggregation_temporality ()] is the default value for type [aggregation_temporality] *) +val copy_gauge : gauge -> gauge -val default_sum : +val gauge_set_data_points : gauge -> number_data_point list -> unit + (** set field data_points in gauge *) + +val make_sum : ?data_points:number_data_point list -> ?aggregation_temporality:aggregation_temporality -> ?is_monotonic:bool -> unit -> sum -(** [default_sum ()] is the default value for type [sum] *) +(** [make_sum … ()] is a builder for type [sum] *) + +val copy_sum : sum -> sum + +val sum_set_data_points : sum -> number_data_point list -> unit + (** set field data_points in sum *) + +val sum_has_aggregation_temporality : sum -> bool + (** presence of field "aggregation_temporality" in [sum] *) + +val sum_set_aggregation_temporality : sum -> aggregation_temporality -> unit + (** set field aggregation_temporality in sum *) -val default_histogram_data_point : +val sum_has_is_monotonic : sum -> bool + (** presence of field "is_monotonic" in [sum] *) + +val sum_set_is_monotonic : sum -> bool -> unit + (** set field is_monotonic in sum *) + +val make_histogram_data_point : ?attributes:Common.key_value list -> ?start_time_unix_nano:int64 -> ?time_unix_nano:int64 -> ?count:int64 -> - ?sum:float option -> + ?sum:float -> ?bucket_counts:int64 list -> ?explicit_bounds:float list -> ?exemplars:exemplar list -> ?flags:int32 -> - ?min:float option -> - ?max:float option -> + ?min:float -> + ?max:float -> unit -> histogram_data_point -(** [default_histogram_data_point ()] is the default value for type [histogram_data_point] *) +(** [make_histogram_data_point … ()] is a builder for type [histogram_data_point] *) + +val copy_histogram_data_point : histogram_data_point -> histogram_data_point + +val histogram_data_point_set_attributes : histogram_data_point -> Common.key_value list -> unit + (** set field attributes in histogram_data_point *) + +val histogram_data_point_has_start_time_unix_nano : histogram_data_point -> bool + (** presence of field "start_time_unix_nano" in [histogram_data_point] *) + +val histogram_data_point_set_start_time_unix_nano : histogram_data_point -> int64 -> unit + (** set field start_time_unix_nano in histogram_data_point *) + +val histogram_data_point_has_time_unix_nano : histogram_data_point -> bool + (** presence of field "time_unix_nano" in [histogram_data_point] *) + +val histogram_data_point_set_time_unix_nano : histogram_data_point -> int64 -> unit + (** set field time_unix_nano in histogram_data_point *) + +val histogram_data_point_has_count : histogram_data_point -> bool + (** presence of field "count" in [histogram_data_point] *) + +val histogram_data_point_set_count : histogram_data_point -> int64 -> unit + (** set field count in histogram_data_point *) + +val histogram_data_point_has_sum : histogram_data_point -> bool + (** presence of field "sum" in [histogram_data_point] *) + +val histogram_data_point_set_sum : histogram_data_point -> float -> unit + (** set field sum in histogram_data_point *) -val default_histogram : +val histogram_data_point_set_bucket_counts : histogram_data_point -> int64 list -> unit + (** set field bucket_counts in histogram_data_point *) + +val histogram_data_point_set_explicit_bounds : histogram_data_point -> float list -> unit + (** set field explicit_bounds in histogram_data_point *) + +val histogram_data_point_set_exemplars : histogram_data_point -> exemplar list -> unit + (** set field exemplars in histogram_data_point *) + +val histogram_data_point_has_flags : histogram_data_point -> bool + (** presence of field "flags" in [histogram_data_point] *) + +val histogram_data_point_set_flags : histogram_data_point -> int32 -> unit + (** set field flags in histogram_data_point *) + +val histogram_data_point_has_min : histogram_data_point -> bool + (** presence of field "min" in [histogram_data_point] *) + +val histogram_data_point_set_min : histogram_data_point -> float -> unit + (** set field min in histogram_data_point *) + +val histogram_data_point_has_max : histogram_data_point -> bool + (** presence of field "max" in [histogram_data_point] *) + +val histogram_data_point_set_max : histogram_data_point -> float -> unit + (** set field max in histogram_data_point *) + +val make_histogram : ?data_points:histogram_data_point list -> ?aggregation_temporality:aggregation_temporality -> unit -> histogram -(** [default_histogram ()] is the default value for type [histogram] *) +(** [make_histogram … ()] is a builder for type [histogram] *) + +val copy_histogram : histogram -> histogram + +val histogram_set_data_points : histogram -> histogram_data_point list -> unit + (** set field data_points in histogram *) + +val histogram_has_aggregation_temporality : histogram -> bool + (** presence of field "aggregation_temporality" in [histogram] *) + +val histogram_set_aggregation_temporality : histogram -> aggregation_temporality -> unit + (** set field aggregation_temporality in histogram *) -val default_exponential_histogram_data_point_buckets : +val make_exponential_histogram_data_point_buckets : ?offset:int32 -> ?bucket_counts:int64 list -> unit -> exponential_histogram_data_point_buckets -(** [default_exponential_histogram_data_point_buckets ()] is the default value for type [exponential_histogram_data_point_buckets] *) +(** [make_exponential_histogram_data_point_buckets … ()] is a builder for type [exponential_histogram_data_point_buckets] *) + +val copy_exponential_histogram_data_point_buckets : exponential_histogram_data_point_buckets -> exponential_histogram_data_point_buckets + +val exponential_histogram_data_point_buckets_has_offset : exponential_histogram_data_point_buckets -> bool + (** presence of field "offset" in [exponential_histogram_data_point_buckets] *) -val default_exponential_histogram_data_point : +val exponential_histogram_data_point_buckets_set_offset : exponential_histogram_data_point_buckets -> int32 -> unit + (** set field offset in exponential_histogram_data_point_buckets *) + +val exponential_histogram_data_point_buckets_set_bucket_counts : exponential_histogram_data_point_buckets -> int64 list -> unit + (** set field bucket_counts in exponential_histogram_data_point_buckets *) + +val make_exponential_histogram_data_point : ?attributes:Common.key_value list -> ?start_time_unix_nano:int64 -> ?time_unix_nano:int64 -> ?count:int64 -> - ?sum:float option -> + ?sum:float -> ?scale:int32 -> ?zero_count:int64 -> - ?positive:exponential_histogram_data_point_buckets option -> - ?negative:exponential_histogram_data_point_buckets option -> + ?positive:exponential_histogram_data_point_buckets -> + ?negative:exponential_histogram_data_point_buckets -> ?flags:int32 -> ?exemplars:exemplar list -> - ?min:float option -> - ?max:float option -> + ?min:float -> + ?max:float -> ?zero_threshold:float -> unit -> exponential_histogram_data_point -(** [default_exponential_histogram_data_point ()] is the default value for type [exponential_histogram_data_point] *) +(** [make_exponential_histogram_data_point … ()] is a builder for type [exponential_histogram_data_point] *) -val default_exponential_histogram : - ?data_points:exponential_histogram_data_point list -> - ?aggregation_temporality:aggregation_temporality -> - unit -> - exponential_histogram -(** [default_exponential_histogram ()] is the default value for type [exponential_histogram] *) +val copy_exponential_histogram_data_point : exponential_histogram_data_point -> exponential_histogram_data_point -val default_summary_data_point_value_at_quantile : - ?quantile:float -> - ?value:float -> - unit -> - summary_data_point_value_at_quantile -(** [default_summary_data_point_value_at_quantile ()] is the default value for type [summary_data_point_value_at_quantile] *) +val exponential_histogram_data_point_set_attributes : exponential_histogram_data_point -> Common.key_value list -> unit + (** set field attributes in exponential_histogram_data_point *) -val default_summary_data_point : - ?attributes:Common.key_value list -> - ?start_time_unix_nano:int64 -> - ?time_unix_nano:int64 -> - ?count:int64 -> - ?sum:float -> - ?quantile_values:summary_data_point_value_at_quantile list -> - ?flags:int32 -> - unit -> - summary_data_point -(** [default_summary_data_point ()] is the default value for type [summary_data_point] *) +val exponential_histogram_data_point_has_start_time_unix_nano : exponential_histogram_data_point -> bool + (** presence of field "start_time_unix_nano" in [exponential_histogram_data_point] *) -val default_summary : - ?data_points:summary_data_point list -> - unit -> - summary -(** [default_summary ()] is the default value for type [summary] *) +val exponential_histogram_data_point_set_start_time_unix_nano : exponential_histogram_data_point -> int64 -> unit + (** set field start_time_unix_nano in exponential_histogram_data_point *) -val default_metric_data : unit -> metric_data -(** [default_metric_data ()] is the default value for type [metric_data] *) +val exponential_histogram_data_point_has_time_unix_nano : exponential_histogram_data_point -> bool + (** presence of field "time_unix_nano" in [exponential_histogram_data_point] *) -val default_metric : - ?name:string -> - ?description:string -> - ?unit_:string -> - ?data:metric_data -> - unit -> - metric -(** [default_metric ()] is the default value for type [metric] *) +val exponential_histogram_data_point_set_time_unix_nano : exponential_histogram_data_point -> int64 -> unit + (** set field time_unix_nano in exponential_histogram_data_point *) -val default_scope_metrics : - ?scope:Common.instrumentation_scope option -> - ?metrics:metric list -> - ?schema_url:string -> - unit -> - scope_metrics -(** [default_scope_metrics ()] is the default value for type [scope_metrics] *) +val exponential_histogram_data_point_has_count : exponential_histogram_data_point -> bool + (** presence of field "count" in [exponential_histogram_data_point] *) -val default_resource_metrics : - ?resource:Resource.resource option -> - ?scope_metrics:scope_metrics list -> - ?schema_url:string -> - unit -> - resource_metrics -(** [default_resource_metrics ()] is the default value for type [resource_metrics] *) +val exponential_histogram_data_point_set_count : exponential_histogram_data_point -> int64 -> unit + (** set field count in exponential_histogram_data_point *) -val default_metrics_data : - ?resource_metrics:resource_metrics list -> - unit -> - metrics_data -(** [default_metrics_data ()] is the default value for type [metrics_data] *) +val exponential_histogram_data_point_has_sum : exponential_histogram_data_point -> bool + (** presence of field "sum" in [exponential_histogram_data_point] *) -val default_data_point_flags : unit -> data_point_flags -(** [default_data_point_flags ()] is the default value for type [data_point_flags] *) +val exponential_histogram_data_point_set_sum : exponential_histogram_data_point -> float -> unit + (** set field sum in exponential_histogram_data_point *) +val exponential_histogram_data_point_has_scale : exponential_histogram_data_point -> bool + (** presence of field "scale" in [exponential_histogram_data_point] *) -(** {2 Make functions} *) +val exponential_histogram_data_point_set_scale : exponential_histogram_data_point -> int32 -> unit + (** set field scale in exponential_histogram_data_point *) +val exponential_histogram_data_point_has_zero_count : exponential_histogram_data_point -> bool + (** presence of field "zero_count" in [exponential_histogram_data_point] *) -val make_exemplar : - filtered_attributes:Common.key_value list -> - time_unix_nano:int64 -> - value:exemplar_value -> - span_id:bytes -> - trace_id:bytes -> - unit -> - exemplar -(** [make_exemplar … ()] is a builder for type [exemplar] *) +val exponential_histogram_data_point_set_zero_count : exponential_histogram_data_point -> int64 -> unit + (** set field zero_count in exponential_histogram_data_point *) +val exponential_histogram_data_point_set_positive : exponential_histogram_data_point -> exponential_histogram_data_point_buckets -> unit + (** set field positive in exponential_histogram_data_point *) -val make_number_data_point : - attributes:Common.key_value list -> - start_time_unix_nano:int64 -> - time_unix_nano:int64 -> - value:number_data_point_value -> - exemplars:exemplar list -> - flags:int32 -> - unit -> - number_data_point -(** [make_number_data_point … ()] is a builder for type [number_data_point] *) +val exponential_histogram_data_point_set_negative : exponential_histogram_data_point -> exponential_histogram_data_point_buckets -> unit + (** set field negative in exponential_histogram_data_point *) -val make_gauge : - data_points:number_data_point list -> - unit -> - gauge -(** [make_gauge … ()] is a builder for type [gauge] *) +val exponential_histogram_data_point_has_flags : exponential_histogram_data_point -> bool + (** presence of field "flags" in [exponential_histogram_data_point] *) +val exponential_histogram_data_point_set_flags : exponential_histogram_data_point -> int32 -> unit + (** set field flags in exponential_histogram_data_point *) -val make_sum : - data_points:number_data_point list -> - aggregation_temporality:aggregation_temporality -> - is_monotonic:bool -> - unit -> - sum -(** [make_sum … ()] is a builder for type [sum] *) +val exponential_histogram_data_point_set_exemplars : exponential_histogram_data_point -> exemplar list -> unit + (** set field exemplars in exponential_histogram_data_point *) -val make_histogram_data_point : - attributes:Common.key_value list -> - start_time_unix_nano:int64 -> - time_unix_nano:int64 -> - count:int64 -> - ?sum:float option -> - bucket_counts:int64 list -> - explicit_bounds:float list -> - exemplars:exemplar list -> - flags:int32 -> - ?min:float option -> - ?max:float option -> - unit -> - histogram_data_point -(** [make_histogram_data_point … ()] is a builder for type [histogram_data_point] *) +val exponential_histogram_data_point_has_min : exponential_histogram_data_point -> bool + (** presence of field "min" in [exponential_histogram_data_point] *) -val make_histogram : - data_points:histogram_data_point list -> - aggregation_temporality:aggregation_temporality -> - unit -> - histogram -(** [make_histogram … ()] is a builder for type [histogram] *) +val exponential_histogram_data_point_set_min : exponential_histogram_data_point -> float -> unit + (** set field min in exponential_histogram_data_point *) -val make_exponential_histogram_data_point_buckets : - offset:int32 -> - bucket_counts:int64 list -> - unit -> - exponential_histogram_data_point_buckets -(** [make_exponential_histogram_data_point_buckets … ()] is a builder for type [exponential_histogram_data_point_buckets] *) +val exponential_histogram_data_point_has_max : exponential_histogram_data_point -> bool + (** presence of field "max" in [exponential_histogram_data_point] *) -val make_exponential_histogram_data_point : - attributes:Common.key_value list -> - start_time_unix_nano:int64 -> - time_unix_nano:int64 -> - count:int64 -> - ?sum:float option -> - scale:int32 -> - zero_count:int64 -> - ?positive:exponential_histogram_data_point_buckets option -> - ?negative:exponential_histogram_data_point_buckets option -> - flags:int32 -> - exemplars:exemplar list -> - ?min:float option -> - ?max:float option -> - zero_threshold:float -> - unit -> - exponential_histogram_data_point -(** [make_exponential_histogram_data_point … ()] is a builder for type [exponential_histogram_data_point] *) +val exponential_histogram_data_point_set_max : exponential_histogram_data_point -> float -> unit + (** set field max in exponential_histogram_data_point *) + +val exponential_histogram_data_point_has_zero_threshold : exponential_histogram_data_point -> bool + (** presence of field "zero_threshold" in [exponential_histogram_data_point] *) + +val exponential_histogram_data_point_set_zero_threshold : exponential_histogram_data_point -> float -> unit + (** set field zero_threshold in exponential_histogram_data_point *) val make_exponential_histogram : - data_points:exponential_histogram_data_point list -> - aggregation_temporality:aggregation_temporality -> + ?data_points:exponential_histogram_data_point list -> + ?aggregation_temporality:aggregation_temporality -> unit -> exponential_histogram (** [make_exponential_histogram … ()] is a builder for type [exponential_histogram] *) +val copy_exponential_histogram : exponential_histogram -> exponential_histogram + +val exponential_histogram_set_data_points : exponential_histogram -> exponential_histogram_data_point list -> unit + (** set field data_points in exponential_histogram *) + +val exponential_histogram_has_aggregation_temporality : exponential_histogram -> bool + (** presence of field "aggregation_temporality" in [exponential_histogram] *) + +val exponential_histogram_set_aggregation_temporality : exponential_histogram -> aggregation_temporality -> unit + (** set field aggregation_temporality in exponential_histogram *) + val make_summary_data_point_value_at_quantile : - quantile:float -> - value:float -> + ?quantile:float -> + ?value:float -> unit -> summary_data_point_value_at_quantile (** [make_summary_data_point_value_at_quantile … ()] is a builder for type [summary_data_point_value_at_quantile] *) +val copy_summary_data_point_value_at_quantile : summary_data_point_value_at_quantile -> summary_data_point_value_at_quantile + +val summary_data_point_value_at_quantile_has_quantile : summary_data_point_value_at_quantile -> bool + (** presence of field "quantile" in [summary_data_point_value_at_quantile] *) + +val summary_data_point_value_at_quantile_set_quantile : summary_data_point_value_at_quantile -> float -> unit + (** set field quantile in summary_data_point_value_at_quantile *) + +val summary_data_point_value_at_quantile_has_value : summary_data_point_value_at_quantile -> bool + (** presence of field "value" in [summary_data_point_value_at_quantile] *) + +val summary_data_point_value_at_quantile_set_value : summary_data_point_value_at_quantile -> float -> unit + (** set field value in summary_data_point_value_at_quantile *) + val make_summary_data_point : - attributes:Common.key_value list -> - start_time_unix_nano:int64 -> - time_unix_nano:int64 -> - count:int64 -> - sum:float -> - quantile_values:summary_data_point_value_at_quantile list -> - flags:int32 -> + ?attributes:Common.key_value list -> + ?start_time_unix_nano:int64 -> + ?time_unix_nano:int64 -> + ?count:int64 -> + ?sum:float -> + ?quantile_values:summary_data_point_value_at_quantile list -> + ?flags:int32 -> unit -> summary_data_point (** [make_summary_data_point … ()] is a builder for type [summary_data_point] *) +val copy_summary_data_point : summary_data_point -> summary_data_point + +val summary_data_point_set_attributes : summary_data_point -> Common.key_value list -> unit + (** set field attributes in summary_data_point *) + +val summary_data_point_has_start_time_unix_nano : summary_data_point -> bool + (** presence of field "start_time_unix_nano" in [summary_data_point] *) + +val summary_data_point_set_start_time_unix_nano : summary_data_point -> int64 -> unit + (** set field start_time_unix_nano in summary_data_point *) + +val summary_data_point_has_time_unix_nano : summary_data_point -> bool + (** presence of field "time_unix_nano" in [summary_data_point] *) + +val summary_data_point_set_time_unix_nano : summary_data_point -> int64 -> unit + (** set field time_unix_nano in summary_data_point *) + +val summary_data_point_has_count : summary_data_point -> bool + (** presence of field "count" in [summary_data_point] *) + +val summary_data_point_set_count : summary_data_point -> int64 -> unit + (** set field count in summary_data_point *) + +val summary_data_point_has_sum : summary_data_point -> bool + (** presence of field "sum" in [summary_data_point] *) + +val summary_data_point_set_sum : summary_data_point -> float -> unit + (** set field sum in summary_data_point *) + +val summary_data_point_set_quantile_values : summary_data_point -> summary_data_point_value_at_quantile list -> unit + (** set field quantile_values in summary_data_point *) + +val summary_data_point_has_flags : summary_data_point -> bool + (** presence of field "flags" in [summary_data_point] *) + +val summary_data_point_set_flags : summary_data_point -> int32 -> unit + (** set field flags in summary_data_point *) + val make_summary : - data_points:summary_data_point list -> + ?data_points:summary_data_point list -> unit -> summary (** [make_summary … ()] is a builder for type [summary] *) +val copy_summary : summary -> summary + +val summary_set_data_points : summary -> summary_data_point list -> unit + (** set field data_points in summary *) val make_metric : - name:string -> - description:string -> - unit_:string -> - data:metric_data -> + ?name:string -> + ?description:string -> + ?unit_:string -> + ?data:metric_data -> + ?metadata:Common.key_value list -> unit -> metric (** [make_metric … ()] is a builder for type [metric] *) +val copy_metric : metric -> metric + +val metric_has_name : metric -> bool + (** presence of field "name" in [metric] *) + +val metric_set_name : metric -> string -> unit + (** set field name in metric *) + +val metric_has_description : metric -> bool + (** presence of field "description" in [metric] *) + +val metric_set_description : metric -> string -> unit + (** set field description in metric *) + +val metric_has_unit_ : metric -> bool + (** presence of field "unit_" in [metric] *) + +val metric_set_unit_ : metric -> string -> unit + (** set field unit_ in metric *) + +val metric_set_data : metric -> metric_data -> unit + (** set field data in metric *) + +val metric_set_metadata : metric -> Common.key_value list -> unit + (** set field metadata in metric *) + val make_scope_metrics : - ?scope:Common.instrumentation_scope option -> - metrics:metric list -> - schema_url:string -> + ?scope:Common.instrumentation_scope -> + ?metrics:metric list -> + ?schema_url:string -> unit -> scope_metrics (** [make_scope_metrics … ()] is a builder for type [scope_metrics] *) +val copy_scope_metrics : scope_metrics -> scope_metrics + +val scope_metrics_set_scope : scope_metrics -> Common.instrumentation_scope -> unit + (** set field scope in scope_metrics *) + +val scope_metrics_set_metrics : scope_metrics -> metric list -> unit + (** set field metrics in scope_metrics *) + +val scope_metrics_has_schema_url : scope_metrics -> bool + (** presence of field "schema_url" in [scope_metrics] *) + +val scope_metrics_set_schema_url : scope_metrics -> string -> unit + (** set field schema_url in scope_metrics *) + val make_resource_metrics : - ?resource:Resource.resource option -> - scope_metrics:scope_metrics list -> - schema_url:string -> + ?resource:Resource.resource -> + ?scope_metrics:scope_metrics list -> + ?schema_url:string -> unit -> resource_metrics (** [make_resource_metrics … ()] is a builder for type [resource_metrics] *) +val copy_resource_metrics : resource_metrics -> resource_metrics + +val resource_metrics_set_resource : resource_metrics -> Resource.resource -> unit + (** set field resource in resource_metrics *) + +val resource_metrics_set_scope_metrics : resource_metrics -> scope_metrics list -> unit + (** set field scope_metrics in resource_metrics *) + +val resource_metrics_has_schema_url : resource_metrics -> bool + (** presence of field "schema_url" in [resource_metrics] *) + +val resource_metrics_set_schema_url : resource_metrics -> string -> unit + (** set field schema_url in resource_metrics *) + val make_metrics_data : - resource_metrics:resource_metrics list -> + ?resource_metrics:resource_metrics list -> unit -> metrics_data (** [make_metrics_data … ()] is a builder for type [metrics_data] *) +val copy_metrics_data : metrics_data -> metrics_data + +val metrics_data_set_resource_metrics : metrics_data -> resource_metrics list -> unit + (** set field resource_metrics in metrics_data *) (** {2 Formatters} *) diff --git a/src/proto/metrics_service.ml b/src/proto/metrics_service.ml index 6d1fa094..1d39a204 100644 --- a/src/proto/metrics_service.ml +++ b/src/proto/metrics_service.ml @@ -1,88 +1,94 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type export_metrics_service_request = { - resource_metrics : Metrics.resource_metrics list; + mutable resource_metrics : Metrics.resource_metrics list; } type export_metrics_partial_success = { - rejected_data_points : int64; - error_message : string; + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_data_points : int64; + mutable error_message : string; } type export_metrics_service_response = { - partial_success : export_metrics_partial_success option; + mutable partial_success : export_metrics_partial_success option; } -let rec default_export_metrics_service_request - ?resource_metrics:((resource_metrics:Metrics.resource_metrics list) = []) - () : export_metrics_service_request = { - resource_metrics; +let default_export_metrics_service_request (): export_metrics_service_request = +{ + resource_metrics=[]; } -let rec default_export_metrics_partial_success - ?rejected_data_points:((rejected_data_points:int64) = 0L) - ?error_message:((error_message:string) = "") - () : export_metrics_partial_success = { - rejected_data_points; - error_message; +let default_export_metrics_partial_success (): export_metrics_partial_success = +{ + _presence=Pbrt.Bitfield.empty; + rejected_data_points=0L; + error_message=""; } -let rec default_export_metrics_service_response - ?partial_success:((partial_success:export_metrics_partial_success option) = None) - () : export_metrics_service_response = { - partial_success; +let default_export_metrics_service_response (): export_metrics_service_response = +{ + partial_success=None; } -type export_metrics_service_request_mutable = { - mutable resource_metrics : Metrics.resource_metrics list; -} -let default_export_metrics_service_request_mutable () : export_metrics_service_request_mutable = { - resource_metrics = []; -} +(** {2 Make functions} *) -type export_metrics_partial_success_mutable = { - mutable rejected_data_points : int64; - mutable error_message : string; -} -let default_export_metrics_partial_success_mutable () : export_metrics_partial_success_mutable = { - rejected_data_points = 0L; - error_message = ""; -} +let[@inline] export_metrics_service_request_set_resource_metrics (self:export_metrics_service_request) (x:Metrics.resource_metrics list) : unit = + self.resource_metrics <- x -type export_metrics_service_response_mutable = { - mutable partial_success : export_metrics_partial_success option; -} +let copy_export_metrics_service_request (self:export_metrics_service_request) : export_metrics_service_request = + { self with resource_metrics = self.resource_metrics } -let default_export_metrics_service_response_mutable () : export_metrics_service_response_mutable = { - partial_success = None; -} +let make_export_metrics_service_request + ?(resource_metrics=[]) + () : export_metrics_service_request = + let _res = default_export_metrics_service_request () in + export_metrics_service_request_set_resource_metrics _res resource_metrics; + _res +let[@inline] export_metrics_partial_success_has_rejected_data_points (self:export_metrics_partial_success) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] export_metrics_partial_success_has_error_message (self:export_metrics_partial_success) : bool = (Pbrt.Bitfield.get self._presence 1) -(** {2 Make functions} *) +let[@inline] export_metrics_partial_success_set_rejected_data_points (self:export_metrics_partial_success) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.rejected_data_points <- x +let[@inline] export_metrics_partial_success_set_error_message (self:export_metrics_partial_success) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.error_message <- x -let rec make_export_metrics_service_request - ~(resource_metrics:Metrics.resource_metrics list) - () : export_metrics_service_request = { - resource_metrics; -} +let copy_export_metrics_partial_success (self:export_metrics_partial_success) : export_metrics_partial_success = + { self with rejected_data_points = self.rejected_data_points } -let rec make_export_metrics_partial_success - ~(rejected_data_points:int64) - ~(error_message:string) - () : export_metrics_partial_success = { - rejected_data_points; - error_message; -} +let make_export_metrics_partial_success + ?(rejected_data_points:int64 option) + ?(error_message:string option) + () : export_metrics_partial_success = + let _res = default_export_metrics_partial_success () in + (match rejected_data_points with + | None -> () + | Some v -> export_metrics_partial_success_set_rejected_data_points _res v); + (match error_message with + | None -> () + | Some v -> export_metrics_partial_success_set_error_message _res v); + _res -let rec make_export_metrics_service_response - ?partial_success:((partial_success:export_metrics_partial_success option) = None) - () : export_metrics_service_response = { - partial_success; -} -[@@@ocaml.warning "-27-30-39"] +let[@inline] export_metrics_service_response_set_partial_success (self:export_metrics_service_response) (x:export_metrics_partial_success) : unit = + self.partial_success <- Some x + +let copy_export_metrics_service_response (self:export_metrics_service_response) : export_metrics_service_response = + { self with partial_success = self.partial_success } + +let make_export_metrics_service_response + ?(partial_success:export_metrics_partial_success option) + () : export_metrics_service_response = + let _res = default_export_metrics_service_response () in + (match partial_success with + | None -> () + | Some v -> export_metrics_service_response_set_partial_success _res v); + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -94,8 +100,8 @@ let rec pp_export_metrics_service_request fmt (v:export_metrics_service_request) let rec pp_export_metrics_partial_success fmt (v:export_metrics_partial_success) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "rejected_data_points" Pbrt.Pp.pp_int64 fmt v.rejected_data_points; - Pbrt.Pp.pp_record_field ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; + Pbrt.Pp.pp_record_field ~absent:(not (export_metrics_partial_success_has_rejected_data_points v)) ~first:true "rejected_data_points" Pbrt.Pp.pp_int64 fmt v.rejected_data_points; + Pbrt.Pp.pp_record_field ~absent:(not (export_metrics_partial_success_has_error_message v)) ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; in Pbrt.Pp.pp_brk pp_i fmt () @@ -105,22 +111,26 @@ let rec pp_export_metrics_service_response fmt (v:export_metrics_service_respons in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) let rec encode_pb_export_metrics_service_request (v:export_metrics_service_request) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Metrics.encode_pb_resource_metrics x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_metrics encoder; () let rec encode_pb_export_metrics_partial_success (v:export_metrics_partial_success) encoder = - Pbrt.Encoder.int64_as_varint v.rejected_data_points encoder; - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.string v.error_message encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + if export_metrics_partial_success_has_rejected_data_points v then ( + Pbrt.Encoder.int64_as_varint v.rejected_data_points encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + ); + if export_metrics_partial_success_has_error_message v then ( + Pbrt.Encoder.string v.error_message encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); () let rec encode_pb_export_metrics_service_response (v:export_metrics_service_response) encoder = @@ -132,67 +142,61 @@ let rec encode_pb_export_metrics_service_response (v:export_metrics_service_resp end; () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) let rec decode_pb_export_metrics_service_request d = - let v = default_export_metrics_service_request_mutable () in + let v = default_export_metrics_service_request () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_metrics <- List.rev v.resource_metrics; + (* put lists in the correct order *) + export_metrics_service_request_set_resource_metrics v (List.rev v.resource_metrics); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_metrics <- (Metrics.decode_pb_resource_metrics (Pbrt.Decoder.nested d)) :: v.resource_metrics; + export_metrics_service_request_set_resource_metrics v ((Metrics.decode_pb_resource_metrics (Pbrt.Decoder.nested d)) :: v.resource_metrics); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_metrics_service_request), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_metrics_service_request" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_metrics = v.resource_metrics; - } : export_metrics_service_request) + (v : export_metrics_service_request) let rec decode_pb_export_metrics_partial_success d = - let v = default_export_metrics_partial_success_mutable () in + let v = default_export_metrics_partial_success () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.rejected_data_points <- Pbrt.Decoder.int64_as_varint d; + export_metrics_partial_success_set_rejected_data_points v (Pbrt.Decoder.int64_as_varint d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_metrics_partial_success), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_metrics_partial_success" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.error_message <- Pbrt.Decoder.string d; + export_metrics_partial_success_set_error_message v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_metrics_partial_success), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "export_metrics_partial_success" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - rejected_data_points = v.rejected_data_points; - error_message = v.error_message; - } : export_metrics_partial_success) + (v : export_metrics_partial_success) let rec decode_pb_export_metrics_service_response d = - let v = default_export_metrics_service_response_mutable () in + let v = default_export_metrics_service_response () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.partial_success <- Some (decode_pb_export_metrics_partial_success (Pbrt.Decoder.nested d)); + export_metrics_service_response_set_partial_success v (decode_pb_export_metrics_partial_success (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_metrics_service_response), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_metrics_service_response" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - partial_success = v.partial_success; - } : export_metrics_service_response) + (v : export_metrics_service_response) diff --git a/src/proto/metrics_service.mli b/src/proto/metrics_service.mli index f3357d87..36d646b3 100644 --- a/src/proto/metrics_service.mli +++ b/src/proto/metrics_service.mli @@ -7,63 +7,78 @@ (** {2 Types} *) -type export_metrics_service_request = { - resource_metrics : Metrics.resource_metrics list; +type export_metrics_service_request = private { + mutable resource_metrics : Metrics.resource_metrics list; } -type export_metrics_partial_success = { - rejected_data_points : int64; - error_message : string; +type export_metrics_partial_success = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_data_points : int64; + mutable error_message : string; } -type export_metrics_service_response = { - partial_success : export_metrics_partial_success option; +type export_metrics_service_response = private { + mutable partial_success : export_metrics_partial_success option; } (** {2 Basic values} *) -val default_export_metrics_service_request : - ?resource_metrics:Metrics.resource_metrics list -> - unit -> - export_metrics_service_request -(** [default_export_metrics_service_request ()] is the default value for type [export_metrics_service_request] *) +val default_export_metrics_service_request : unit -> export_metrics_service_request +(** [default_export_metrics_service_request ()] is a new empty value for type [export_metrics_service_request] *) -val default_export_metrics_partial_success : - ?rejected_data_points:int64 -> - ?error_message:string -> - unit -> - export_metrics_partial_success -(** [default_export_metrics_partial_success ()] is the default value for type [export_metrics_partial_success] *) +val default_export_metrics_partial_success : unit -> export_metrics_partial_success +(** [default_export_metrics_partial_success ()] is a new empty value for type [export_metrics_partial_success] *) -val default_export_metrics_service_response : - ?partial_success:export_metrics_partial_success option -> - unit -> - export_metrics_service_response -(** [default_export_metrics_service_response ()] is the default value for type [export_metrics_service_response] *) +val default_export_metrics_service_response : unit -> export_metrics_service_response +(** [default_export_metrics_service_response ()] is a new empty value for type [export_metrics_service_response] *) (** {2 Make functions} *) val make_export_metrics_service_request : - resource_metrics:Metrics.resource_metrics list -> + ?resource_metrics:Metrics.resource_metrics list -> unit -> export_metrics_service_request (** [make_export_metrics_service_request … ()] is a builder for type [export_metrics_service_request] *) +val copy_export_metrics_service_request : export_metrics_service_request -> export_metrics_service_request + +val export_metrics_service_request_set_resource_metrics : export_metrics_service_request -> Metrics.resource_metrics list -> unit + (** set field resource_metrics in export_metrics_service_request *) + val make_export_metrics_partial_success : - rejected_data_points:int64 -> - error_message:string -> + ?rejected_data_points:int64 -> + ?error_message:string -> unit -> export_metrics_partial_success (** [make_export_metrics_partial_success … ()] is a builder for type [export_metrics_partial_success] *) +val copy_export_metrics_partial_success : export_metrics_partial_success -> export_metrics_partial_success + +val export_metrics_partial_success_has_rejected_data_points : export_metrics_partial_success -> bool + (** presence of field "rejected_data_points" in [export_metrics_partial_success] *) + +val export_metrics_partial_success_set_rejected_data_points : export_metrics_partial_success -> int64 -> unit + (** set field rejected_data_points in export_metrics_partial_success *) + +val export_metrics_partial_success_has_error_message : export_metrics_partial_success -> bool + (** presence of field "error_message" in [export_metrics_partial_success] *) + +val export_metrics_partial_success_set_error_message : export_metrics_partial_success -> string -> unit + (** set field error_message in export_metrics_partial_success *) + val make_export_metrics_service_response : - ?partial_success:export_metrics_partial_success option -> + ?partial_success:export_metrics_partial_success -> unit -> export_metrics_service_response (** [make_export_metrics_service_response … ()] is a builder for type [export_metrics_service_response] *) +val copy_export_metrics_service_response : export_metrics_service_response -> export_metrics_service_response + +val export_metrics_service_response_set_partial_success : export_metrics_service_response -> export_metrics_partial_success -> unit + (** set field partial_success in export_metrics_service_response *) + (** {2 Formatters} *) diff --git a/src/proto/resource.ml b/src/proto/resource.ml index cd4b8808..913110fd 100644 --- a/src/proto/resource.ml +++ b/src/proto/resource.ml @@ -1,88 +1,108 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type resource = { - attributes : Common.key_value list; - dropped_attributes_count : int32; -} - -let rec default_resource - ?attributes:((attributes:Common.key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - () : resource = { - attributes; - dropped_attributes_count; -} - -type resource_mutable = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable attributes : Common.key_value list; mutable dropped_attributes_count : int32; + mutable entity_refs : Common.entity_ref list; } -let default_resource_mutable () : resource_mutable = { - attributes = []; - dropped_attributes_count = 0l; +let default_resource (): resource = +{ + _presence=Pbrt.Bitfield.empty; + attributes=[]; + dropped_attributes_count=0l; + entity_refs=[]; } (** {2 Make functions} *) -let rec make_resource - ~(attributes:Common.key_value list) - ~(dropped_attributes_count:int32) - () : resource = { - attributes; - dropped_attributes_count; -} - -[@@@ocaml.warning "-27-30-39"] +let[@inline] resource_has_dropped_attributes_count (self:resource) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] resource_set_attributes (self:resource) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] resource_set_dropped_attributes_count (self:resource) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.dropped_attributes_count <- x +let[@inline] resource_set_entity_refs (self:resource) (x:Common.entity_ref list) : unit = + self.entity_refs <- x + +let copy_resource (self:resource) : resource = + { self with attributes = self.attributes } + +let make_resource + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + ?(entity_refs=[]) + () : resource = + let _res = default_resource () in + resource_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> resource_set_dropped_attributes_count _res v); + resource_set_entity_refs _res entity_refs; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) let rec pp_resource fmt (v:resource) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (resource_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~first:false "entity_refs" (Pbrt.Pp.pp_list Common.pp_entity_ref) fmt v.entity_refs; in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) let rec encode_pb_resource (v:resource) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; + if resource_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.nested Common.encode_pb_entity_ref x encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ) v.entity_refs encoder; () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) let rec decode_pb_resource d = - let v = default_resource_mutable () in + let v = default_resource () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + resource_set_entity_refs v (List.rev v.entity_refs); + resource_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + resource_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "resource" 1 pk | Some (2, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + resource_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "resource" 2 pk + | Some (3, Pbrt.Bytes) -> begin + resource_set_entity_refs v ((Common.decode_pb_entity_ref (Pbrt.Decoder.nested d)) :: v.entity_refs); + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload_message "resource" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - } : resource) + (v : resource) diff --git a/src/proto/resource.mli b/src/proto/resource.mli index 88f7cb9c..ab21c2a3 100644 --- a/src/proto/resource.mli +++ b/src/proto/resource.mli @@ -7,31 +7,44 @@ (** {2 Types} *) -type resource = { - attributes : Common.key_value list; - dropped_attributes_count : int32; +type resource = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable attributes : Common.key_value list; + mutable dropped_attributes_count : int32; + mutable entity_refs : Common.entity_ref list; } (** {2 Basic values} *) -val default_resource : - ?attributes:Common.key_value list -> - ?dropped_attributes_count:int32 -> - unit -> - resource -(** [default_resource ()] is the default value for type [resource] *) +val default_resource : unit -> resource +(** [default_resource ()] is a new empty value for type [resource] *) (** {2 Make functions} *) val make_resource : - attributes:Common.key_value list -> - dropped_attributes_count:int32 -> + ?attributes:Common.key_value list -> + ?dropped_attributes_count:int32 -> + ?entity_refs:Common.entity_ref list -> unit -> resource (** [make_resource … ()] is a builder for type [resource] *) +val copy_resource : resource -> resource + +val resource_set_attributes : resource -> Common.key_value list -> unit + (** set field attributes in resource *) + +val resource_has_dropped_attributes_count : resource -> bool + (** presence of field "dropped_attributes_count" in [resource] *) + +val resource_set_dropped_attributes_count : resource -> int32 -> unit + (** set field dropped_attributes_count in resource *) + +val resource_set_entity_refs : resource -> Common.entity_ref list -> unit + (** set field entity_refs in resource *) + (** {2 Formatters} *) diff --git a/src/proto/status.ml b/src/proto/status.ml index fd9987de..64b4943f 100644 --- a/src/proto/status.ml +++ b/src/proto/status.ml @@ -1,104 +1,110 @@ -[@@@ocaml.warning "-27-30-39-44"] +[@@@ocaml.warning "-23-27-30-39-44"] type status = { - code : int32; - message : bytes; - details : bytes list; -} - -let rec default_status - ?code:((code:int32) = 0l) - ?message:((message:bytes) = Bytes.create 0) - ?details:((details:bytes list) = []) - () : status = { - code; - message; - details; -} - -type status_mutable = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) mutable code : int32; mutable message : bytes; mutable details : bytes list; } -let default_status_mutable () : status_mutable = { - code = 0l; - message = Bytes.create 0; - details = []; +let default_status (): status = +{ + _presence=Pbrt.Bitfield.empty; + code=0l; + message=Bytes.create 0; + details=[]; } (** {2 Make functions} *) -let rec make_status - ~(code:int32) - ~(message:bytes) - ~(details:bytes list) - () : status = { - code; - message; - details; -} - -[@@@ocaml.warning "-27-30-39"] +let[@inline] status_has_code (self:status) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] status_has_message (self:status) : bool = (Pbrt.Bitfield.get self._presence 1) + +let[@inline] status_set_code (self:status) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.code <- x +let[@inline] status_set_message (self:status) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.message <- x +let[@inline] status_set_details (self:status) (x:bytes list) : unit = + self.details <- x + +let copy_status (self:status) : status = + { self with code = self.code } + +let make_status + ?(code:int32 option) + ?(message:bytes option) + ?(details=[]) + () : status = + let _res = default_status () in + (match code with + | None -> () + | Some v -> status_set_code _res v); + (match message with + | None -> () + | Some v -> status_set_message _res v); + status_set_details _res details; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) let rec pp_status fmt (v:status) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "code" Pbrt.Pp.pp_int32 fmt v.code; - Pbrt.Pp.pp_record_field ~first:false "message" Pbrt.Pp.pp_bytes fmt v.message; + Pbrt.Pp.pp_record_field ~absent:(not (status_has_code v)) ~first:true "code" Pbrt.Pp.pp_int32 fmt v.code; + Pbrt.Pp.pp_record_field ~absent:(not (status_has_message v)) ~first:false "message" Pbrt.Pp.pp_bytes fmt v.message; Pbrt.Pp.pp_record_field ~first:false "details" (Pbrt.Pp.pp_list Pbrt.Pp.pp_bytes) fmt v.details; in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) let rec encode_pb_status (v:status) encoder = - Pbrt.Encoder.int32_as_varint v.code encoder; - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.bytes v.message encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if status_has_code v then ( + Pbrt.Encoder.int32_as_varint v.code encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + ); + if status_has_message v then ( + Pbrt.Encoder.bytes v.message encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.bytes x encoder; Pbrt.Encoder.key 3 Pbrt.Bytes encoder; ) v.details encoder; () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) let rec decode_pb_status d = - let v = default_status_mutable () in + let v = default_status () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.details <- List.rev v.details; + (* put lists in the correct order *) + status_set_details v (List.rev v.details); ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.code <- Pbrt.Decoder.int32_as_varint d; + status_set_code v (Pbrt.Decoder.int32_as_varint d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(status), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "status" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.message <- Pbrt.Decoder.bytes d; + status_set_message v (Pbrt.Decoder.bytes d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(status), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "status" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.details <- (Pbrt.Decoder.bytes d) :: v.details; + status_set_details v ((Pbrt.Decoder.bytes d) :: v.details); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(status), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "status" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - code = v.code; - message = v.message; - details = v.details; - } : status) + (v : status) diff --git a/src/proto/status.mli b/src/proto/status.mli index 622f1256..9abe68f9 100644 --- a/src/proto/status.mli +++ b/src/proto/status.mli @@ -7,34 +7,47 @@ (** {2 Types} *) -type status = { - code : int32; - message : bytes; - details : bytes list; +type status = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable code : int32; + mutable message : bytes; + mutable details : bytes list; } (** {2 Basic values} *) -val default_status : - ?code:int32 -> - ?message:bytes -> - ?details:bytes list -> - unit -> - status -(** [default_status ()] is the default value for type [status] *) +val default_status : unit -> status +(** [default_status ()] is a new empty value for type [status] *) (** {2 Make functions} *) val make_status : - code:int32 -> - message:bytes -> - details:bytes list -> + ?code:int32 -> + ?message:bytes -> + ?details:bytes list -> unit -> status (** [make_status … ()] is a builder for type [status] *) +val copy_status : status -> status + +val status_has_code : status -> bool + (** presence of field "code" in [status] *) + +val status_set_code : status -> int32 -> unit + (** set field code in status *) + +val status_has_message : status -> bool + (** presence of field "message" in [status] *) + +val status_set_message : status -> bytes -> unit + (** set field message in status *) + +val status_set_details : status -> bytes list -> unit + (** set field details in status *) + (** {2 Formatters} *) diff --git a/src/proto/trace.ml b/src/proto/trace.ml index 9e35831e..60c421f5 100644 --- a/src/proto/trace.ml +++ b/src/proto/trace.ml @@ -1,4 +1,4 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type span_span_kind = | Span_kind_unspecified @@ -9,207 +9,41 @@ type span_span_kind = | Span_kind_consumer type span_event = { - time_unix_nano : int64; - name : string; - attributes : Common.key_value list; - dropped_attributes_count : int32; -} - -type span_link = { - trace_id : bytes; - span_id : bytes; - trace_state : string; - attributes : Common.key_value list; - dropped_attributes_count : int32; -} - -type status_status_code = - | Status_code_unset - | Status_code_ok - | Status_code_error - -type status = { - message : string; - code : status_status_code; -} - -type span = { - trace_id : bytes; - span_id : bytes; - trace_state : string; - parent_span_id : bytes; - name : string; - kind : span_span_kind; - start_time_unix_nano : int64; - end_time_unix_nano : int64; - attributes : Common.key_value list; - dropped_attributes_count : int32; - events : span_event list; - dropped_events_count : int32; - links : span_link list; - dropped_links_count : int32; - status : status option; -} - -type scope_spans = { - scope : Common.instrumentation_scope option; - spans : span list; - schema_url : string; -} - -type resource_spans = { - resource : Resource.resource option; - scope_spans : scope_spans list; - schema_url : string; -} - -type traces_data = { - resource_spans : resource_spans list; -} - -let rec default_span_span_kind () = (Span_kind_unspecified:span_span_kind) - -let rec default_span_event - ?time_unix_nano:((time_unix_nano:int64) = 0L) - ?name:((name:string) = "") - ?attributes:((attributes:Common.key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - () : span_event = { - time_unix_nano; - name; - attributes; - dropped_attributes_count; -} - -let rec default_span_link - ?trace_id:((trace_id:bytes) = Bytes.create 0) - ?span_id:((span_id:bytes) = Bytes.create 0) - ?trace_state:((trace_state:string) = "") - ?attributes:((attributes:Common.key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - () : span_link = { - trace_id; - span_id; - trace_state; - attributes; - dropped_attributes_count; -} - -let rec default_status_status_code () = (Status_code_unset:status_status_code) - -let rec default_status - ?message:((message:string) = "") - ?code:((code:status_status_code) = default_status_status_code ()) - () : status = { - message; - code; -} - -let rec default_span - ?trace_id:((trace_id:bytes) = Bytes.create 0) - ?span_id:((span_id:bytes) = Bytes.create 0) - ?trace_state:((trace_state:string) = "") - ?parent_span_id:((parent_span_id:bytes) = Bytes.create 0) - ?name:((name:string) = "") - ?kind:((kind:span_span_kind) = default_span_span_kind ()) - ?start_time_unix_nano:((start_time_unix_nano:int64) = 0L) - ?end_time_unix_nano:((end_time_unix_nano:int64) = 0L) - ?attributes:((attributes:Common.key_value list) = []) - ?dropped_attributes_count:((dropped_attributes_count:int32) = 0l) - ?events:((events:span_event list) = []) - ?dropped_events_count:((dropped_events_count:int32) = 0l) - ?links:((links:span_link list) = []) - ?dropped_links_count:((dropped_links_count:int32) = 0l) - ?status:((status:status option) = None) - () : span = { - trace_id; - span_id; - trace_state; - parent_span_id; - name; - kind; - start_time_unix_nano; - end_time_unix_nano; - attributes; - dropped_attributes_count; - events; - dropped_events_count; - links; - dropped_links_count; - status; -} - -let rec default_scope_spans - ?scope:((scope:Common.instrumentation_scope option) = None) - ?spans:((spans:span list) = []) - ?schema_url:((schema_url:string) = "") - () : scope_spans = { - scope; - spans; - schema_url; -} - -let rec default_resource_spans - ?resource:((resource:Resource.resource option) = None) - ?scope_spans:((scope_spans:scope_spans list) = []) - ?schema_url:((schema_url:string) = "") - () : resource_spans = { - resource; - scope_spans; - schema_url; -} - -let rec default_traces_data - ?resource_spans:((resource_spans:resource_spans list) = []) - () : traces_data = { - resource_spans; -} - -type span_event_mutable = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) mutable time_unix_nano : int64; mutable name : string; mutable attributes : Common.key_value list; mutable dropped_attributes_count : int32; } -let default_span_event_mutable () : span_event_mutable = { - time_unix_nano = 0L; - name = ""; - attributes = []; - dropped_attributes_count = 0l; -} - -type span_link_mutable = { +type span_link = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 5 fields *) mutable trace_id : bytes; mutable span_id : bytes; mutable trace_state : string; mutable attributes : Common.key_value list; mutable dropped_attributes_count : int32; + mutable flags : int32; } -let default_span_link_mutable () : span_link_mutable = { - trace_id = Bytes.create 0; - span_id = Bytes.create 0; - trace_state = ""; - attributes = []; - dropped_attributes_count = 0l; -} +type status_status_code = + | Status_code_unset + | Status_code_ok + | Status_code_error -type status_mutable = { +type status = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) mutable message : string; mutable code : status_status_code; } -let default_status_mutable () : status_mutable = { - message = ""; - code = default_status_status_code (); -} - -type span_mutable = { +type span = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 12 fields *) mutable trace_id : bytes; mutable span_id : bytes; mutable trace_state : string; mutable parent_span_id : bytes; + mutable flags : int32; mutable name : string; mutable kind : span_span_kind; mutable start_time_unix_nano : int64; @@ -223,156 +57,397 @@ type span_mutable = { mutable status : status option; } -let default_span_mutable () : span_mutable = { - trace_id = Bytes.create 0; - span_id = Bytes.create 0; - trace_state = ""; - parent_span_id = Bytes.create 0; - name = ""; - kind = default_span_span_kind (); - start_time_unix_nano = 0L; - end_time_unix_nano = 0L; - attributes = []; - dropped_attributes_count = 0l; - events = []; - dropped_events_count = 0l; - links = []; - dropped_links_count = 0l; - status = None; -} - -type scope_spans_mutable = { +type scope_spans = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable scope : Common.instrumentation_scope option; mutable spans : span list; mutable schema_url : string; } -let default_scope_spans_mutable () : scope_spans_mutable = { - scope = None; - spans = []; - schema_url = ""; -} - -type resource_spans_mutable = { +type resource_spans = { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) mutable resource : Resource.resource option; mutable scope_spans : scope_spans list; mutable schema_url : string; } -let default_resource_spans_mutable () : resource_spans_mutable = { - resource = None; - scope_spans = []; - schema_url = ""; -} - -type traces_data_mutable = { +type traces_data = { mutable resource_spans : resource_spans list; } -let default_traces_data_mutable () : traces_data_mutable = { - resource_spans = []; +type span_flags = + | Span_flags_do_not_use + | Span_flags_trace_flags_mask + | Span_flags_context_has_is_remote_mask + | Span_flags_context_is_remote_mask + +let default_span_span_kind () = (Span_kind_unspecified:span_span_kind) + +let default_span_event (): span_event = +{ + _presence=Pbrt.Bitfield.empty; + time_unix_nano=0L; + name=""; + attributes=[]; + dropped_attributes_count=0l; } +let default_span_link (): span_link = +{ + _presence=Pbrt.Bitfield.empty; + trace_id=Bytes.create 0; + span_id=Bytes.create 0; + trace_state=""; + attributes=[]; + dropped_attributes_count=0l; + flags=0l; +} -(** {2 Make functions} *) - +let default_status_status_code () = (Status_code_unset:status_status_code) -let rec make_span_event - ~(time_unix_nano:int64) - ~(name:string) - ~(attributes:Common.key_value list) - ~(dropped_attributes_count:int32) - () : span_event = { - time_unix_nano; - name; - attributes; - dropped_attributes_count; +let default_status (): status = +{ + _presence=Pbrt.Bitfield.empty; + message=""; + code=default_status_status_code (); } -let rec make_span_link - ~(trace_id:bytes) - ~(span_id:bytes) - ~(trace_state:string) - ~(attributes:Common.key_value list) - ~(dropped_attributes_count:int32) - () : span_link = { - trace_id; - span_id; - trace_state; - attributes; - dropped_attributes_count; +let default_span (): span = +{ + _presence=Pbrt.Bitfield.empty; + trace_id=Bytes.create 0; + span_id=Bytes.create 0; + trace_state=""; + parent_span_id=Bytes.create 0; + flags=0l; + name=""; + kind=default_span_span_kind (); + start_time_unix_nano=0L; + end_time_unix_nano=0L; + attributes=[]; + dropped_attributes_count=0l; + events=[]; + dropped_events_count=0l; + links=[]; + dropped_links_count=0l; + status=None; } - -let rec make_status - ~(message:string) - ~(code:status_status_code) - () : status = { - message; - code; +let default_scope_spans (): scope_spans = +{ + _presence=Pbrt.Bitfield.empty; + scope=None; + spans=[]; + schema_url=""; } -let rec make_span - ~(trace_id:bytes) - ~(span_id:bytes) - ~(trace_state:string) - ~(parent_span_id:bytes) - ~(name:string) - ~(kind:span_span_kind) - ~(start_time_unix_nano:int64) - ~(end_time_unix_nano:int64) - ~(attributes:Common.key_value list) - ~(dropped_attributes_count:int32) - ~(events:span_event list) - ~(dropped_events_count:int32) - ~(links:span_link list) - ~(dropped_links_count:int32) - ?status:((status:status option) = None) - () : span = { - trace_id; - span_id; - trace_state; - parent_span_id; - name; - kind; - start_time_unix_nano; - end_time_unix_nano; - attributes; - dropped_attributes_count; - events; - dropped_events_count; - links; - dropped_links_count; - status; +let default_resource_spans (): resource_spans = +{ + _presence=Pbrt.Bitfield.empty; + resource=None; + scope_spans=[]; + schema_url=""; } -let rec make_scope_spans - ?scope:((scope:Common.instrumentation_scope option) = None) - ~(spans:span list) - ~(schema_url:string) - () : scope_spans = { - scope; - spans; - schema_url; +let default_traces_data (): traces_data = +{ + resource_spans=[]; } -let rec make_resource_spans - ?resource:((resource:Resource.resource option) = None) - ~(scope_spans:scope_spans list) - ~(schema_url:string) - () : resource_spans = { - resource; - scope_spans; - schema_url; -} +let default_span_flags () = (Span_flags_do_not_use:span_flags) -let rec make_traces_data - ~(resource_spans:resource_spans list) - () : traces_data = { - resource_spans; -} -[@@@ocaml.warning "-27-30-39"] +(** {2 Make functions} *) + +let[@inline] span_event_has_time_unix_nano (self:span_event) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] span_event_has_name (self:span_event) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] span_event_has_dropped_attributes_count (self:span_event) : bool = (Pbrt.Bitfield.get self._presence 2) + +let[@inline] span_event_set_time_unix_nano (self:span_event) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.time_unix_nano <- x +let[@inline] span_event_set_name (self:span_event) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.name <- x +let[@inline] span_event_set_attributes (self:span_event) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] span_event_set_dropped_attributes_count (self:span_event) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.dropped_attributes_count <- x + +let copy_span_event (self:span_event) : span_event = + { self with time_unix_nano = self.time_unix_nano } + +let make_span_event + ?(time_unix_nano:int64 option) + ?(name:string option) + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + () : span_event = + let _res = default_span_event () in + (match time_unix_nano with + | None -> () + | Some v -> span_event_set_time_unix_nano _res v); + (match name with + | None -> () + | Some v -> span_event_set_name _res v); + span_event_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> span_event_set_dropped_attributes_count _res v); + _res + +let[@inline] span_link_has_trace_id (self:span_link) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] span_link_has_span_id (self:span_link) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] span_link_has_trace_state (self:span_link) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] span_link_has_dropped_attributes_count (self:span_link) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] span_link_has_flags (self:span_link) : bool = (Pbrt.Bitfield.get self._presence 4) + +let[@inline] span_link_set_trace_id (self:span_link) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.trace_id <- x +let[@inline] span_link_set_span_id (self:span_link) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.span_id <- x +let[@inline] span_link_set_trace_state (self:span_link) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.trace_state <- x +let[@inline] span_link_set_attributes (self:span_link) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] span_link_set_dropped_attributes_count (self:span_link) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.dropped_attributes_count <- x +let[@inline] span_link_set_flags (self:span_link) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.flags <- x + +let copy_span_link (self:span_link) : span_link = + { self with trace_id = self.trace_id } + +let make_span_link + ?(trace_id:bytes option) + ?(span_id:bytes option) + ?(trace_state:string option) + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + ?(flags:int32 option) + () : span_link = + let _res = default_span_link () in + (match trace_id with + | None -> () + | Some v -> span_link_set_trace_id _res v); + (match span_id with + | None -> () + | Some v -> span_link_set_span_id _res v); + (match trace_state with + | None -> () + | Some v -> span_link_set_trace_state _res v); + span_link_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> span_link_set_dropped_attributes_count _res v); + (match flags with + | None -> () + | Some v -> span_link_set_flags _res v); + _res + +let[@inline] status_has_message (self:status) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] status_has_code (self:status) : bool = (Pbrt.Bitfield.get self._presence 1) + +let[@inline] status_set_message (self:status) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.message <- x +let[@inline] status_set_code (self:status) (x:status_status_code) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.code <- x + +let copy_status (self:status) : status = + { self with message = self.message } + +let make_status + ?(message:string option) + ?(code:status_status_code option) + () : status = + let _res = default_status () in + (match message with + | None -> () + | Some v -> status_set_message _res v); + (match code with + | None -> () + | Some v -> status_set_code _res v); + _res + +let[@inline] span_has_trace_id (self:span) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] span_has_span_id (self:span) : bool = (Pbrt.Bitfield.get self._presence 1) +let[@inline] span_has_trace_state (self:span) : bool = (Pbrt.Bitfield.get self._presence 2) +let[@inline] span_has_parent_span_id (self:span) : bool = (Pbrt.Bitfield.get self._presence 3) +let[@inline] span_has_flags (self:span) : bool = (Pbrt.Bitfield.get self._presence 4) +let[@inline] span_has_name (self:span) : bool = (Pbrt.Bitfield.get self._presence 5) +let[@inline] span_has_kind (self:span) : bool = (Pbrt.Bitfield.get self._presence 6) +let[@inline] span_has_start_time_unix_nano (self:span) : bool = (Pbrt.Bitfield.get self._presence 7) +let[@inline] span_has_end_time_unix_nano (self:span) : bool = (Pbrt.Bitfield.get self._presence 8) +let[@inline] span_has_dropped_attributes_count (self:span) : bool = (Pbrt.Bitfield.get self._presence 9) +let[@inline] span_has_dropped_events_count (self:span) : bool = (Pbrt.Bitfield.get self._presence 10) +let[@inline] span_has_dropped_links_count (self:span) : bool = (Pbrt.Bitfield.get self._presence 11) + +let[@inline] span_set_trace_id (self:span) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.trace_id <- x +let[@inline] span_set_span_id (self:span) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.span_id <- x +let[@inline] span_set_trace_state (self:span) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 2); self.trace_state <- x +let[@inline] span_set_parent_span_id (self:span) (x:bytes) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 3); self.parent_span_id <- x +let[@inline] span_set_flags (self:span) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 4); self.flags <- x +let[@inline] span_set_name (self:span) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 5); self.name <- x +let[@inline] span_set_kind (self:span) (x:span_span_kind) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 6); self.kind <- x +let[@inline] span_set_start_time_unix_nano (self:span) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 7); self.start_time_unix_nano <- x +let[@inline] span_set_end_time_unix_nano (self:span) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 8); self.end_time_unix_nano <- x +let[@inline] span_set_attributes (self:span) (x:Common.key_value list) : unit = + self.attributes <- x +let[@inline] span_set_dropped_attributes_count (self:span) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 9); self.dropped_attributes_count <- x +let[@inline] span_set_events (self:span) (x:span_event list) : unit = + self.events <- x +let[@inline] span_set_dropped_events_count (self:span) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 10); self.dropped_events_count <- x +let[@inline] span_set_links (self:span) (x:span_link list) : unit = + self.links <- x +let[@inline] span_set_dropped_links_count (self:span) (x:int32) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 11); self.dropped_links_count <- x +let[@inline] span_set_status (self:span) (x:status) : unit = + self.status <- Some x + +let copy_span (self:span) : span = + { self with trace_id = self.trace_id } + +let make_span + ?(trace_id:bytes option) + ?(span_id:bytes option) + ?(trace_state:string option) + ?(parent_span_id:bytes option) + ?(flags:int32 option) + ?(name:string option) + ?(kind:span_span_kind option) + ?(start_time_unix_nano:int64 option) + ?(end_time_unix_nano:int64 option) + ?(attributes=[]) + ?(dropped_attributes_count:int32 option) + ?(events=[]) + ?(dropped_events_count:int32 option) + ?(links=[]) + ?(dropped_links_count:int32 option) + ?(status:status option) + () : span = + let _res = default_span () in + (match trace_id with + | None -> () + | Some v -> span_set_trace_id _res v); + (match span_id with + | None -> () + | Some v -> span_set_span_id _res v); + (match trace_state with + | None -> () + | Some v -> span_set_trace_state _res v); + (match parent_span_id with + | None -> () + | Some v -> span_set_parent_span_id _res v); + (match flags with + | None -> () + | Some v -> span_set_flags _res v); + (match name with + | None -> () + | Some v -> span_set_name _res v); + (match kind with + | None -> () + | Some v -> span_set_kind _res v); + (match start_time_unix_nano with + | None -> () + | Some v -> span_set_start_time_unix_nano _res v); + (match end_time_unix_nano with + | None -> () + | Some v -> span_set_end_time_unix_nano _res v); + span_set_attributes _res attributes; + (match dropped_attributes_count with + | None -> () + | Some v -> span_set_dropped_attributes_count _res v); + span_set_events _res events; + (match dropped_events_count with + | None -> () + | Some v -> span_set_dropped_events_count _res v); + span_set_links _res links; + (match dropped_links_count with + | None -> () + | Some v -> span_set_dropped_links_count _res v); + (match status with + | None -> () + | Some v -> span_set_status _res v); + _res + +let[@inline] scope_spans_has_schema_url (self:scope_spans) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] scope_spans_set_scope (self:scope_spans) (x:Common.instrumentation_scope) : unit = + self.scope <- Some x +let[@inline] scope_spans_set_spans (self:scope_spans) (x:span list) : unit = + self.spans <- x +let[@inline] scope_spans_set_schema_url (self:scope_spans) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_scope_spans (self:scope_spans) : scope_spans = + { self with scope = self.scope } + +let make_scope_spans + ?(scope:Common.instrumentation_scope option) + ?(spans=[]) + ?(schema_url:string option) + () : scope_spans = + let _res = default_scope_spans () in + (match scope with + | None -> () + | Some v -> scope_spans_set_scope _res v); + scope_spans_set_spans _res spans; + (match schema_url with + | None -> () + | Some v -> scope_spans_set_schema_url _res v); + _res + +let[@inline] resource_spans_has_schema_url (self:resource_spans) : bool = (Pbrt.Bitfield.get self._presence 0) + +let[@inline] resource_spans_set_resource (self:resource_spans) (x:Resource.resource) : unit = + self.resource <- Some x +let[@inline] resource_spans_set_scope_spans (self:resource_spans) (x:scope_spans list) : unit = + self.scope_spans <- x +let[@inline] resource_spans_set_schema_url (self:resource_spans) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.schema_url <- x + +let copy_resource_spans (self:resource_spans) : resource_spans = + { self with resource = self.resource } + +let make_resource_spans + ?(resource:Resource.resource option) + ?(scope_spans=[]) + ?(schema_url:string option) + () : resource_spans = + let _res = default_resource_spans () in + (match resource with + | None -> () + | Some v -> resource_spans_set_resource _res v); + resource_spans_set_scope_spans _res scope_spans; + (match schema_url with + | None -> () + | Some v -> resource_spans_set_schema_url _res v); + _res + + +let[@inline] traces_data_set_resource_spans (self:traces_data) (x:resource_spans list) : unit = + self.resource_spans <- x + +let copy_traces_data (self:traces_data) : traces_data = + { self with resource_spans = self.resource_spans } + +let make_traces_data + ?(resource_spans=[]) + () : traces_data = + let _res = default_traces_data () in + traces_data_set_resource_spans _res resource_spans; + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -387,20 +462,21 @@ let rec pp_span_span_kind fmt (v:span_span_kind) = let rec pp_span_event fmt (v:span_event) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "name" Pbrt.Pp.pp_string fmt v.name; + Pbrt.Pp.pp_record_field ~absent:(not (span_event_has_time_unix_nano v)) ~first:true "time_unix_nano" Pbrt.Pp.pp_int64 fmt v.time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (span_event_has_name v)) ~first:false "name" Pbrt.Pp.pp_string fmt v.name; Pbrt.Pp.pp_record_field ~first:false "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_event_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_span_link fmt (v:span_link) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; - Pbrt.Pp.pp_record_field ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; - Pbrt.Pp.pp_record_field ~first:false "trace_state" Pbrt.Pp.pp_string fmt v.trace_state; + Pbrt.Pp.pp_record_field ~absent:(not (span_link_has_trace_id v)) ~first:true "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; + Pbrt.Pp.pp_record_field ~absent:(not (span_link_has_span_id v)) ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; + Pbrt.Pp.pp_record_field ~absent:(not (span_link_has_trace_state v)) ~first:false "trace_state" Pbrt.Pp.pp_string fmt v.trace_state; Pbrt.Pp.pp_record_field ~first:false "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_link_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_link_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; in Pbrt.Pp.pp_brk pp_i fmt () @@ -412,27 +488,28 @@ let rec pp_status_status_code fmt (v:status_status_code) = let rec pp_status fmt (v:status) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "message" Pbrt.Pp.pp_string fmt v.message; - Pbrt.Pp.pp_record_field ~first:false "code" pp_status_status_code fmt v.code; + Pbrt.Pp.pp_record_field ~absent:(not (status_has_message v)) ~first:true "message" Pbrt.Pp.pp_string fmt v.message; + Pbrt.Pp.pp_record_field ~absent:(not (status_has_code v)) ~first:false "code" pp_status_status_code fmt v.code; in Pbrt.Pp.pp_brk pp_i fmt () let rec pp_span fmt (v:span) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; - Pbrt.Pp.pp_record_field ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; - Pbrt.Pp.pp_record_field ~first:false "trace_state" Pbrt.Pp.pp_string fmt v.trace_state; - Pbrt.Pp.pp_record_field ~first:false "parent_span_id" Pbrt.Pp.pp_bytes fmt v.parent_span_id; - Pbrt.Pp.pp_record_field ~first:false "name" Pbrt.Pp.pp_string fmt v.name; - Pbrt.Pp.pp_record_field ~first:false "kind" pp_span_span_kind fmt v.kind; - Pbrt.Pp.pp_record_field ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; - Pbrt.Pp.pp_record_field ~first:false "end_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.end_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_trace_id v)) ~first:true "trace_id" Pbrt.Pp.pp_bytes fmt v.trace_id; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_span_id v)) ~first:false "span_id" Pbrt.Pp.pp_bytes fmt v.span_id; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_trace_state v)) ~first:false "trace_state" Pbrt.Pp.pp_string fmt v.trace_state; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_parent_span_id v)) ~first:false "parent_span_id" Pbrt.Pp.pp_bytes fmt v.parent_span_id; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_flags v)) ~first:false "flags" Pbrt.Pp.pp_int32 fmt v.flags; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_name v)) ~first:false "name" Pbrt.Pp.pp_string fmt v.name; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_kind v)) ~first:false "kind" pp_span_span_kind fmt v.kind; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_start_time_unix_nano v)) ~first:false "start_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.start_time_unix_nano; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_end_time_unix_nano v)) ~first:false "end_time_unix_nano" Pbrt.Pp.pp_int64 fmt v.end_time_unix_nano; Pbrt.Pp.pp_record_field ~first:false "attributes" (Pbrt.Pp.pp_list Common.pp_key_value) fmt v.attributes; - Pbrt.Pp.pp_record_field ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_dropped_attributes_count v)) ~first:false "dropped_attributes_count" Pbrt.Pp.pp_int32 fmt v.dropped_attributes_count; Pbrt.Pp.pp_record_field ~first:false "events" (Pbrt.Pp.pp_list pp_span_event) fmt v.events; - Pbrt.Pp.pp_record_field ~first:false "dropped_events_count" Pbrt.Pp.pp_int32 fmt v.dropped_events_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_dropped_events_count v)) ~first:false "dropped_events_count" Pbrt.Pp.pp_int32 fmt v.dropped_events_count; Pbrt.Pp.pp_record_field ~first:false "links" (Pbrt.Pp.pp_list pp_span_link) fmt v.links; - Pbrt.Pp.pp_record_field ~first:false "dropped_links_count" Pbrt.Pp.pp_int32 fmt v.dropped_links_count; + Pbrt.Pp.pp_record_field ~absent:(not (span_has_dropped_links_count v)) ~first:false "dropped_links_count" Pbrt.Pp.pp_int32 fmt v.dropped_links_count; Pbrt.Pp.pp_record_field ~first:false "status" (Pbrt.Pp.pp_option pp_status) fmt v.status; in Pbrt.Pp.pp_brk pp_i fmt () @@ -441,7 +518,7 @@ let rec pp_scope_spans fmt (v:scope_spans) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "scope" (Pbrt.Pp.pp_option Common.pp_instrumentation_scope) fmt v.scope; Pbrt.Pp.pp_record_field ~first:false "spans" (Pbrt.Pp.pp_list pp_span) fmt v.spans; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (scope_spans_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -449,7 +526,7 @@ let rec pp_resource_spans fmt (v:resource_spans) = let pp_i fmt () = Pbrt.Pp.pp_record_field ~first:true "resource" (Pbrt.Pp.pp_option Resource.pp_resource) fmt v.resource; Pbrt.Pp.pp_record_field ~first:false "scope_spans" (Pbrt.Pp.pp_list pp_scope_spans) fmt v.scope_spans; - Pbrt.Pp.pp_record_field ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; + Pbrt.Pp.pp_record_field ~absent:(not (resource_spans_has_schema_url v)) ~first:false "schema_url" Pbrt.Pp.pp_string fmt v.schema_url; in Pbrt.Pp.pp_brk pp_i fmt () @@ -459,7 +536,14 @@ let rec pp_traces_data fmt (v:traces_data) = in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +let rec pp_span_flags fmt (v:span_flags) = + match v with + | Span_flags_do_not_use -> Format.fprintf fmt "Span_flags_do_not_use" + | Span_flags_trace_flags_mask -> Format.fprintf fmt "Span_flags_trace_flags_mask" + | Span_flags_context_has_is_remote_mask -> Format.fprintf fmt "Span_flags_context_has_is_remote_mask" + | Span_flags_context_is_remote_mask -> Format.fprintf fmt "Span_flags_context_is_remote_mask" + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) @@ -473,31 +557,49 @@ let rec encode_pb_span_span_kind (v:span_span_kind) encoder = | Span_kind_consumer -> Pbrt.Encoder.int_as_varint 5 encoder let rec encode_pb_span_event (v:span_event) encoder = - Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; - Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; - Pbrt.Encoder.string v.name encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if span_event_has_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.time_unix_nano encoder; + Pbrt.Encoder.key 1 Pbrt.Bits64 encoder; + ); + if span_event_has_name v then ( + Pbrt.Encoder.string v.name encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 3 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 4 Pbrt.Varint encoder; + if span_event_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 4 Pbrt.Varint encoder; + ); () let rec encode_pb_span_link (v:span_link) encoder = - Pbrt.Encoder.bytes v.trace_id encoder; - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.bytes v.span_id encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.trace_state encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if span_link_has_trace_id v then ( + Pbrt.Encoder.bytes v.trace_id encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); + if span_link_has_span_id v then ( + Pbrt.Encoder.bytes v.span_id encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + if span_link_has_trace_state v then ( + Pbrt.Encoder.string v.trace_state encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 4 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 5 Pbrt.Varint encoder; + if span_link_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 5 Pbrt.Varint encoder; + ); + if span_link_has_flags v then ( + Pbrt.Encoder.int32_as_bits32 v.flags encoder; + Pbrt.Encoder.key 6 Pbrt.Bits32 encoder; + ); () let rec encode_pb_status_status_code (v:status_status_code) encoder = @@ -507,47 +609,77 @@ let rec encode_pb_status_status_code (v:status_status_code) encoder = | Status_code_error -> Pbrt.Encoder.int_as_varint 2 encoder let rec encode_pb_status (v:status) encoder = - Pbrt.Encoder.string v.message encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - encode_pb_status_status_code v.code encoder; - Pbrt.Encoder.key 3 Pbrt.Varint encoder; + if status_has_message v then ( + Pbrt.Encoder.string v.message encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + if status_has_code v then ( + encode_pb_status_status_code v.code encoder; + Pbrt.Encoder.key 3 Pbrt.Varint encoder; + ); () let rec encode_pb_span (v:span) encoder = - Pbrt.Encoder.bytes v.trace_id encoder; - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.bytes v.span_id encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.trace_state encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.bytes v.parent_span_id encoder; - Pbrt.Encoder.key 4 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.name encoder; - Pbrt.Encoder.key 5 Pbrt.Bytes encoder; - encode_pb_span_span_kind v.kind encoder; - Pbrt.Encoder.key 6 Pbrt.Varint encoder; - Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; - Pbrt.Encoder.key 7 Pbrt.Bits64 encoder; - Pbrt.Encoder.int64_as_bits64 v.end_time_unix_nano encoder; - Pbrt.Encoder.key 8 Pbrt.Bits64 encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if span_has_trace_id v then ( + Pbrt.Encoder.bytes v.trace_id encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ); + if span_has_span_id v then ( + Pbrt.Encoder.bytes v.span_id encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); + if span_has_trace_state v then ( + Pbrt.Encoder.string v.trace_state encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); + if span_has_parent_span_id v then ( + Pbrt.Encoder.bytes v.parent_span_id encoder; + Pbrt.Encoder.key 4 Pbrt.Bytes encoder; + ); + if span_has_flags v then ( + Pbrt.Encoder.int32_as_bits32 v.flags encoder; + Pbrt.Encoder.key 16 Pbrt.Bits32 encoder; + ); + if span_has_name v then ( + Pbrt.Encoder.string v.name encoder; + Pbrt.Encoder.key 5 Pbrt.Bytes encoder; + ); + if span_has_kind v then ( + encode_pb_span_span_kind v.kind encoder; + Pbrt.Encoder.key 6 Pbrt.Varint encoder; + ); + if span_has_start_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.start_time_unix_nano encoder; + Pbrt.Encoder.key 7 Pbrt.Bits64 encoder; + ); + if span_has_end_time_unix_nano v then ( + Pbrt.Encoder.int64_as_bits64 v.end_time_unix_nano encoder; + Pbrt.Encoder.key 8 Pbrt.Bits64 encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Common.encode_pb_key_value x encoder; Pbrt.Encoder.key 9 Pbrt.Bytes encoder; ) v.attributes encoder; - Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; - Pbrt.Encoder.key 10 Pbrt.Varint encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if span_has_dropped_attributes_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_attributes_count encoder; + Pbrt.Encoder.key 10 Pbrt.Varint encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_span_event x encoder; Pbrt.Encoder.key 11 Pbrt.Bytes encoder; ) v.events encoder; - Pbrt.Encoder.int32_as_varint v.dropped_events_count encoder; - Pbrt.Encoder.key 12 Pbrt.Varint encoder; - Pbrt.List_util.rev_iter_with (fun x encoder -> + if span_has_dropped_events_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_events_count encoder; + Pbrt.Encoder.key 12 Pbrt.Varint encoder; + ); + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_span_link x encoder; Pbrt.Encoder.key 13 Pbrt.Bytes encoder; ) v.links encoder; - Pbrt.Encoder.int32_as_varint v.dropped_links_count encoder; - Pbrt.Encoder.key 14 Pbrt.Varint encoder; + if span_has_dropped_links_count v then ( + Pbrt.Encoder.int32_as_varint v.dropped_links_count encoder; + Pbrt.Encoder.key 14 Pbrt.Varint encoder; + ); begin match v.status with | Some x -> Pbrt.Encoder.nested encode_pb_status x encoder; @@ -563,12 +695,14 @@ let rec encode_pb_scope_spans (v:scope_spans) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_span x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.spans encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if scope_spans_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_resource_spans (v:resource_spans) encoder = @@ -578,328 +712,321 @@ let rec encode_pb_resource_spans (v:resource_spans) encoder = Pbrt.Encoder.key 1 Pbrt.Bytes encoder; | None -> (); end; - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_scope_spans x encoder; Pbrt.Encoder.key 2 Pbrt.Bytes encoder; ) v.scope_spans encoder; - Pbrt.Encoder.string v.schema_url encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + if resource_spans_has_schema_url v then ( + Pbrt.Encoder.string v.schema_url encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + ); () let rec encode_pb_traces_data (v:traces_data) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested encode_pb_resource_spans x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_spans encoder; () -[@@@ocaml.warning "-27-30-39"] +let rec encode_pb_span_flags (v:span_flags) encoder = + match v with + | Span_flags_do_not_use -> Pbrt.Encoder.int_as_varint (0) encoder + | Span_flags_trace_flags_mask -> Pbrt.Encoder.int_as_varint 255 encoder + | Span_flags_context_has_is_remote_mask -> Pbrt.Encoder.int_as_varint 256 encoder + | Span_flags_context_is_remote_mask -> Pbrt.Encoder.int_as_varint 512 encoder + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) -let rec decode_pb_span_span_kind d = +let rec decode_pb_span_span_kind d : span_span_kind = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Span_kind_unspecified:span_span_kind) - | 1 -> (Span_kind_internal:span_span_kind) - | 2 -> (Span_kind_server:span_span_kind) - | 3 -> (Span_kind_client:span_span_kind) - | 4 -> (Span_kind_producer:span_span_kind) - | 5 -> (Span_kind_consumer:span_span_kind) + | 0 -> Span_kind_unspecified + | 1 -> Span_kind_internal + | 2 -> Span_kind_server + | 3 -> Span_kind_client + | 4 -> Span_kind_producer + | 5 -> Span_kind_consumer | _ -> Pbrt.Decoder.malformed_variant "span_span_kind" let rec decode_pb_span_event d = - let v = default_span_event_mutable () in + let v = default_span_event () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + span_event_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bits64) -> begin - v.time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + span_event_set_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_event), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "span_event" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.name <- Pbrt.Decoder.string d; + span_event_set_name v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_event), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "span_event" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + span_event_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_event), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "span_event" 3 pk | Some (4, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + span_event_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_event), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "span_event" 4 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - time_unix_nano = v.time_unix_nano; - name = v.name; - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - } : span_event) + (v : span_event) let rec decode_pb_span_link d = - let v = default_span_link_mutable () in + let v = default_span_link () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + span_link_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.trace_id <- Pbrt.Decoder.bytes d; + span_link_set_trace_id v (Pbrt.Decoder.bytes d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_link), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "span_link" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.span_id <- Pbrt.Decoder.bytes d; + span_link_set_span_id v (Pbrt.Decoder.bytes d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_link), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "span_link" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.trace_state <- Pbrt.Decoder.string d; + span_link_set_trace_state v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_link), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "span_link" 3 pk | Some (4, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + span_link_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_link), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "span_link" 4 pk | Some (5, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + span_link_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span_link), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "span_link" 5 pk + | Some (6, Pbrt.Bits32) -> begin + span_link_set_flags v (Pbrt.Decoder.int32_as_bits32 d); + end + | Some (6, pk) -> + Pbrt.Decoder.unexpected_payload_message "span_link" 6 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - trace_id = v.trace_id; - span_id = v.span_id; - trace_state = v.trace_state; - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - } : span_link) - -let rec decode_pb_status_status_code d = + (v : span_link) + +let rec decode_pb_status_status_code d : status_status_code = match Pbrt.Decoder.int_as_varint d with - | 0 -> (Status_code_unset:status_status_code) - | 1 -> (Status_code_ok:status_status_code) - | 2 -> (Status_code_error:status_status_code) + | 0 -> Status_code_unset + | 1 -> Status_code_ok + | 2 -> Status_code_error | _ -> Pbrt.Decoder.malformed_variant "status_status_code" let rec decode_pb_status d = - let v = default_status_mutable () in + let v = default_status () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (2, Pbrt.Bytes) -> begin - v.message <- Pbrt.Decoder.string d; + status_set_message v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(status), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "status" 2 pk | Some (3, Pbrt.Varint) -> begin - v.code <- decode_pb_status_status_code d; + status_set_code v (decode_pb_status_status_code d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(status), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "status" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - message = v.message; - code = v.code; - } : status) + (v : status) let rec decode_pb_span d = - let v = default_span_mutable () in + let v = default_span () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.links <- List.rev v.links; - v.events <- List.rev v.events; - v.attributes <- List.rev v.attributes; + (* put lists in the correct order *) + span_set_links v (List.rev v.links); + span_set_events v (List.rev v.events); + span_set_attributes v (List.rev v.attributes); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.trace_id <- Pbrt.Decoder.bytes d; + span_set_trace_id v (Pbrt.Decoder.bytes d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "span" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.span_id <- Pbrt.Decoder.bytes d; + span_set_span_id v (Pbrt.Decoder.bytes d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "span" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.trace_state <- Pbrt.Decoder.string d; + span_set_trace_state v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "span" 3 pk | Some (4, Pbrt.Bytes) -> begin - v.parent_span_id <- Pbrt.Decoder.bytes d; + span_set_parent_span_id v (Pbrt.Decoder.bytes d); end | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(4)" pk + Pbrt.Decoder.unexpected_payload_message "span" 4 pk + | Some (16, Pbrt.Bits32) -> begin + span_set_flags v (Pbrt.Decoder.int32_as_bits32 d); + end + | Some (16, pk) -> + Pbrt.Decoder.unexpected_payload_message "span" 16 pk | Some (5, Pbrt.Bytes) -> begin - v.name <- Pbrt.Decoder.string d; + span_set_name v (Pbrt.Decoder.string d); end | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(5)" pk + Pbrt.Decoder.unexpected_payload_message "span" 5 pk | Some (6, Pbrt.Varint) -> begin - v.kind <- decode_pb_span_span_kind d; + span_set_kind v (decode_pb_span_span_kind d); end | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(6)" pk + Pbrt.Decoder.unexpected_payload_message "span" 6 pk | Some (7, Pbrt.Bits64) -> begin - v.start_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + span_set_start_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(7)" pk + Pbrt.Decoder.unexpected_payload_message "span" 7 pk | Some (8, Pbrt.Bits64) -> begin - v.end_time_unix_nano <- Pbrt.Decoder.int64_as_bits64 d; + span_set_end_time_unix_nano v (Pbrt.Decoder.int64_as_bits64 d); end | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(8)" pk + Pbrt.Decoder.unexpected_payload_message "span" 8 pk | Some (9, Pbrt.Bytes) -> begin - v.attributes <- (Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes; + span_set_attributes v ((Common.decode_pb_key_value (Pbrt.Decoder.nested d)) :: v.attributes); end | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(9)" pk + Pbrt.Decoder.unexpected_payload_message "span" 9 pk | Some (10, Pbrt.Varint) -> begin - v.dropped_attributes_count <- Pbrt.Decoder.int32_as_varint d; + span_set_dropped_attributes_count v (Pbrt.Decoder.int32_as_varint d); end | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(10)" pk + Pbrt.Decoder.unexpected_payload_message "span" 10 pk | Some (11, Pbrt.Bytes) -> begin - v.events <- (decode_pb_span_event (Pbrt.Decoder.nested d)) :: v.events; + span_set_events v ((decode_pb_span_event (Pbrt.Decoder.nested d)) :: v.events); end | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(11)" pk + Pbrt.Decoder.unexpected_payload_message "span" 11 pk | Some (12, Pbrt.Varint) -> begin - v.dropped_events_count <- Pbrt.Decoder.int32_as_varint d; + span_set_dropped_events_count v (Pbrt.Decoder.int32_as_varint d); end | Some (12, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(12)" pk + Pbrt.Decoder.unexpected_payload_message "span" 12 pk | Some (13, Pbrt.Bytes) -> begin - v.links <- (decode_pb_span_link (Pbrt.Decoder.nested d)) :: v.links; + span_set_links v ((decode_pb_span_link (Pbrt.Decoder.nested d)) :: v.links); end | Some (13, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(13)" pk + Pbrt.Decoder.unexpected_payload_message "span" 13 pk | Some (14, Pbrt.Varint) -> begin - v.dropped_links_count <- Pbrt.Decoder.int32_as_varint d; + span_set_dropped_links_count v (Pbrt.Decoder.int32_as_varint d); end | Some (14, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(14)" pk + Pbrt.Decoder.unexpected_payload_message "span" 14 pk | Some (15, Pbrt.Bytes) -> begin - v.status <- Some (decode_pb_status (Pbrt.Decoder.nested d)); + span_set_status v (decode_pb_status (Pbrt.Decoder.nested d)); end | Some (15, pk) -> - Pbrt.Decoder.unexpected_payload "Message(span), field(15)" pk + Pbrt.Decoder.unexpected_payload_message "span" 15 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - trace_id = v.trace_id; - span_id = v.span_id; - trace_state = v.trace_state; - parent_span_id = v.parent_span_id; - name = v.name; - kind = v.kind; - start_time_unix_nano = v.start_time_unix_nano; - end_time_unix_nano = v.end_time_unix_nano; - attributes = v.attributes; - dropped_attributes_count = v.dropped_attributes_count; - events = v.events; - dropped_events_count = v.dropped_events_count; - links = v.links; - dropped_links_count = v.dropped_links_count; - status = v.status; - } : span) + (v : span) let rec decode_pb_scope_spans d = - let v = default_scope_spans_mutable () in + let v = default_scope_spans () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.spans <- List.rev v.spans; + (* put lists in the correct order *) + scope_spans_set_spans v (List.rev v.spans); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.scope <- Some (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); + scope_spans_set_scope v (Common.decode_pb_instrumentation_scope (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_spans), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "scope_spans" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.spans <- (decode_pb_span (Pbrt.Decoder.nested d)) :: v.spans; + scope_spans_set_spans v ((decode_pb_span (Pbrt.Decoder.nested d)) :: v.spans); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_spans), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "scope_spans" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + scope_spans_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(scope_spans), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "scope_spans" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - scope = v.scope; - spans = v.spans; - schema_url = v.schema_url; - } : scope_spans) + (v : scope_spans) let rec decode_pb_resource_spans d = - let v = default_resource_spans_mutable () in + let v = default_resource_spans () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.scope_spans <- List.rev v.scope_spans; + (* put lists in the correct order *) + resource_spans_set_scope_spans v (List.rev v.scope_spans); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource <- Some (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); + resource_spans_set_resource v (Resource.decode_pb_resource (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_spans), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "resource_spans" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.scope_spans <- (decode_pb_scope_spans (Pbrt.Decoder.nested d)) :: v.scope_spans; + resource_spans_set_scope_spans v ((decode_pb_scope_spans (Pbrt.Decoder.nested d)) :: v.scope_spans); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_spans), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "resource_spans" 2 pk | Some (3, Pbrt.Bytes) -> begin - v.schema_url <- Pbrt.Decoder.string d; + resource_spans_set_schema_url v (Pbrt.Decoder.string d); end | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(resource_spans), field(3)" pk + Pbrt.Decoder.unexpected_payload_message "resource_spans" 3 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource = v.resource; - scope_spans = v.scope_spans; - schema_url = v.schema_url; - } : resource_spans) + (v : resource_spans) let rec decode_pb_traces_data d = - let v = default_traces_data_mutable () in + let v = default_traces_data () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_spans <- List.rev v.resource_spans; + (* put lists in the correct order *) + traces_data_set_resource_spans v (List.rev v.resource_spans); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_spans <- (decode_pb_resource_spans (Pbrt.Decoder.nested d)) :: v.resource_spans; + traces_data_set_resource_spans v ((decode_pb_resource_spans (Pbrt.Decoder.nested d)) :: v.resource_spans); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(traces_data), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "traces_data" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_spans = v.resource_spans; - } : traces_data) + (v : traces_data) + +let rec decode_pb_span_flags d : span_flags = + match Pbrt.Decoder.int_as_varint d with + | 0 -> Span_flags_do_not_use + | 255 -> Span_flags_trace_flags_mask + | 256 -> Span_flags_context_has_is_remote_mask + | 512 -> Span_flags_context_is_remote_mask + | _ -> Pbrt.Decoder.malformed_variant "span_flags" diff --git a/src/proto/trace.mli b/src/proto/trace.mli index bd7598e2..ba4dcfd2 100644 --- a/src/proto/trace.mli +++ b/src/proto/trace.mli @@ -15,19 +15,22 @@ type span_span_kind = | Span_kind_producer | Span_kind_consumer -type span_event = { - time_unix_nano : int64; - name : string; - attributes : Common.key_value list; - dropped_attributes_count : int32; +type span_event = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 3 fields *) + mutable time_unix_nano : int64; + mutable name : string; + mutable attributes : Common.key_value list; + mutable dropped_attributes_count : int32; } -type span_link = { - trace_id : bytes; - span_id : bytes; - trace_state : string; - attributes : Common.key_value list; - dropped_attributes_count : int32; +type span_link = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 5 fields *) + mutable trace_id : bytes; + mutable span_id : bytes; + mutable trace_state : string; + mutable attributes : Common.key_value list; + mutable dropped_attributes_count : int32; + mutable flags : int32; } type status_status_code = @@ -35,85 +38,197 @@ type status_status_code = | Status_code_ok | Status_code_error -type status = { - message : string; - code : status_status_code; +type status = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable message : string; + mutable code : status_status_code; } -type span = { - trace_id : bytes; - span_id : bytes; - trace_state : string; - parent_span_id : bytes; - name : string; - kind : span_span_kind; - start_time_unix_nano : int64; - end_time_unix_nano : int64; - attributes : Common.key_value list; - dropped_attributes_count : int32; - events : span_event list; - dropped_events_count : int32; - links : span_link list; - dropped_links_count : int32; - status : status option; +type span = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 12 fields *) + mutable trace_id : bytes; + mutable span_id : bytes; + mutable trace_state : string; + mutable parent_span_id : bytes; + mutable flags : int32; + mutable name : string; + mutable kind : span_span_kind; + mutable start_time_unix_nano : int64; + mutable end_time_unix_nano : int64; + mutable attributes : Common.key_value list; + mutable dropped_attributes_count : int32; + mutable events : span_event list; + mutable dropped_events_count : int32; + mutable links : span_link list; + mutable dropped_links_count : int32; + mutable status : status option; } -type scope_spans = { - scope : Common.instrumentation_scope option; - spans : span list; - schema_url : string; +type scope_spans = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable scope : Common.instrumentation_scope option; + mutable spans : span list; + mutable schema_url : string; } -type resource_spans = { - resource : Resource.resource option; - scope_spans : scope_spans list; - schema_url : string; +type resource_spans = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 1 fields *) + mutable resource : Resource.resource option; + mutable scope_spans : scope_spans list; + mutable schema_url : string; } -type traces_data = { - resource_spans : resource_spans list; +type traces_data = private { + mutable resource_spans : resource_spans list; } +type span_flags = + | Span_flags_do_not_use + | Span_flags_trace_flags_mask + | Span_flags_context_has_is_remote_mask + | Span_flags_context_is_remote_mask + (** {2 Basic values} *) val default_span_span_kind : unit -> span_span_kind -(** [default_span_span_kind ()] is the default value for type [span_span_kind] *) +(** [default_span_span_kind ()] is a new empty value for type [span_span_kind] *) + +val default_span_event : unit -> span_event +(** [default_span_event ()] is a new empty value for type [span_event] *) + +val default_span_link : unit -> span_link +(** [default_span_link ()] is a new empty value for type [span_link] *) + +val default_status_status_code : unit -> status_status_code +(** [default_status_status_code ()] is a new empty value for type [status_status_code] *) + +val default_status : unit -> status +(** [default_status ()] is a new empty value for type [status] *) + +val default_span : unit -> span +(** [default_span ()] is a new empty value for type [span] *) + +val default_scope_spans : unit -> scope_spans +(** [default_scope_spans ()] is a new empty value for type [scope_spans] *) -val default_span_event : +val default_resource_spans : unit -> resource_spans +(** [default_resource_spans ()] is a new empty value for type [resource_spans] *) + +val default_traces_data : unit -> traces_data +(** [default_traces_data ()] is a new empty value for type [traces_data] *) + +val default_span_flags : unit -> span_flags +(** [default_span_flags ()] is a new empty value for type [span_flags] *) + + +(** {2 Make functions} *) + +val make_span_event : ?time_unix_nano:int64 -> ?name:string -> ?attributes:Common.key_value list -> ?dropped_attributes_count:int32 -> unit -> span_event -(** [default_span_event ()] is the default value for type [span_event] *) +(** [make_span_event … ()] is a builder for type [span_event] *) + +val copy_span_event : span_event -> span_event + +val span_event_has_time_unix_nano : span_event -> bool + (** presence of field "time_unix_nano" in [span_event] *) + +val span_event_set_time_unix_nano : span_event -> int64 -> unit + (** set field time_unix_nano in span_event *) + +val span_event_has_name : span_event -> bool + (** presence of field "name" in [span_event] *) + +val span_event_set_name : span_event -> string -> unit + (** set field name in span_event *) + +val span_event_set_attributes : span_event -> Common.key_value list -> unit + (** set field attributes in span_event *) -val default_span_link : +val span_event_has_dropped_attributes_count : span_event -> bool + (** presence of field "dropped_attributes_count" in [span_event] *) + +val span_event_set_dropped_attributes_count : span_event -> int32 -> unit + (** set field dropped_attributes_count in span_event *) + +val make_span_link : ?trace_id:bytes -> ?span_id:bytes -> ?trace_state:string -> ?attributes:Common.key_value list -> ?dropped_attributes_count:int32 -> + ?flags:int32 -> unit -> span_link -(** [default_span_link ()] is the default value for type [span_link] *) +(** [make_span_link … ()] is a builder for type [span_link] *) -val default_status_status_code : unit -> status_status_code -(** [default_status_status_code ()] is the default value for type [status_status_code] *) +val copy_span_link : span_link -> span_link + +val span_link_has_trace_id : span_link -> bool + (** presence of field "trace_id" in [span_link] *) + +val span_link_set_trace_id : span_link -> bytes -> unit + (** set field trace_id in span_link *) -val default_status : +val span_link_has_span_id : span_link -> bool + (** presence of field "span_id" in [span_link] *) + +val span_link_set_span_id : span_link -> bytes -> unit + (** set field span_id in span_link *) + +val span_link_has_trace_state : span_link -> bool + (** presence of field "trace_state" in [span_link] *) + +val span_link_set_trace_state : span_link -> string -> unit + (** set field trace_state in span_link *) + +val span_link_set_attributes : span_link -> Common.key_value list -> unit + (** set field attributes in span_link *) + +val span_link_has_dropped_attributes_count : span_link -> bool + (** presence of field "dropped_attributes_count" in [span_link] *) + +val span_link_set_dropped_attributes_count : span_link -> int32 -> unit + (** set field dropped_attributes_count in span_link *) + +val span_link_has_flags : span_link -> bool + (** presence of field "flags" in [span_link] *) + +val span_link_set_flags : span_link -> int32 -> unit + (** set field flags in span_link *) + +val make_status : ?message:string -> ?code:status_status_code -> unit -> status -(** [default_status ()] is the default value for type [status] *) +(** [make_status … ()] is a builder for type [status] *) + +val copy_status : status -> status + +val status_has_message : status -> bool + (** presence of field "message" in [status] *) + +val status_set_message : status -> string -> unit + (** set field message in status *) -val default_span : +val status_has_code : status -> bool + (** presence of field "code" in [status] *) + +val status_set_code : status -> status_status_code -> unit + (** set field code in status *) + +val make_span : ?trace_id:bytes -> ?span_id:bytes -> ?trace_state:string -> ?parent_span_id:bytes -> + ?flags:int32 -> ?name:string -> ?kind:span_span_kind -> ?start_time_unix_nano:int64 -> @@ -124,106 +239,152 @@ val default_span : ?dropped_events_count:int32 -> ?links:span_link list -> ?dropped_links_count:int32 -> - ?status:status option -> + ?status:status -> unit -> span -(** [default_span ()] is the default value for type [span] *) +(** [make_span … ()] is a builder for type [span] *) -val default_scope_spans : - ?scope:Common.instrumentation_scope option -> - ?spans:span list -> - ?schema_url:string -> - unit -> - scope_spans -(** [default_scope_spans ()] is the default value for type [scope_spans] *) +val copy_span : span -> span -val default_resource_spans : - ?resource:Resource.resource option -> - ?scope_spans:scope_spans list -> - ?schema_url:string -> - unit -> - resource_spans -(** [default_resource_spans ()] is the default value for type [resource_spans] *) +val span_has_trace_id : span -> bool + (** presence of field "trace_id" in [span] *) -val default_traces_data : - ?resource_spans:resource_spans list -> - unit -> - traces_data -(** [default_traces_data ()] is the default value for type [traces_data] *) +val span_set_trace_id : span -> bytes -> unit + (** set field trace_id in span *) +val span_has_span_id : span -> bool + (** presence of field "span_id" in [span] *) -(** {2 Make functions} *) +val span_set_span_id : span -> bytes -> unit + (** set field span_id in span *) +val span_has_trace_state : span -> bool + (** presence of field "trace_state" in [span] *) -val make_span_event : - time_unix_nano:int64 -> - name:string -> - attributes:Common.key_value list -> - dropped_attributes_count:int32 -> - unit -> - span_event -(** [make_span_event … ()] is a builder for type [span_event] *) +val span_set_trace_state : span -> string -> unit + (** set field trace_state in span *) -val make_span_link : - trace_id:bytes -> - span_id:bytes -> - trace_state:string -> - attributes:Common.key_value list -> - dropped_attributes_count:int32 -> - unit -> - span_link -(** [make_span_link … ()] is a builder for type [span_link] *) +val span_has_parent_span_id : span -> bool + (** presence of field "parent_span_id" in [span] *) +val span_set_parent_span_id : span -> bytes -> unit + (** set field parent_span_id in span *) -val make_status : - message:string -> - code:status_status_code -> - unit -> - status -(** [make_status … ()] is a builder for type [status] *) +val span_has_flags : span -> bool + (** presence of field "flags" in [span] *) -val make_span : - trace_id:bytes -> - span_id:bytes -> - trace_state:string -> - parent_span_id:bytes -> - name:string -> - kind:span_span_kind -> - start_time_unix_nano:int64 -> - end_time_unix_nano:int64 -> - attributes:Common.key_value list -> - dropped_attributes_count:int32 -> - events:span_event list -> - dropped_events_count:int32 -> - links:span_link list -> - dropped_links_count:int32 -> - ?status:status option -> - unit -> - span -(** [make_span … ()] is a builder for type [span] *) +val span_set_flags : span -> int32 -> unit + (** set field flags in span *) + +val span_has_name : span -> bool + (** presence of field "name" in [span] *) + +val span_set_name : span -> string -> unit + (** set field name in span *) + +val span_has_kind : span -> bool + (** presence of field "kind" in [span] *) + +val span_set_kind : span -> span_span_kind -> unit + (** set field kind in span *) + +val span_has_start_time_unix_nano : span -> bool + (** presence of field "start_time_unix_nano" in [span] *) + +val span_set_start_time_unix_nano : span -> int64 -> unit + (** set field start_time_unix_nano in span *) + +val span_has_end_time_unix_nano : span -> bool + (** presence of field "end_time_unix_nano" in [span] *) + +val span_set_end_time_unix_nano : span -> int64 -> unit + (** set field end_time_unix_nano in span *) + +val span_set_attributes : span -> Common.key_value list -> unit + (** set field attributes in span *) + +val span_has_dropped_attributes_count : span -> bool + (** presence of field "dropped_attributes_count" in [span] *) + +val span_set_dropped_attributes_count : span -> int32 -> unit + (** set field dropped_attributes_count in span *) + +val span_set_events : span -> span_event list -> unit + (** set field events in span *) + +val span_has_dropped_events_count : span -> bool + (** presence of field "dropped_events_count" in [span] *) + +val span_set_dropped_events_count : span -> int32 -> unit + (** set field dropped_events_count in span *) + +val span_set_links : span -> span_link list -> unit + (** set field links in span *) + +val span_has_dropped_links_count : span -> bool + (** presence of field "dropped_links_count" in [span] *) + +val span_set_dropped_links_count : span -> int32 -> unit + (** set field dropped_links_count in span *) + +val span_set_status : span -> status -> unit + (** set field status in span *) val make_scope_spans : - ?scope:Common.instrumentation_scope option -> - spans:span list -> - schema_url:string -> + ?scope:Common.instrumentation_scope -> + ?spans:span list -> + ?schema_url:string -> unit -> scope_spans (** [make_scope_spans … ()] is a builder for type [scope_spans] *) +val copy_scope_spans : scope_spans -> scope_spans + +val scope_spans_set_scope : scope_spans -> Common.instrumentation_scope -> unit + (** set field scope in scope_spans *) + +val scope_spans_set_spans : scope_spans -> span list -> unit + (** set field spans in scope_spans *) + +val scope_spans_has_schema_url : scope_spans -> bool + (** presence of field "schema_url" in [scope_spans] *) + +val scope_spans_set_schema_url : scope_spans -> string -> unit + (** set field schema_url in scope_spans *) + val make_resource_spans : - ?resource:Resource.resource option -> - scope_spans:scope_spans list -> - schema_url:string -> + ?resource:Resource.resource -> + ?scope_spans:scope_spans list -> + ?schema_url:string -> unit -> resource_spans (** [make_resource_spans … ()] is a builder for type [resource_spans] *) +val copy_resource_spans : resource_spans -> resource_spans + +val resource_spans_set_resource : resource_spans -> Resource.resource -> unit + (** set field resource in resource_spans *) + +val resource_spans_set_scope_spans : resource_spans -> scope_spans list -> unit + (** set field scope_spans in resource_spans *) + +val resource_spans_has_schema_url : resource_spans -> bool + (** presence of field "schema_url" in [resource_spans] *) + +val resource_spans_set_schema_url : resource_spans -> string -> unit + (** set field schema_url in resource_spans *) + val make_traces_data : - resource_spans:resource_spans list -> + ?resource_spans:resource_spans list -> unit -> traces_data (** [make_traces_data … ()] is a builder for type [traces_data] *) +val copy_traces_data : traces_data -> traces_data + +val traces_data_set_resource_spans : traces_data -> resource_spans list -> unit + (** set field resource_spans in traces_data *) + (** {2 Formatters} *) @@ -254,6 +415,9 @@ val pp_resource_spans : Format.formatter -> resource_spans -> unit val pp_traces_data : Format.formatter -> traces_data -> unit (** [pp_traces_data v] formats v *) +val pp_span_flags : Format.formatter -> span_flags -> unit +(** [pp_span_flags v] formats v *) + (** {2 Protobuf Encoding} *) @@ -284,6 +448,9 @@ val encode_pb_resource_spans : resource_spans -> Pbrt.Encoder.t -> unit val encode_pb_traces_data : traces_data -> Pbrt.Encoder.t -> unit (** [encode_pb_traces_data v encoder] encodes [v] with the given [encoder] *) +val encode_pb_span_flags : span_flags -> Pbrt.Encoder.t -> unit +(** [encode_pb_span_flags v encoder] encodes [v] with the given [encoder] *) + (** {2 Protobuf Decoding} *) @@ -313,3 +480,6 @@ val decode_pb_resource_spans : Pbrt.Decoder.t -> resource_spans val decode_pb_traces_data : Pbrt.Decoder.t -> traces_data (** [decode_pb_traces_data decoder] decodes a [traces_data] binary value from [decoder] *) + +val decode_pb_span_flags : Pbrt.Decoder.t -> span_flags +(** [decode_pb_span_flags decoder] decodes a [span_flags] binary value from [decoder] *) diff --git a/src/proto/trace_service.ml b/src/proto/trace_service.ml index 79f5fe8d..4839ec04 100644 --- a/src/proto/trace_service.ml +++ b/src/proto/trace_service.ml @@ -1,88 +1,94 @@ -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39-44"] type export_trace_service_request = { - resource_spans : Trace.resource_spans list; + mutable resource_spans : Trace.resource_spans list; } type export_trace_partial_success = { - rejected_spans : int64; - error_message : string; + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_spans : int64; + mutable error_message : string; } type export_trace_service_response = { - partial_success : export_trace_partial_success option; + mutable partial_success : export_trace_partial_success option; } -let rec default_export_trace_service_request - ?resource_spans:((resource_spans:Trace.resource_spans list) = []) - () : export_trace_service_request = { - resource_spans; +let default_export_trace_service_request (): export_trace_service_request = +{ + resource_spans=[]; } -let rec default_export_trace_partial_success - ?rejected_spans:((rejected_spans:int64) = 0L) - ?error_message:((error_message:string) = "") - () : export_trace_partial_success = { - rejected_spans; - error_message; +let default_export_trace_partial_success (): export_trace_partial_success = +{ + _presence=Pbrt.Bitfield.empty; + rejected_spans=0L; + error_message=""; } -let rec default_export_trace_service_response - ?partial_success:((partial_success:export_trace_partial_success option) = None) - () : export_trace_service_response = { - partial_success; +let default_export_trace_service_response (): export_trace_service_response = +{ + partial_success=None; } -type export_trace_service_request_mutable = { - mutable resource_spans : Trace.resource_spans list; -} -let default_export_trace_service_request_mutable () : export_trace_service_request_mutable = { - resource_spans = []; -} +(** {2 Make functions} *) -type export_trace_partial_success_mutable = { - mutable rejected_spans : int64; - mutable error_message : string; -} -let default_export_trace_partial_success_mutable () : export_trace_partial_success_mutable = { - rejected_spans = 0L; - error_message = ""; -} +let[@inline] export_trace_service_request_set_resource_spans (self:export_trace_service_request) (x:Trace.resource_spans list) : unit = + self.resource_spans <- x -type export_trace_service_response_mutable = { - mutable partial_success : export_trace_partial_success option; -} +let copy_export_trace_service_request (self:export_trace_service_request) : export_trace_service_request = + { self with resource_spans = self.resource_spans } -let default_export_trace_service_response_mutable () : export_trace_service_response_mutable = { - partial_success = None; -} +let make_export_trace_service_request + ?(resource_spans=[]) + () : export_trace_service_request = + let _res = default_export_trace_service_request () in + export_trace_service_request_set_resource_spans _res resource_spans; + _res +let[@inline] export_trace_partial_success_has_rejected_spans (self:export_trace_partial_success) : bool = (Pbrt.Bitfield.get self._presence 0) +let[@inline] export_trace_partial_success_has_error_message (self:export_trace_partial_success) : bool = (Pbrt.Bitfield.get self._presence 1) -(** {2 Make functions} *) +let[@inline] export_trace_partial_success_set_rejected_spans (self:export_trace_partial_success) (x:int64) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 0); self.rejected_spans <- x +let[@inline] export_trace_partial_success_set_error_message (self:export_trace_partial_success) (x:string) : unit = + self._presence <- (Pbrt.Bitfield.set self._presence 1); self.error_message <- x -let rec make_export_trace_service_request - ~(resource_spans:Trace.resource_spans list) - () : export_trace_service_request = { - resource_spans; -} +let copy_export_trace_partial_success (self:export_trace_partial_success) : export_trace_partial_success = + { self with rejected_spans = self.rejected_spans } -let rec make_export_trace_partial_success - ~(rejected_spans:int64) - ~(error_message:string) - () : export_trace_partial_success = { - rejected_spans; - error_message; -} +let make_export_trace_partial_success + ?(rejected_spans:int64 option) + ?(error_message:string option) + () : export_trace_partial_success = + let _res = default_export_trace_partial_success () in + (match rejected_spans with + | None -> () + | Some v -> export_trace_partial_success_set_rejected_spans _res v); + (match error_message with + | None -> () + | Some v -> export_trace_partial_success_set_error_message _res v); + _res -let rec make_export_trace_service_response - ?partial_success:((partial_success:export_trace_partial_success option) = None) - () : export_trace_service_response = { - partial_success; -} -[@@@ocaml.warning "-27-30-39"] +let[@inline] export_trace_service_response_set_partial_success (self:export_trace_service_response) (x:export_trace_partial_success) : unit = + self.partial_success <- Some x + +let copy_export_trace_service_response (self:export_trace_service_response) : export_trace_service_response = + { self with partial_success = self.partial_success } + +let make_export_trace_service_response + ?(partial_success:export_trace_partial_success option) + () : export_trace_service_response = + let _res = default_export_trace_service_response () in + (match partial_success with + | None -> () + | Some v -> export_trace_service_response_set_partial_success _res v); + _res + +[@@@ocaml.warning "-23-27-30-39"] (** {2 Formatters} *) @@ -94,8 +100,8 @@ let rec pp_export_trace_service_request fmt (v:export_trace_service_request) = let rec pp_export_trace_partial_success fmt (v:export_trace_partial_success) = let pp_i fmt () = - Pbrt.Pp.pp_record_field ~first:true "rejected_spans" Pbrt.Pp.pp_int64 fmt v.rejected_spans; - Pbrt.Pp.pp_record_field ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; + Pbrt.Pp.pp_record_field ~absent:(not (export_trace_partial_success_has_rejected_spans v)) ~first:true "rejected_spans" Pbrt.Pp.pp_int64 fmt v.rejected_spans; + Pbrt.Pp.pp_record_field ~absent:(not (export_trace_partial_success_has_error_message v)) ~first:false "error_message" Pbrt.Pp.pp_string fmt v.error_message; in Pbrt.Pp.pp_brk pp_i fmt () @@ -105,22 +111,26 @@ let rec pp_export_trace_service_response fmt (v:export_trace_service_response) = in Pbrt.Pp.pp_brk pp_i fmt () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Encoding} *) let rec encode_pb_export_trace_service_request (v:export_trace_service_request) encoder = - Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.List_util.rev_iter_with (fun x encoder -> Pbrt.Encoder.nested Trace.encode_pb_resource_spans x encoder; Pbrt.Encoder.key 1 Pbrt.Bytes encoder; ) v.resource_spans encoder; () let rec encode_pb_export_trace_partial_success (v:export_trace_partial_success) encoder = - Pbrt.Encoder.int64_as_varint v.rejected_spans encoder; - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.string v.error_message encoder; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + if export_trace_partial_success_has_rejected_spans v then ( + Pbrt.Encoder.int64_as_varint v.rejected_spans encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + ); + if export_trace_partial_success_has_error_message v then ( + Pbrt.Encoder.string v.error_message encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + ); () let rec encode_pb_export_trace_service_response (v:export_trace_service_response) encoder = @@ -132,67 +142,61 @@ let rec encode_pb_export_trace_service_response (v:export_trace_service_response end; () -[@@@ocaml.warning "-27-30-39"] +[@@@ocaml.warning "-23-27-30-39"] (** {2 Protobuf Decoding} *) let rec decode_pb_export_trace_service_request d = - let v = default_export_trace_service_request_mutable () in + let v = default_export_trace_service_request () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( - v.resource_spans <- List.rev v.resource_spans; + (* put lists in the correct order *) + export_trace_service_request_set_resource_spans v (List.rev v.resource_spans); ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.resource_spans <- (Trace.decode_pb_resource_spans (Pbrt.Decoder.nested d)) :: v.resource_spans; + export_trace_service_request_set_resource_spans v ((Trace.decode_pb_resource_spans (Pbrt.Decoder.nested d)) :: v.resource_spans); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_trace_service_request), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_trace_service_request" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - resource_spans = v.resource_spans; - } : export_trace_service_request) + (v : export_trace_service_request) let rec decode_pb_export_trace_partial_success d = - let v = default_export_trace_partial_success_mutable () in + let v = default_export_trace_partial_success () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.rejected_spans <- Pbrt.Decoder.int64_as_varint d; + export_trace_partial_success_set_rejected_spans v (Pbrt.Decoder.int64_as_varint d); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_trace_partial_success), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_trace_partial_success" 1 pk | Some (2, Pbrt.Bytes) -> begin - v.error_message <- Pbrt.Decoder.string d; + export_trace_partial_success_set_error_message v (Pbrt.Decoder.string d); end | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_trace_partial_success), field(2)" pk + Pbrt.Decoder.unexpected_payload_message "export_trace_partial_success" 2 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - rejected_spans = v.rejected_spans; - error_message = v.error_message; - } : export_trace_partial_success) + (v : export_trace_partial_success) let rec decode_pb_export_trace_service_response d = - let v = default_export_trace_service_response_mutable () in + let v = default_export_trace_service_response () in let continue__= ref true in while !continue__ do match Pbrt.Decoder.key d with | None -> ( ); continue__ := false | Some (1, Pbrt.Bytes) -> begin - v.partial_success <- Some (decode_pb_export_trace_partial_success (Pbrt.Decoder.nested d)); + export_trace_service_response_set_partial_success v (decode_pb_export_trace_partial_success (Pbrt.Decoder.nested d)); end | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(export_trace_service_response), field(1)" pk + Pbrt.Decoder.unexpected_payload_message "export_trace_service_response" 1 pk | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind done; - ({ - partial_success = v.partial_success; - } : export_trace_service_response) + (v : export_trace_service_response) diff --git a/src/proto/trace_service.mli b/src/proto/trace_service.mli index 4b555371..67932f0b 100644 --- a/src/proto/trace_service.mli +++ b/src/proto/trace_service.mli @@ -7,63 +7,78 @@ (** {2 Types} *) -type export_trace_service_request = { - resource_spans : Trace.resource_spans list; +type export_trace_service_request = private { + mutable resource_spans : Trace.resource_spans list; } -type export_trace_partial_success = { - rejected_spans : int64; - error_message : string; +type export_trace_partial_success = private { + mutable _presence: Pbrt.Bitfield.t; (** presence for 2 fields *) + mutable rejected_spans : int64; + mutable error_message : string; } -type export_trace_service_response = { - partial_success : export_trace_partial_success option; +type export_trace_service_response = private { + mutable partial_success : export_trace_partial_success option; } (** {2 Basic values} *) -val default_export_trace_service_request : - ?resource_spans:Trace.resource_spans list -> - unit -> - export_trace_service_request -(** [default_export_trace_service_request ()] is the default value for type [export_trace_service_request] *) +val default_export_trace_service_request : unit -> export_trace_service_request +(** [default_export_trace_service_request ()] is a new empty value for type [export_trace_service_request] *) -val default_export_trace_partial_success : - ?rejected_spans:int64 -> - ?error_message:string -> - unit -> - export_trace_partial_success -(** [default_export_trace_partial_success ()] is the default value for type [export_trace_partial_success] *) +val default_export_trace_partial_success : unit -> export_trace_partial_success +(** [default_export_trace_partial_success ()] is a new empty value for type [export_trace_partial_success] *) -val default_export_trace_service_response : - ?partial_success:export_trace_partial_success option -> - unit -> - export_trace_service_response -(** [default_export_trace_service_response ()] is the default value for type [export_trace_service_response] *) +val default_export_trace_service_response : unit -> export_trace_service_response +(** [default_export_trace_service_response ()] is a new empty value for type [export_trace_service_response] *) (** {2 Make functions} *) val make_export_trace_service_request : - resource_spans:Trace.resource_spans list -> + ?resource_spans:Trace.resource_spans list -> unit -> export_trace_service_request (** [make_export_trace_service_request … ()] is a builder for type [export_trace_service_request] *) +val copy_export_trace_service_request : export_trace_service_request -> export_trace_service_request + +val export_trace_service_request_set_resource_spans : export_trace_service_request -> Trace.resource_spans list -> unit + (** set field resource_spans in export_trace_service_request *) + val make_export_trace_partial_success : - rejected_spans:int64 -> - error_message:string -> + ?rejected_spans:int64 -> + ?error_message:string -> unit -> export_trace_partial_success (** [make_export_trace_partial_success … ()] is a builder for type [export_trace_partial_success] *) +val copy_export_trace_partial_success : export_trace_partial_success -> export_trace_partial_success + +val export_trace_partial_success_has_rejected_spans : export_trace_partial_success -> bool + (** presence of field "rejected_spans" in [export_trace_partial_success] *) + +val export_trace_partial_success_set_rejected_spans : export_trace_partial_success -> int64 -> unit + (** set field rejected_spans in export_trace_partial_success *) + +val export_trace_partial_success_has_error_message : export_trace_partial_success -> bool + (** presence of field "error_message" in [export_trace_partial_success] *) + +val export_trace_partial_success_set_error_message : export_trace_partial_success -> string -> unit + (** set field error_message in export_trace_partial_success *) + val make_export_trace_service_response : - ?partial_success:export_trace_partial_success option -> + ?partial_success:export_trace_partial_success -> unit -> export_trace_service_response (** [make_export_trace_service_response … ()] is a builder for type [export_trace_service_response] *) +val copy_export_trace_service_response : export_trace_service_response -> export_trace_service_response + +val export_trace_service_response_set_partial_success : export_trace_service_response -> export_trace_partial_success -> unit + (** set field partial_success in export_trace_service_response *) + (** {2 Formatters} *) diff --git a/src/trace/opentelemetry_trace.ml b/src/trace/opentelemetry_trace.ml index 0126257b..ead41826 100644 --- a/src/trace/opentelemetry_trace.ml +++ b/src/trace/opentelemetry_trace.ml @@ -193,8 +193,9 @@ module Internal = struct let status : Span_status.t = match List.assoc_opt Well_known.status_error_key attrs with - | Some (`String message) -> { message; code = Status_code_error } - | _ -> { message = ""; code = Status_code_ok } + | Some (`String message) -> + Span_status.make ~message ~code:Status_code_error + | _ -> Span_status.make ~message:"" ~code:Status_code_ok in let attrs = diff --git a/tests/bin/emit1.ml b/tests/bin/emit1.ml index 95a4d55b..fdcdbc06 100644 --- a/tests/bin/emit1.ml +++ b/tests/bin/emit1.ml @@ -86,6 +86,8 @@ let run () = [ sum ~name:"num-sleep" ~is_monotonic:true [ int (Atomic.get num_sleep) ]; + sum ~name:"otel.bytes-sent" ~is_monotonic:true ~unit_:"B" + [ int (Opentelemetry_client_ocurl.n_bytes_sent ()) ]; ]); let n_jobs = max 1 !n_jobs in diff --git a/tests/client_e2e/clients_e2e_lib.ml b/tests/client_e2e/clients_e2e_lib.ml index 3206bfe9..3466e9d1 100644 --- a/tests/client_e2e/clients_e2e_lib.ml +++ b/tests/client_e2e/clients_e2e_lib.ml @@ -79,10 +79,12 @@ let get_metric_values name signals = Option.some @@ match m.data with - | Sum { data_points; is_monotonic = true; _ } -> + | Some (Sum { data_points; is_monotonic = true; _ }) -> List.fold_left (fun acc (p : Proto.Metrics.number_data_point) -> - acc +. number_data_point_to_float p.value) + acc + +. CCOption.map_or ~default:0. number_data_point_to_float + p.value) 0. data_points | _ -> failwith "TODO: Support for getting other metrics") diff --git a/tests/core/dune b/tests/core/dune index 8a702b10..77d2b02f 100644 --- a/tests/core/dune +++ b/tests/core/dune @@ -1,4 +1,4 @@ (tests - (names test_trace_context) + (names test_trace_context t_size) (package opentelemetry) - (libraries opentelemetry)) + (libraries opentelemetry opentelemetry.client)) diff --git a/tests/core/t_size.expected b/tests/core/t_size.expected new file mode 100644 index 00000000..a6f0adc3 --- /dev/null +++ b/tests/core/t_size.expected @@ -0,0 +1,352 @@ +metrics size: 149B +res1: { resource = None; + scope_metrics = + [{ scope = None; + metrics = + [{ name = "sum.foo"; + description = "" (* absent *); + unit_ = "" (* absent *); + data = + Some( + Sum( + { data_points = + [{ attributes = []; + start_time_unix_nano = 42; + time_unix_nano = 45; + value = Some(As_int(10)); + exemplars = []; + flags = 0 (* absent *); + }; + { attributes = []; + start_time_unix_nano = 52; + time_unix_nano = 55; + value = Some(As_int(20)); + exemplars = []; + flags = 0 (* absent *); + } + ]; + aggregation_temporality = + Aggregation_temporality_cumulative; + is_monotonic = false (* absent *); + })); + metadata = []; + }; + { name = "gauge.bar"; + description = "" (* absent *); + unit_ = "" (* absent *); + data = + Some( + Gauge( + { data_points = + [{ attributes = []; + start_time_unix_nano = 42; + time_unix_nano = 45; + value = Some(As_double(10.)); + exemplars = []; + flags = 0 (* absent *); + }; + { attributes = []; + start_time_unix_nano = 52; + time_unix_nano = 55; + value = Some(As_double(20.)); + exemplars = []; + flags = 0 (* absent *); + } + ]; + })); + metadata = []; + } + ]; + schema_url = "" (* absent *); + } + ]; + schema_url = "" (* absent *); + } +res1: { resource = None; + scope_metrics = + [{ scope = None; + metrics = + [{ name = "sum.foo"; + description = "" (* absent *); + unit_ = "" (* absent *); + data = + Some( + Sum( + { data_points = + [{ attributes = []; + start_time_unix_nano = 42; + time_unix_nano = 45; + value = Some(As_int(10)); + exemplars = []; + flags = 0 (* absent *); + }; + { attributes = []; + start_time_unix_nano = 52; + time_unix_nano = 55; + value = Some(As_int(20)); + exemplars = []; + flags = 0 (* absent *); + } + ]; + aggregation_temporality = + Aggregation_temporality_cumulative; + is_monotonic = false (* absent *); + })); + metadata = []; + }; + { name = "gauge.bar"; + description = "" (* absent *); + unit_ = "" (* absent *); + data = + Some( + Gauge( + { data_points = + [{ attributes = []; + start_time_unix_nano = 42; + time_unix_nano = 45; + value = Some(As_double(10.)); + exemplars = []; + flags = 0 (* absent *); + }; + { attributes = []; + start_time_unix_nano = 52; + time_unix_nano = 55; + value = Some(As_double(20.)); + exemplars = []; + flags = 0 (* absent *); + } + ]; + })); + metadata = []; + } + ]; + schema_url = "" (* absent *); + } + ]; + schema_url = "" (* absent *); + } +trace size: 371B +trace1: { resource = None; + scope_spans = + [{ scope = None; + spans = + [{ trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = (* absent *); + flags = 0 (* absent *); + name = "sp1"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 10; + end_time_unix_nano = 15; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp2"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 20; + end_time_unix_nano = 25; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp3"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 30; + end_time_unix_nano = 35; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp4"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 40; + end_time_unix_nano = 45; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp5"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 50; + end_time_unix_nano = 55; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp6"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 60; + end_time_unix_nano = 65; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + } + ]; + schema_url = "" (* absent *); + } + ]; + schema_url = "" (* absent *); + } +trace2: { resource = None; + scope_spans = + [{ scope = None; + spans = + [{ trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = (* absent *); + flags = 0 (* absent *); + name = "sp1"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 10; + end_time_unix_nano = 15; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp2"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 20; + end_time_unix_nano = 25; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp3"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 30; + end_time_unix_nano = 35; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp4"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 40; + end_time_unix_nano = 45; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp5"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 50; + end_time_unix_nano = 55; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + }; + { trace_id = ; + span_id = ; + trace_state = "" (* absent *); + parent_span_id = ; + flags = 0 (* absent *); + name = "sp6"; + kind = Span_kind_unspecified (* absent *); + start_time_unix_nano = 60; + end_time_unix_nano = 65; + attributes = []; + dropped_attributes_count = 0 (* absent *); + events = []; + dropped_events_count = 0 (* absent *); + links = []; + dropped_links_count = 0 (* absent *); + status = None; + } + ]; + schema_url = "" (* absent *); + } + ]; + schema_url = "" (* absent *); + } diff --git a/tests/core/t_size.ml b/tests/core/t_size.ml new file mode 100644 index 00000000..cfa024b5 --- /dev/null +++ b/tests/core/t_size.ml @@ -0,0 +1,87 @@ +(* test the size of serialized data *) + +open Opentelemetry + +let res1 : Proto.Metrics.resource_metrics = + Proto.Metrics.make_resource_metrics + ~scope_metrics: + [ + Proto.Metrics.make_scope_metrics + ~metrics: + [ + Metrics.sum ~name:"sum.foo" + [ + Metrics.int ~start_time_unix_nano:42L ~now:45L 10; + Metrics.int ~start_time_unix_nano:52L ~now:55L 20; + ]; + Metrics.gauge ~name:"gauge.bar" + [ + Metrics.float ~start_time_unix_nano:42L ~now:45L 10.; + Metrics.float ~start_time_unix_nano:52L ~now:55L 20.; + ]; + ] + (); + ] + () + +let str = + let enc = Pbrt.Encoder.create () in + Proto.Metrics.encode_pb_resource_metrics res1 enc; + Pbrt.Encoder.to_string enc + +let () = Printf.printf "metrics size: %dB\n" (String.length str) + +let () = + let dec = Pbrt.Decoder.of_string str in + let res2 = Proto.Metrics.decode_pb_resource_metrics dec in + Format.printf "res1: %a@." Proto.Metrics.pp_resource_metrics res1; + Format.printf "res1: %a@." Proto.Metrics.pp_resource_metrics res2; + () + +(* traces *) + +let trace1 : Proto.Trace.resource_spans = + let span_id = Span_id.dummy |> Span_id.to_bytes in + let trace_id = Trace_id.dummy |> Trace_id.to_bytes in + Proto.Trace.make_resource_spans + ~scope_spans: + [ + Proto.Trace.make_scope_spans + ~spans: + [ + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp1" + ~start_time_unix_nano:10L ~end_time_unix_nano:15L ~events:[] + ~links:[] ~attributes:[] (); + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp2" + ~start_time_unix_nano:20L ~end_time_unix_nano:25L ~events:[] + ~links:[] ~attributes:[] ~parent_span_id:span_id (); + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp3" + ~start_time_unix_nano:30L ~end_time_unix_nano:35L ~events:[] + ~links:[] ~attributes:[] ~parent_span_id:span_id (); + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp4" + ~start_time_unix_nano:40L ~end_time_unix_nano:45L ~events:[] + ~links:[] ~attributes:[] ~parent_span_id:span_id (); + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp5" + ~start_time_unix_nano:50L ~end_time_unix_nano:55L ~events:[] + ~links:[] ~attributes:[] ~parent_span_id:span_id (); + Proto.Trace.make_span ~trace_id ~span_id ~name:"sp6" + ~start_time_unix_nano:60L ~end_time_unix_nano:65L ~events:[] + ~links:[] ~attributes:[] ~parent_span_id:span_id (); + ] + (); + ] + () + +let str = + let enc = Pbrt.Encoder.create () in + Proto.Trace.encode_pb_resource_spans trace1 enc; + Pbrt.Encoder.to_string enc + +let () = Printf.printf "trace size: %dB\n" (String.length str) + +let () = + let dec = Pbrt.Decoder.of_string str in + let trace2 = Proto.Trace.decode_pb_resource_spans dec in + Format.printf "trace1: %a@." Proto.Trace.pp_resource_spans trace1; + Format.printf "trace2: %a@." Proto.Trace.pp_resource_spans trace2; + () diff --git a/tests/logs/test_logs_e2e.expected b/tests/logs/test_logs_e2e.expected index e408710e..7fc78213 100644 --- a/tests/logs/test_logs_e2e.expected +++ b/tests/logs/test_logs_e2e.expected @@ -8,7 +8,8 @@ { key = "src"; value = Some(String_value("application")); }; { key = "my_reporter_attr"; value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -16,7 +17,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -25,16 +26,17 @@ severity_text = "debug"; body = Some(String_value("emit_logs: starting")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -46,7 +48,8 @@ { key = "src"; value = Some(String_value("application")); }; { key = "my_reporter_attr"; value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -54,7 +57,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -63,16 +66,17 @@ severity_text = "info"; body = Some(String_value("emit_logs: info log")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -86,7 +90,8 @@ { key = "src"; value = Some(String_value("application")); }; { key = "my_reporter_attr"; value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -94,7 +99,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -103,16 +108,17 @@ severity_text = "warning"; body = Some(String_value("emit_logs: warn log")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -128,7 +134,8 @@ value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -136,7 +143,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -145,16 +152,17 @@ severity_text = "error"; body = Some(String_value("emit_logs: error log")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -170,7 +178,8 @@ value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -178,7 +187,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -187,16 +196,17 @@ severity_text = "app"; body = Some(String_value("emit_logs: app log")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -221,7 +231,8 @@ value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -229,7 +240,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -241,16 +252,17 @@ String_value( "emit_logs: this log is emitted with varied tags from a span")); attributes = []; - dropped_attributes_count = 0; - flags = 0; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); trace_id = ; span_id = ; + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -275,7 +287,8 @@ value = Some(String_value("foo")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -283,7 +296,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -295,16 +308,17 @@ String_value( "emit_logs: this log will be emitted with varied tags")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } { resource = Some( @@ -322,7 +336,8 @@ value = Some(String_value("bar")); } ]; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); + entity_refs = []; }); scope_logs = [{ scope = @@ -330,7 +345,7 @@ { name = "ocaml-otel"; version = "%%VERSION_NUM%%"; attributes = []; - dropped_attributes_count = 0; + dropped_attributes_count = 0 (* absent *); }); log_records = [{ time_unix_nano = 0; @@ -342,14 +357,15 @@ String_value( "emit_logs: this log will be emitted from otel and fmt reporter")); attributes = []; - dropped_attributes_count = 0; - flags = 0; - trace_id = ; - span_id = ; + dropped_attributes_count = 0 (* absent *); + flags = 0 (* absent *); + trace_id = (* absent *); + span_id = (* absent *); + event_name = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } ]; - schema_url = ""; + schema_url = "" (* absent *); } diff --git a/tests/logs/test_logs_e2e.ml b/tests/logs/test_logs_e2e.ml index 51af2968..156c7f75 100644 --- a/tests/logs/test_logs_e2e.ml +++ b/tests/logs/test_logs_e2e.ml @@ -23,17 +23,20 @@ let tests (signal_batches : Client.Signal.t list) = let masked_log_records = List.map (fun (lr : L.log_record) -> - { - lr with - time_unix_nano = 0L; - observed_time_unix_nano = 0L; - }) + let lr = L.copy_log_record lr in + L.log_record_set_time_unix_nano lr 0L; + L.log_record_set_observed_time_unix_nano lr 0L; + lr) sl.log_records in - { sl with log_records = masked_log_records }) + let sl = L.copy_scope_logs sl in + L.scope_logs_set_log_records sl masked_log_records; + sl) l.scope_logs in - { l with scope_logs = masked_scope_logs }) + let l = L.copy_resource_logs l in + L.resource_logs_set_scope_logs l masked_scope_logs; + l) |> List.iter (Format.printf "%a\n" L.pp_resource_logs) | _ -> ()) signal_batches diff --git a/vendor/opentelemetry-proto b/vendor/opentelemetry-proto index c4dfbc51..c0a98a18 160000 --- a/vendor/opentelemetry-proto +++ b/vendor/opentelemetry-proto @@ -1 +1 @@ -Subproject commit c4dfbc51f3cd4089778555a2ac5d9bc093ed2956 +Subproject commit c0a98a1847d3124ac5f9ecd02d0e2d2732bbb590