The use of a non-threadsafe mutable reference for the metrics callbacks
was resulting in a race condition that would sometimes produce
non-deterministic results in the integration tests.
This has not affected the lwt-based collector, because of the single
threaded concurrency Lwt enforces, but it began to show up in the WIP
Eio rewrite, for which I am testing on cross-domain programs.
I suspect this may have also bee affecting the ocurl collector, but we
don't have integration test running on that yet.
Since we need to traverse the elements added to count up the new size,
we can use that pass to add the elements onto our FIFO queue, and then
drain the queue in one last pass to reverse. IIUC, this should give us
liner complexity of the batch retrieval.
This allows clien implementors to micromanage the state of the protobuf
`encoder` if they want, or to just let the library handle allocation and
garbage collection of encoder states when that level of resource
managment is not required.
The `tick_common` function is only used once.
Removing the indirection also lets us see that we were calling
`sample_gc_metrics_if_needed` twice in a row on each tick.
Matches the convention in /src/trace/dune and prevents dependency on
the library from polluting the global namespace of a component with the
generic `Client` module.
As discussed in https://github.com/ocaml/ocaml/issues/14078,
alerts (with deprecation alerts as a special case) are not currently
supported as item-attributes on let-bindings. This usage produces
`misplaced-attribute` warnings, such as
```
Warning 53 [misplaced-attribute]: the "deprecated" attribute cannot appear in this context
File "src/core/opentelemetry.ml", line 1229, characters 37-47:
1229 | let add_event = Scope.add_event [@@deprecated "use Scope.add_event"]
^^^^^^^^^^
Warning 53 [misplaced-attribute]: the "deprecated" attribute cannot appear in this context
File "src/core/opentelemetry.ml", line 1231, characters 37-47:
1231 | let add_attrs = Scope.add_attrs [@@deprecated "use Scope.add_attrs"]
^^^^^^^^^^
Warning 53 [misplaced-attribute]: the "deprecated" attribute cannot appear in this context
```
Fortunately, we can still add deprecation alerts to these value by
moving the alert to the pattern, as done here.
As of OCaml 5.3, the OCaml runtime doesn't support signals on
Windows. Trying to block them with Thread.sigmask will raise:
Thread 5 killed on uncaught exception Invalid_argument("Thread.sigmask not implemented")
Raised by primitive operation at Opentelemetry_client_ocurl.start_bg_thread.run in file "src/client-ocurl/opentelemetry_client_ocurl.ml", line 106, characters 12-49