Skip to content

Commit 04c04e4

Browse files
committed
fixes
1 parent 3e1c673 commit 04c04e4

File tree

3 files changed

+56
-60
lines changed

3 files changed

+56
-60
lines changed

src/client/signal.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,22 @@ module Encode = struct
5454
resource_logs
5555
|> resource_to_string ~encoder
5656
~ctor:(fun r ->
57-
Logs_service.default_export_logs_service_request ~resource_logs:r ())
57+
Logs_service.make_export_logs_service_request ~resource_logs:r ())
5858
~enc:Logs_service.encode_pb_export_logs_service_request
5959

6060
let metrics ?encoder resource_metrics =
6161
resource_metrics
6262
|> resource_to_string ~encoder
6363
~ctor:(fun r ->
64-
Metrics_service.default_export_metrics_service_request
64+
Metrics_service.make_export_metrics_service_request
6565
~resource_metrics:r ())
6666
~enc:Metrics_service.encode_pb_export_metrics_service_request
6767

6868
let traces ?encoder resource_spans =
6969
resource_spans
7070
|> resource_to_string ~encoder
7171
~ctor:(fun r ->
72-
Trace_service.default_export_trace_service_request ~resource_spans:r
73-
())
72+
Trace_service.make_export_trace_service_request ~resource_spans:r ())
7473
~enc:Trace_service.encode_pb_export_trace_service_request
7574
end
7675

src/core/opentelemetry.ml

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ open struct
669669
let _conv_key_value (k, v) =
670670
let open Proto.Common in
671671
let value = _conv_value v in
672-
default_key_value ~key:k ~value ()
672+
make_key_value ~key:k ?value ()
673673
end
674674

675675
(** {2 Global settings} *)
@@ -691,17 +691,17 @@ module Globals = struct
691691
@since NEXT_RELEASE *)
692692
let service_version = ref None
693693

694-
let instrumentation_library =
695-
default_instrumentation_scope ~version:"%%VERSION_NUM%%" ~name:"ocaml-otel"
696-
()
694+
let instrumentation_library : instrumentation_scope =
695+
make_instrumentation_scope ~version:"%%VERSION_NUM%%" ~name:"ocaml-otel"
696+
~attributes:[] ()
697697

698698
(** Global attributes, initially set via OTEL_RESOURCE_ATTRIBUTES and
699699
modifiable by the user code. They will be attached to each outgoing
700700
metrics/traces. *)
701701
let global_attributes : key_value list ref =
702702
let parse_pair s =
703703
match String.split_on_char '=' s with
704-
| [ a; b ] -> default_key_value ~key:a ~value:(Some (String_value b)) ()
704+
| [ a; b ] -> make_key_value ~key:a ~value:(String_value b) ()
705705
| _ -> failwith (Printf.sprintf "invalid attribute: %S" s)
706706
in
707707
ref
@@ -730,32 +730,32 @@ module Globals = struct
730730
let mk_attributes ?(service_name = !service_name) ?(attrs = []) () : _ list =
731731
let l = List.map _conv_key_value attrs in
732732
let l =
733-
default_key_value ~key:Conventions.Attributes.Service.name
734-
~value:(Some (String_value service_name)) ()
733+
make_key_value ~key:Conventions.Attributes.Service.name
734+
~value:(String_value service_name) ()
735735
:: l
736736
in
737737
let l =
738738
match !service_instance_id with
739739
| None -> l
740740
| Some v ->
741-
default_key_value ~key:Conventions.Attributes.Service.instance_id
742-
~value:(Some (String_value v)) ()
741+
make_key_value ~key:Conventions.Attributes.Service.instance_id
742+
~value:(String_value v) ()
743743
:: l
744744
in
745745
let l =
746746
match !service_namespace with
747747
| None -> l
748748
| Some v ->
749-
default_key_value ~key:Conventions.Attributes.Service.namespace
750-
~value:(Some (String_value v)) ()
749+
make_key_value ~key:Conventions.Attributes.Service.namespace
750+
~value:(String_value v) ()
751751
:: l
752752
in
753753
let l =
754754
match !service_version with
755755
| None -> l
756756
| Some v ->
757-
default_key_value ~key:Conventions.Attributes.Service.version
758-
~value:(Some (String_value v)) ()
757+
make_key_value ~key:Conventions.Attributes.Service.version
758+
~value:(String_value v) ()
759759
:: l
760760
in
761761
l |> merge_global_attributes_
@@ -782,7 +782,7 @@ end = struct
782782
let make ?(time_unix_nano = Timestamp_ns.now_unix_ns ()) ?(attrs = [])
783783
(name : string) : t =
784784
let attrs = List.map _conv_key_value attrs in
785-
default_span_event ~time_unix_nano ~name ~attributes:attrs ()
785+
make_span_event ~time_unix_nano ~name ~attributes:attrs ()
786786
end
787787

788788
(** Span Link
@@ -822,7 +822,7 @@ end = struct
822822
let dropped_attributes_count =
823823
Option.map Int32.of_int dropped_attributes_count
824824
in
825-
default_span_link
825+
make_span_link
826826
~trace_id:(Trace_id.to_bytes trace_id)
827827
~span_id:(Span_id.to_bytes span_id) ?trace_state ~attributes
828828
?dropped_attributes_count ()
@@ -836,9 +836,10 @@ end
836836
module Span_status : sig
837837
open Proto.Trace
838838

839-
type t = status = {
840-
message: string;
841-
code: status_status_code;
839+
type t = status = private {
840+
mutable _presence: Pbrt.Bitfield.t;
841+
mutable message: string;
842+
mutable code: status_status_code;
842843
}
843844

844845
type code = status_status_code =
@@ -850,17 +851,18 @@ module Span_status : sig
850851
end = struct
851852
open Proto.Trace
852853

853-
type t = status = {
854-
message: string;
855-
code: status_status_code;
854+
type t = status = private {
855+
mutable _presence: Pbrt.Bitfield.t;
856+
mutable message: string;
857+
mutable code: status_status_code;
856858
}
857859

858860
type code = status_status_code =
859861
| Status_code_unset
860862
| Status_code_ok
861863
| Status_code_error
862864

863-
let make ~message ~code = { message; code }
865+
let[@inline] make ~message ~code : t = make_status ~message ~code ()
864866
end
865867

866868
(** @since 0.11 *)
@@ -1195,8 +1197,8 @@ end = struct
11951197
let parent_span_id = Option.map Span_id.to_bytes parent in
11961198
let attributes = List.map _conv_key_value attrs in
11971199
let span =
1198-
default_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id)
1199-
~attributes ~events ?trace_state ~status ~kind ~name ~links
1200+
make_span ~trace_id ?parent_span_id ~span_id:(Span_id.to_bytes id)
1201+
~attributes ~events ?trace_state ?status ~kind ~name ~links
12001202
~start_time_unix_nano:start_time ~end_time_unix_nano:end_time ()
12011203
in
12021204
span, id
@@ -1212,14 +1214,13 @@ module Trace = struct
12121214

12131215
type span = Span.t
12141216

1215-
let make_resource_spans ?service_name ?attrs spans =
1217+
let make_resource_spans ?service_name ?attrs spans : resource_spans =
12161218
let ils =
1217-
default_scope_spans ~scope:(Some Globals.instrumentation_library) ~spans
1218-
()
1219+
make_scope_spans ~scope:Globals.instrumentation_library ~spans ()
12191220
in
12201221
let attributes = Globals.mk_attributes ?service_name ?attrs () in
1221-
let resource = Proto.Resource.default_resource ~attributes () in
1222-
default_resource_spans ~resource:(Some resource) ~scope_spans:[ ils ] ()
1222+
let resource = Proto.Resource.make_resource ~attributes () in
1223+
make_resource_spans ~resource ~scope_spans:[ ils ] ()
12231224

12241225
(** Sync emitter.
12251226
@@ -1286,7 +1287,7 @@ module Trace = struct
12861287
| Error (e, bt) ->
12871288
Scope.record_exception scope e bt;
12881289
Some
1289-
(default_status ~code:Status_code_error
1290+
(make_status ~code:Status_code_error
12901291
~message:(Printexc.to_string e) ()))
12911292
in
12921293
let span, _ =
@@ -1367,23 +1368,22 @@ module Metrics = struct
13671368
?(now = Timestamp_ns.now_unix_ns ()) ?(attrs = []) (d : float) :
13681369
number_data_point =
13691370
let attributes = attrs |> List.map _conv_key_value in
1370-
default_number_data_point ~start_time_unix_nano ~time_unix_nano:now
1371-
~attributes ~value:(As_double d) ()
1371+
make_number_data_point ~start_time_unix_nano ~time_unix_nano:now ~attributes
1372+
~value:(As_double d) ~exemplars:[] ()
13721373

13731374
(** Number data point, as an int *)
13741375
let int ?(start_time_unix_nano = _program_start)
13751376
?(now = Timestamp_ns.now_unix_ns ()) ?(attrs = []) (i : int) :
13761377
number_data_point =
13771378
let attributes = attrs |> List.map _conv_key_value in
1378-
default_number_data_point ~start_time_unix_nano ~time_unix_nano:now
1379-
~attributes
1379+
make_number_data_point ~start_time_unix_nano ~time_unix_nano:now ~attributes
13801380
~value:(As_int (Int64.of_int i))
1381-
()
1381+
~exemplars:[] ()
13821382

13831383
(** Aggregation of a scalar metric, always with the current value *)
13841384
let gauge ~name ?description ?unit_ (l : number_data_point list) : t =
1385-
let data = Gauge (default_gauge ~data_points:l ()) in
1386-
default_metric ~name ?description ?unit_ ~data ()
1385+
let data = Gauge (make_gauge ~data_points:l ()) in
1386+
make_metric ~name ?description ?unit_ ~data ()
13871387

13881388
type aggregation_temporality = Metrics.aggregation_temporality =
13891389
| Aggregation_temporality_unspecified
@@ -1395,9 +1395,9 @@ module Metrics = struct
13951395
?(aggregation_temporality = Aggregation_temporality_cumulative)
13961396
?is_monotonic (l : number_data_point list) : t =
13971397
let data =
1398-
Sum (default_sum ~data_points:l ?is_monotonic ~aggregation_temporality ())
1398+
Sum (make_sum ~data_points:l ?is_monotonic ~aggregation_temporality ())
13991399
in
1400-
default_metric ~name ?description ?unit_ ~data ()
1400+
make_metric ~name ?description ?unit_ ~data ()
14011401

14021402
(** Histogram data
14031403
@param count number of values in population (non negative)
@@ -1412,15 +1412,15 @@ module Metrics = struct
14121412
?(explicit_bounds = []) ?sum ~bucket_counts ~count () :
14131413
histogram_data_point =
14141414
let attributes = attrs |> List.map _conv_key_value in
1415-
default_histogram_data_point ~start_time_unix_nano ~time_unix_nano:now
1415+
make_histogram_data_point ~start_time_unix_nano ~time_unix_nano:now
14161416
~attributes ~exemplars ~bucket_counts ~explicit_bounds ~count ?sum ()
14171417

14181418
let histogram ~name ?description ?unit_ ?aggregation_temporality
14191419
(l : histogram_data_point list) : t =
14201420
let data =
1421-
Histogram (default_histogram ~data_points:l ?aggregation_temporality ())
1421+
Histogram (make_histogram ~data_points:l ?aggregation_temporality ())
14221422
in
1423-
default_metric ~name ?description ?unit_ ~data ()
1423+
make_metric ~name ?description ?unit_ ~data ()
14241424

14251425
(* TODO: exponential history *)
14261426
(* TODO: summary *)
@@ -1430,12 +1430,11 @@ module Metrics = struct
14301430
let make_resource_metrics ?service_name ?attrs (l : t list) : resource_metrics
14311431
=
14321432
let lm =
1433-
default_scope_metrics ~scope:(Some Globals.instrumentation_library)
1434-
~metrics:l ()
1433+
make_scope_metrics ~scope:Globals.instrumentation_library ~metrics:l ()
14351434
in
14361435
let attributes = Globals.mk_attributes ?service_name ?attrs () in
1437-
let resource = Proto.Resource.default_resource ~attributes () in
1438-
default_resource_metrics ~scope_metrics:[ lm ] ~resource:(Some resource) ()
1436+
let resource = Proto.Resource.make_resource ~attributes () in
1437+
make_resource_metrics ~scope_metrics:[ lm ] ~resource ()
14391438

14401439
(** Emit some metrics to the collector (sync). This blocks until the backend
14411440
has pushed the metrics into some internal queue, or discarded them.
@@ -1539,9 +1538,9 @@ module Logs = struct
15391538
let trace_id = Option.map Trace_id.to_bytes trace_id in
15401539
let span_id = Option.map Span_id.to_bytes span_id in
15411540
let body = _conv_value body in
1542-
default_log_record ~time_unix_nano ~observed_time_unix_nano
1541+
make_log_record ~time_unix_nano ~observed_time_unix_nano ~attributes:[]
15431542
?severity_number:severity ?severity_text:log_level ?flags ?trace_id
1544-
?span_id ~body ()
1543+
?span_id ?body ()
15451544

15461545
(** Make a log entry whose body is a string *)
15471546
let make_str ?time ?observed_time_unix_nano ?severity ?log_level ?flags
@@ -1565,14 +1564,11 @@ module Logs = struct
15651564
cause deadlocks. *)
15661565
let emit ?service_name ?attrs (l : t list) : unit =
15671566
let attributes = Globals.mk_attributes ?service_name ?attrs () in
1568-
let resource = Proto.Resource.default_resource ~attributes () in
1567+
let resource = Proto.Resource.make_resource ~attributes () in
15691568
let ll =
1570-
default_scope_logs ~scope:(Some Globals.instrumentation_library)
1571-
~log_records:l ()
1572-
in
1573-
let rl =
1574-
default_resource_logs ~resource:(Some resource) ~scope_logs:[ ll ] ()
1569+
make_scope_logs ~scope:Globals.instrumentation_library ~log_records:l ()
15751570
in
1571+
let rl = make_resource_logs ~resource ~scope_logs:[ ll ] () in
15761572
Collector.send_logs [ rl ] ~ret:ignore
15771573
end
15781574

src/trace/opentelemetry_trace.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ module Internal = struct
193193

194194
let status : Span_status.t =
195195
match List.assoc_opt Well_known.status_error_key attrs with
196-
| Some (`String message) -> { message; code = Status_code_error }
197-
| _ -> { message = ""; code = Status_code_ok }
196+
| Some (`String message) ->
197+
Span_status.make ~message ~code:Status_code_error
198+
| _ -> Span_status.make ~message:"" ~code:Status_code_ok
198199
in
199200

200201
let attrs =

0 commit comments

Comments
 (0)