Skip to content

Commit

Permalink
re-add code to set span status based on scope
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Oct 18, 2024
1 parent acc9cb3 commit 53c1ddb
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/core/opentelemetry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,22 @@ module Trace = struct
(* called once we're done, to emit a span *)
let finally res =
let status =
match res with
| Ok () -> default_status ~code:Status_code_ok ()
| Error (e, bt) ->
(* add backtrace *)
Scope.record_exception scope e bt;
default_status ~code:Status_code_error ~message:(Printexc.to_string e)
()
match Scope.status scope with
| Some status -> Some status
| None ->
(match res with
| Ok () ->
(* By default, all spans are Unset, which means a span completed without error.
The Ok status is reserved for when you need to explicitly mark a span as successful
rather than stick with the default of Unset (i.e., “without error”).
https://opentelemetry.io/docs/languages/go/instrumentation/#set-span-status *)
None
| Error (e, bt) ->
Scope.record_exception scope e bt;
Some
(default_status ~code:Status_code_error
~message:(Printexc.to_string e) ()))
in
let span, _ =
(* TODO: should the attrs passed to with_ go on the Span
Expand All @@ -1182,7 +1191,7 @@ module Trace = struct
~id:span_id ?trace_state ~attrs:(Scope.attrs scope)
~events:(Scope.events scope) ~start_time
~end_time:(Timestamp_ns.now_unix_ns ())
~status name
?status name
in
emit ?service_name [ span ]
in
Expand Down

0 comments on commit 53c1ddb

Please sign in to comment.