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

Tracing fixes for error span #297

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tracing/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ func AddErrorCurrentSpan(ctx context.Context, err error) error {

//AddErrorSpan adds error into span
func AddErrorSpan(span *trace.Span, err error) error {
var code int32 = trace.StatusCodeUnknown
var code int32 = trace.StatusCodeOK
status, ok := status.FromError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

The reuse of status here from module to variable makes the code harder to understand.

if ok && status != nil {
code = int32(status.Code())
}

span.SetStatus(trace.Status{
Code: code,
Message: err.Error(),
})
if code != trace.StatusCodeOK {
span.AddAttributes(trace.Int64Attribute("census.status_code", int64(code)), trace.StringAttribute("census.status_description", err.Error()), trace.BoolAttribute("error", true))
}

return err
}