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

Implement the SDK's Span.SetStatus method #1112

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion sdk/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,18 @@ func (s *span) SetStatus(c codes.Code, msg string) {
if s == nil || !s.sampled {
return
}
/* TODO: implement */

stat := s.span.Status()
stat.SetMessage(msg)

switch c {
case codes.Unset:
stat.SetCode(ptrace.StatusCodeUnset)
case codes.Error:
stat.SetCode(ptrace.StatusCodeError)
case codes.Ok:
stat.SetCode(ptrace.StatusCodeOk)
}
}

func (s *span) SetAttributes(attrs ...attribute.KeyValue) {
Expand Down
20 changes: 20 additions & 0 deletions sdk/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ func TestSpanIsRecording(t *testing.T) {
assert.False(t, s.IsRecording(), "unsampled span should not be recorded")
}

func TestSpanSetStatus(t *testing.T) {
s := spanBuilder{}.Build()

want := ptrace.NewStatus()
assert.Equal(t, want, s.span.Status(), "empty status should not be set")

msg := "test"
want.SetMessage(msg)

for c, p := range map[codes.Code]ptrace.StatusCode{
codes.Error: ptrace.StatusCodeError,
codes.Ok: ptrace.StatusCodeOk,
codes.Unset: ptrace.StatusCodeUnset,
} {
want.SetCode(p)
s.SetStatus(c, msg)
assert.Equalf(t, want, s.span.Status(), "code: %s, msg: %s", c, msg)
}
}

func TestSpanTracerProvider(t *testing.T) {
var s span

Expand Down
Loading