mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 04:17:56 -04:00
add status to spans
This commit is contained in:
parent
898b62aeb7
commit
958d79c875
1 changed files with 38 additions and 5 deletions
|
|
@ -176,6 +176,16 @@ module Span : sig
|
||||||
| Span_kind_producer
|
| Span_kind_producer
|
||||||
| Span_kind_consumer
|
| Span_kind_consumer
|
||||||
|
|
||||||
|
type nonrec status_code = status_status_code =
|
||||||
|
| Status_code_unset
|
||||||
|
| Status_code_ok
|
||||||
|
| Status_code_error
|
||||||
|
|
||||||
|
type nonrec status = status = {
|
||||||
|
message: string;
|
||||||
|
code: status_code;
|
||||||
|
}
|
||||||
|
|
||||||
val id : t -> Span_id.t
|
val id : t -> Span_id.t
|
||||||
|
|
||||||
type key_value = string * [`Int of int | `String of string | `Bool of bool | `None]
|
type key_value = string * [`Int of int | `String of string | `Bool of bool | `None]
|
||||||
|
|
@ -186,6 +196,7 @@ module Span : sig
|
||||||
?trace_state:string ->
|
?trace_state:string ->
|
||||||
?service_name:string ->
|
?service_name:string ->
|
||||||
?attrs:key_value list ->
|
?attrs:key_value list ->
|
||||||
|
?status:status ->
|
||||||
trace_id:Trace_id.t ->
|
trace_id:Trace_id.t ->
|
||||||
?parent:id ->
|
?parent:id ->
|
||||||
?links:(Trace_id.t * Span_id.t * string) list ->
|
?links:(Trace_id.t * Span_id.t * string) list ->
|
||||||
|
|
@ -203,8 +214,6 @@ end = struct
|
||||||
type t = span
|
type t = span
|
||||||
type id = Span_id.t
|
type id = Span_id.t
|
||||||
|
|
||||||
let id self = Span_id.of_bytes self.span_id
|
|
||||||
|
|
||||||
type nonrec kind = span_span_kind =
|
type nonrec kind = span_span_kind =
|
||||||
| Span_kind_unspecified
|
| Span_kind_unspecified
|
||||||
| Span_kind_internal
|
| Span_kind_internal
|
||||||
|
|
@ -215,12 +224,26 @@ end = struct
|
||||||
|
|
||||||
type key_value = string * [`Int of int | `String of string | `Bool of bool | `None]
|
type key_value = string * [`Int of int | `String of string | `Bool of bool | `None]
|
||||||
|
|
||||||
|
type nonrec status_code = status_status_code =
|
||||||
|
| Status_code_unset
|
||||||
|
| Status_code_ok
|
||||||
|
| Status_code_error
|
||||||
|
|
||||||
|
type nonrec status = status = {
|
||||||
|
message: string;
|
||||||
|
code: status_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let id self = Span_id.of_bytes self.span_id
|
||||||
|
|
||||||
let create
|
let create
|
||||||
?(kind=Span_kind_unspecified)
|
?(kind=Span_kind_unspecified)
|
||||||
?(id=Span_id.create())
|
?(id=Span_id.create())
|
||||||
?trace_state
|
?trace_state
|
||||||
?service_name
|
?service_name
|
||||||
?(attrs=[])
|
?(attrs=[])
|
||||||
|
?status
|
||||||
~trace_id ?parent ?(links=[])
|
~trace_id ?parent ?(links=[])
|
||||||
~start_time ~end_time
|
~start_time ~end_time
|
||||||
name : t * id =
|
name : t * id =
|
||||||
|
|
@ -262,7 +285,7 @@ end = struct
|
||||||
~trace_id ?parent_span_id
|
~trace_id ?parent_span_id
|
||||||
~span_id:(Span_id.to_bytes id)
|
~span_id:(Span_id.to_bytes id)
|
||||||
~attributes
|
~attributes
|
||||||
?trace_state
|
?trace_state ~status
|
||||||
~kind ~name ~links
|
~kind ~name ~links
|
||||||
~start_time_unix_nano:start_time
|
~start_time_unix_nano:start_time
|
||||||
~end_time_unix_nano:end_time
|
~end_time_unix_nano:end_time
|
||||||
|
|
@ -293,16 +316,26 @@ module Trace = struct
|
||||||
name (f:Trace_id.t * Span_id.t -> 'a) : 'a =
|
name (f:Trace_id.t * Span_id.t -> 'a) : 'a =
|
||||||
let start_time = Timestamp_ns.now_unix_ns() in
|
let start_time = Timestamp_ns.now_unix_ns() in
|
||||||
let span_id = Span_id.create() in
|
let span_id = Span_id.create() in
|
||||||
let finally() =
|
let finally ok =
|
||||||
|
let status = match ok with
|
||||||
|
| Ok () -> default_status ~code:Status_code_ok ()
|
||||||
|
| Error e -> default_status ~code:Status_code_error ~message:e () in
|
||||||
let span, _ =
|
let span, _ =
|
||||||
Span.create
|
Span.create
|
||||||
?kind ~trace_id ?parent ?links ~id:span_id
|
?kind ~trace_id ?parent ?links ~id:span_id
|
||||||
?trace_state ?service_name ?attrs
|
?trace_state ?service_name ?attrs
|
||||||
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
~start_time ~end_time:(Timestamp_ns.now_unix_ns())
|
||||||
|
~status
|
||||||
name in
|
name in
|
||||||
emit [span];
|
emit [span];
|
||||||
in
|
in
|
||||||
Fun.protect ~finally (fun () -> f (trace_id,span_id))
|
try
|
||||||
|
let x = f (trace_id,span_id) in
|
||||||
|
finally (Ok ());
|
||||||
|
x
|
||||||
|
with e ->
|
||||||
|
finally (Error (Printexc.to_string e));
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Metrics.
|
(** Metrics.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue