mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
fix: critical bugs found in code review
Bug #1: Fix worker count logic in generic_consumer - Was: min 2 (max 500 n_workers) - always created 2 workers - Now: max 2 (min 500 n_workers) - properly clamps between 2-500 - Impact: Worker configuration was completely ignored Bug #2: Handle missing dot in __FUNCTION__ name - Added exception handling for String.rindex in trace span creation - Prevents crash when tracing top-level or non-module functions - Uses option type for module_path when no dot is present - Scoped try/catch to only parsing logic
This commit is contained in:
parent
c29ac75a82
commit
1ebd474423
3 changed files with 27 additions and 12 deletions
|
|
@ -194,7 +194,7 @@ end = struct
|
|||
in
|
||||
|
||||
(* start workers *)
|
||||
let n_workers = min 2 (max 500 self.config.n_workers) in
|
||||
let n_workers = max 2 (min 500 self.config.n_workers) in
|
||||
|
||||
ignore (Atomic.fetch_and_add self.n_workers n_workers : int);
|
||||
for _i = 1 to n_workers do
|
||||
|
|
|
|||
|
|
@ -71,17 +71,27 @@ open struct
|
|||
(* add more data if [__FUNCTION__] is present *)
|
||||
(match __FUNCTION__ with
|
||||
| Some __FUNCTION__ when OTEL.Span.is_not_dummy otel_sp ->
|
||||
let function_name, module_path =
|
||||
try
|
||||
let last_dot = String.rindex __FUNCTION__ '.' in
|
||||
let module_path = String.sub __FUNCTION__ 0 last_dot in
|
||||
let function_name =
|
||||
String.sub __FUNCTION__ (last_dot + 1)
|
||||
(String.length __FUNCTION__ - last_dot - 1)
|
||||
in
|
||||
OTEL.Span.add_attrs otel_sp
|
||||
[
|
||||
"code.function", `String function_name;
|
||||
"code.namespace", `String module_path;
|
||||
]
|
||||
function_name, Some module_path
|
||||
with Not_found ->
|
||||
(* __FUNCTION__ has no dot, use it as-is *)
|
||||
__FUNCTION__, None
|
||||
in
|
||||
let attrs =
|
||||
("code.function", `String function_name)
|
||||
::
|
||||
(match module_path with
|
||||
| Some module_path -> [ "code.namespace", `String module_path ]
|
||||
| None -> [])
|
||||
in
|
||||
OTEL.Span.add_attrs otel_sp attrs
|
||||
| _ -> ());
|
||||
|
||||
Span_otel otel_sp
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
(tests
|
||||
(names test_implicit_scope_sync)
|
||||
(package opentelemetry-client-cohttp-lwt)
|
||||
(libraries threads alcotest opentelemetry unix opentelemetry-client-cohttp-lwt))
|
||||
(libraries
|
||||
threads
|
||||
alcotest
|
||||
opentelemetry
|
||||
unix
|
||||
opentelemetry-client-cohttp-lwt))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue