fix some tests

This commit is contained in:
Simon Cruanes 2025-12-17 14:00:39 -05:00
parent dc99897e87
commit 1853fa7585
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
4 changed files with 142 additions and 338 deletions

View file

@ -1,4 +1,4 @@
(tests (tests
(names test_urls) (names test_urls)
(package opentelemetry-client-cohttp-lwt) (package opentelemetry-client-cohttp-lwt)
(libraries opentelemetry opentelemetry-client-cohttp-lwt)) (libraries opentelemetry opentelemetry-client-cohttp-lwt unix))

View file

@ -1,4 +1,4 @@
(tests (tests
(names test_implicit_scope_sync) (names test_implicit_scope_sync)
(package opentelemetry-client-cohttp-lwt) (package opentelemetry-client-cohttp-lwt)
(libraries threads alcotest opentelemetry opentelemetry-client-cohttp-lwt)) (libraries threads alcotest opentelemetry unix opentelemetry-client-cohttp-lwt))

View file

@ -5,8 +5,12 @@
value = Some(String_value("ocaml-otel.test")); value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; value = Some(String_value("emit_logs")); }; { key = "service.name"; value = Some(String_value("emit_logs")); };
{ key = "src"; value = Some(String_value("application")); }; { key = "process.runtime.version";
{ key = "my_reporter_attr"; value = Some(String_value("foo")); } value = Some(String_value("5.3.0"));
};
{ key = "process.runtime.name";
value = Some(String_value("ocaml"));
}
]; ];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
entity_refs = []; entity_refs = [];
@ -25,338 +29,134 @@
severity_number = Severity_number_debug; severity_number = Severity_number_debug;
severity_text = "debug"; severity_text = "debug";
body = Some(String_value("emit_logs: starting")); body = Some(String_value("emit_logs: starting"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *); span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; value = Some(String_value("emit_logs")); }; { time_unix_nano = 1;
{ key = "src"; value = Some(String_value("application")); }; observed_time_unix_nano = 1;
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_info2; severity_number = Severity_number_info2;
severity_text = "info"; severity_text = "info";
body = Some(String_value("emit_logs: info log")); body = Some(String_value("emit_logs: info log"));
attributes = []; attributes =
dropped_attributes_count = 0 (* absent *); [{ key = "src"; value = Some(String_value("application")); };
flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
};
{ key = "service.name";
value = Some(String_value("emit_logs"));
};
{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); } { key = "my_reporter_attr"; value = Some(String_value("foo")); }
]; ];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
entity_refs = []; flags = 0 (* absent *);
}); trace_id = <bytes len=0> (* absent *);
scope_logs = span_id = <bytes len=0> (* absent *);
[{ scope = event_name = "" (* absent *);
Some( };
{ name = "ocaml-otel"; { time_unix_nano = 2;
version = "%%VERSION_NUM%%"; observed_time_unix_nano = 2;
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_warn; severity_number = Severity_number_warn;
severity_text = "warning"; severity_text = "warning";
body = Some(String_value("emit_logs: warn log")); body = Some(String_value("emit_logs: warn log"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *); span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; { time_unix_nano = 3;
value = Some(String_value("emit_logs")); observed_time_unix_nano = 3;
};
{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr";
value = Some(String_value("foo"));
}
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_error; severity_number = Severity_number_error;
severity_text = "error"; severity_text = "error";
body = Some(String_value("emit_logs: error log")); body = Some(String_value("emit_logs: error log"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *); span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; { time_unix_nano = 4;
value = Some(String_value("emit_logs")); observed_time_unix_nano = 4;
};
{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr";
value = Some(String_value("foo"));
}
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_info; severity_number = Severity_number_info;
severity_text = "app"; severity_text = "app";
body = Some(String_value("emit_logs: app log")); body = Some(String_value("emit_logs: app log"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *); span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; { time_unix_nano = 5;
value = Some(String_value("emit_logs")); observed_time_unix_nano = 5;
};
{ key = "src";
value = Some(String_value("application"));
};
{ key = "string_list_attr";
value = Some(String_value(""));
};
{ key = "bool_attr"; value = Some(String_value("")); };
{ key = "float_attr"; value = Some(String_value("")); };
{ key = "int_attr"; value = Some(String_value("")); };
{ key = "string_attr"; value = Some(String_value("")); };
{ key = "my_reporter_attr";
value = Some(String_value("foo"));
}
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_info2; severity_number = Severity_number_info2;
severity_text = "info"; severity_text = "info";
body = body =
Some( Some(
String_value( String_value(
"emit_logs: this log is emitted with varied tags from a span")); "emit_logs: this log is emitted with varied tags from a span"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "string_list_attr"; value = Some(String_value("")); };
{ key = "bool_attr"; value = Some(String_value("")); };
{ key = "float_attr"; value = Some(String_value("")); };
{ key = "int_attr"; value = Some(String_value("")); };
{ key = "string_attr"; value = Some(String_value("")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=16>; trace_id = <bytes len=16>;
span_id = <bytes len=8>; span_id = <bytes len=8>;
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; { time_unix_nano = 6;
value = Some(String_value("emit_logs")); observed_time_unix_nano = 6;
};
{ key = "src";
value = Some(String_value("application"));
};
{ key = "string_list_attr";
value = Some(String_value(""));
};
{ key = "bool_attr"; value = Some(String_value("")); };
{ key = "float_attr"; value = Some(String_value("")); };
{ key = "int_attr"; value = Some(String_value("")); };
{ key = "string_attr"; value = Some(String_value("")); };
{ key = "my_reporter_attr";
value = Some(String_value("foo"));
}
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_info2; severity_number = Severity_number_info2;
severity_text = "info"; severity_text = "info";
body = body =
Some( Some(
String_value( String_value(
"emit_logs: this log will be emitted with varied tags")); "emit_logs: this log will be emitted with varied tags"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "string_list_attr"; value = Some(String_value("")); };
{ key = "bool_attr"; value = Some(String_value("")); };
{ key = "float_attr"; value = Some(String_value("")); };
{ key = "int_attr"; value = Some(String_value("")); };
{ key = "string_attr"; value = Some(String_value("")); };
{ key = "my_reporter_attr"; value = Some(String_value("foo")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);
span_id = <bytes len=0> (* absent *); span_id = <bytes len=0> (* absent *);
event_name = "" (* absent *); event_name = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
];
schema_url = "" (* absent *);
}
{ resource =
Some(
{ attributes =
[{ key = "service.namespace";
value = Some(String_value("ocaml-otel.test"));
}; };
{ key = "service.name"; { time_unix_nano = 7;
value = Some(String_value("emit_logs_fmt")); observed_time_unix_nano = 7;
};
{ key = "src";
value = Some(String_value("application"));
};
{ key = "my_fmt_attr";
value = Some(String_value("bar"));
}
];
dropped_attributes_count = 0 (* absent *);
entity_refs = [];
});
scope_logs =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0 (* absent *);
});
log_records =
[{ time_unix_nano = 0;
observed_time_unix_nano = 0;
severity_number = Severity_number_info2; severity_number = Severity_number_info2;
severity_text = "info"; severity_text = "info";
body = body =
Some( Some(
String_value( String_value(
"emit_logs: this log will be emitted from otel and fmt reporter")); "emit_logs: this log will be emitted from otel and fmt reporter"));
attributes = []; attributes =
[{ key = "src"; value = Some(String_value("application")); };
{ key = "my_fmt_attr"; value = Some(String_value("bar")); }
];
dropped_attributes_count = 0 (* absent *); dropped_attributes_count = 0 (* absent *);
flags = 0 (* absent *); flags = 0 (* absent *);
trace_id = <bytes len=0> (* absent *); trace_id = <bytes len=0> (* absent *);

View file

@ -11,6 +11,7 @@ let cmd = [ "emit_logs_cohttp"; "--url"; url ]
let tests (signal_batches : Client.Signal.t list) = let tests (signal_batches : Client.Signal.t list) =
ignore signal_batches; ignore signal_batches;
let cur_time = ref 0 in
List.iter List.iter
(fun (signal_batch : Client.Signal.t) -> (fun (signal_batch : Client.Signal.t) ->
match signal_batch with match signal_batch with
@ -24,8 +25,11 @@ let tests (signal_batches : Client.Signal.t list) =
List.map List.map
(fun (lr : L.log_record) -> (fun (lr : L.log_record) ->
let lr = L.copy_log_record lr in let lr = L.copy_log_record lr in
L.log_record_set_time_unix_nano lr 0L; let pseudo_time = Int64.of_int !cur_time in
L.log_record_set_observed_time_unix_nano lr 0L; incr cur_time;
L.log_record_set_time_unix_nano lr pseudo_time;
L.log_record_set_observed_time_unix_nano lr
pseudo_time;
lr) lr)
sl.log_records sl.log_records
in in