Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Scope.set_span_status #75

Merged
merged 6 commits into from
Oct 21, 2024
Merged

Conversation

tatchi
Copy link
Contributor

@tatchi tatchi commented Oct 17, 2024

No description provided.

@@ -807,6 +918,7 @@ module Scope : sig
trace_id: Trace_id.t;
span_id: Span_id.t;
mutable items: item_list;
mutable span_status: Span.status option;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move the Span module up to access it here. But perhaps a better idea would be to extract the status-related code into a Span_status module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now Scope is in Trace section

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Span_status could make sense, indeed, since it's its own type!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to put the status in items, for the same reasons we introduced item_list recently?

Comment on lines 1142 to 1151
match scope.span_status with
| Some status -> status
| None ->
(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) ())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the order of preference is correct here 🤔 My thought was that I don't want to override what the user has set.

But then it means that if the user has explicitly set an Ok status and an exception is raised, the span will remain in the Ok status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at what the official sdk does, I found this. It seems like we shouldn't set Ok unless it's explicitly done by the user; and so it makes sense to not override the user's explicit choice (maybe the exception is not an actual error).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we shouldn't set Ok unless it's explicitly done by the user

I agree and adapted the code

end = struct
type item_list =
| Nil
| Ev of Event.t * item_list
| Attr of key_value * item_list
| Span_link of Span_link.t * item_list
| Span_status of Span_status.t * item_list
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how it matters since that's internal anyway, but this type doesn't enforce the fact that there can only be one status per span.

Copy link
Contributor Author

@tatchi tatchi Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking maybe we can add this info to the Nil constructor

type item_list =
  | Nil of Span_status.t option
  | Ev of Event.t * item_list
  | Attr of key_value * item_list
  | Span_link of Span_link.t * item_list

But I'm not sure how it will scale if we add more elements. We may want to switch to a record if we add more elements but then I don't know if that's any better that my initial implementation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters too much that there can be only one :). We can just pick the last one.

src/core/opentelemetry.ml Outdated Show resolved Hide resolved
Copy link
Member

@c-cube c-cube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now!

@c-cube c-cube merged commit 3a22a93 into imandra-ai:main Oct 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants