You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
Improve trace status handling (#3214)
* Implement specification compliant trace status handling * Update trace/trace.go Co-authored-by: Damien Mathieu <42@dmathieu.com> * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * chore: Make linter happy Co-authored-by: Damien Mathieu <42@dmathieu.com> Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -22,8 +22,84 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
)
|
||||
|
||||
func TestSetStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
span recordingSpan
|
||||
code codes.Code
|
||||
description string
|
||||
expected Status
|
||||
}{
|
||||
{
|
||||
"Error and description should overwrite Unset",
|
||||
recordingSpan{},
|
||||
codes.Error,
|
||||
"description",
|
||||
Status{Code: codes.Error, Description: "description"},
|
||||
},
|
||||
{
|
||||
"Ok should overwrite Unset and ignore description",
|
||||
recordingSpan{},
|
||||
codes.Ok,
|
||||
"description",
|
||||
Status{Code: codes.Ok},
|
||||
},
|
||||
{
|
||||
"Error and description should return error and overwrite description",
|
||||
recordingSpan{status: Status{Code: codes.Error, Description: "d1"}},
|
||||
codes.Error,
|
||||
"d2",
|
||||
Status{Code: codes.Error, Description: "d2"},
|
||||
},
|
||||
{
|
||||
"Ok should overwrite error and remove description",
|
||||
recordingSpan{status: Status{Code: codes.Error, Description: "d1"}},
|
||||
codes.Ok,
|
||||
"d2",
|
||||
Status{Code: codes.Ok},
|
||||
},
|
||||
{
|
||||
"Error and description should be ignored when already Ok",
|
||||
recordingSpan{status: Status{Code: codes.Ok}},
|
||||
codes.Error,
|
||||
"d2",
|
||||
Status{Code: codes.Ok},
|
||||
},
|
||||
{
|
||||
"Ok should be noop when already Ok",
|
||||
recordingSpan{status: Status{Code: codes.Ok}},
|
||||
codes.Ok,
|
||||
"d2",
|
||||
Status{Code: codes.Ok},
|
||||
},
|
||||
{
|
||||
"Unset should be noop when already Ok",
|
||||
recordingSpan{status: Status{Code: codes.Ok}},
|
||||
codes.Unset,
|
||||
"d2",
|
||||
Status{Code: codes.Ok},
|
||||
},
|
||||
{
|
||||
"Unset should be noop when already Error",
|
||||
recordingSpan{status: Status{Code: codes.Error, Description: "d1"}},
|
||||
codes.Unset,
|
||||
"d2",
|
||||
Status{Code: codes.Error, Description: "d1"},
|
||||
},
|
||||
}
|
||||
|
||||
for i := range tests {
|
||||
tc := &tests[i]
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.span.SetStatus(tc.code, tc.description)
|
||||
assert.Equal(t, tc.expected, tc.span.status)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncateAttr(t *testing.T) {
|
||||
const key = "key"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user