mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
follow more closely the official OTEL recommendations, and also try to reduce global state. - use a class type for `Exporter.t` (instead of 1st class module `backend`) - have tracer, logger, metrics_emitter as explicit objects - keep a `Main_exporter` to make migration easier, but discouraged - add stdout_exporter and debug_exporter to opentelemetry.client
37 lines
795 B
OCaml
37 lines
795 B
OCaml
(** Logs.
|
|
|
|
See
|
|
{{:https://opentelemetry.io/docs/reference/specification/overview/#log-signal}
|
|
the spec} *)
|
|
|
|
open Common_
|
|
|
|
(** A logger object *)
|
|
class type t = object
|
|
method is_enabled : Log_record.severity -> bool
|
|
|
|
method emit : Log_record.t list -> unit
|
|
end
|
|
|
|
(** Dummy logger, always disabled *)
|
|
let dummy : t =
|
|
object
|
|
method is_enabled _ = false
|
|
|
|
method emit _ = ()
|
|
end
|
|
|
|
class simple (exp : #Exporter.t) : t =
|
|
object
|
|
method is_enabled _ = true
|
|
|
|
method emit logs = if logs <> [] then exp#send_logs logs
|
|
end
|
|
|
|
let emit ?service_name:_ ?attrs:_ (l : Log_record.t list) : unit =
|
|
match Exporter.Main_exporter.get () with
|
|
| None -> ()
|
|
| Some e -> e#send_logs l
|
|
[@@deprecated "use an explicit Logger"]
|
|
|
|
let k_logger : t Context.key = Context.new_key ()
|