Skip to content

Commit

Permalink
set export status code to upper case
Browse files Browse the repository at this point in the history
  • Loading branch information
NewReStarter committed Oct 17, 2022
1 parent 9d7779a commit 3bc7edc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Slice attributes of `attribute` package are now comparable based on their value, not instance. (#3108 #3252)
- Prometheus exporter will now cumulatively sum histogram buckets. (#3281)
- Names of `Span.Status.Code` of `codes` package are now fully upper case. (#3339)

## [1.11.0/0.32.3] 2022-10-12

Expand Down
18 changes: 11 additions & 7 deletions codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
)

const (
Expand All @@ -36,15 +37,15 @@ const (
type Code uint32

var codeToStr = map[Code]string{
Unset: "Unset",
Error: "Error",
Ok: "Ok",
Unset: "UNSET",
Error: "ERROR",
Ok: "OK",
}

var strToCode = map[string]Code{
`"Unset"`: Unset,
`"Error"`: Error,
`"Ok"`: Ok,
`"UNSET"`: Unset,
`"ERROR"`: Error,
`"OK"`: Ok,
}

// String returns the Code as a string.
Expand Down Expand Up @@ -73,7 +74,10 @@ func (c *Code) UnmarshalJSON(b []byte) error {
}
switch x.(type) {
case string:
if jc, ok := strToCode[string(b)]; ok {
// implicitly convert Status Code Name to upper case so that previous version
// Status.Code Name("Error", "Unset", "Ok") can be properly dealt with.
statusCodeStr := strings.ToUpper(string(b))
if jc, ok := strToCode[statusCodeStr]; ok {
*c = jc
return nil
}
Expand Down
15 changes: 9 additions & 6 deletions codes/codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestCodeString(t *testing.T) {
code Code
want string
}{
{Unset, "Unset"},
{Error, "Error"},
{Ok, "Ok"},
{Unset, "UNSET"},
{Error, "ERROR"},
{Ok, "OK"},
}

for _, test := range tests {
Expand Down Expand Up @@ -62,10 +62,13 @@ func TestCodeUnmarshalJSON(t *testing.T) {
want Code
}{
{"0", Unset},
{`"UNSET"`, Unset},
{`"Unset"`, Unset},
{"1", Error},
{`"ERROR"`, Error},
{`"Error"`, Error},
{"2", Ok},
{`"OK"`, Ok},
{`"Ok"`, Ok},
}
for _, test := range tests {
Expand Down Expand Up @@ -114,9 +117,9 @@ func TestCodeMarshalJSON(t *testing.T) {
code Code
want string
}{
{Unset, `"Unset"`},
{Error, `"Error"`},
{Ok, `"Ok"`},
{Unset, `"UNSET"`},
{Error, `"ERROR"`},
{Ok, `"OK"`},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/stdouttrace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func expectedJSON(now time.Time) string {
],
"Links": null,
"Status": {
"Code": "Error",
"Code": "ERROR",
"Description": "interesting"
},
"DroppedAttributes": 0,
Expand Down
16 changes: 8 additions & 8 deletions exporters/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestModelConversion(t *testing.T) {
"attr1": "42",
"attr2": "bar",
"attr3": "[0,1,2]",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -495,7 +495,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -587,7 +587,7 @@ func TestModelConversion(t *testing.T) {
"net.peer.ip": "1.2.3.4",
"net.peer.port": "9876",
"peer.hostname": "test-peer-hostname",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -673,7 +673,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -707,7 +707,7 @@ func TestModelConversion(t *testing.T) {
Tags: map[string]string{
"attr1": "42",
"attr2": "bar",
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "model-test",
"service.version": "0.1.0",
Expand Down
4 changes: 2 additions & 2 deletions exporters/zipkin/zipkin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestExportSpans(t *testing.T) {
RemoteEndpoint: nil,
Annotations: nil,
Tags: map[string]string{
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "404, file not found",
"service.name": "exporter-test",
"service.version": "0.1.0",
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestExportSpans(t *testing.T) {
RemoteEndpoint: nil,
Annotations: nil,
Tags: map[string]string{
"otel.status_code": "Error",
"otel.status_code": "ERROR",
"error": "403, forbidden",
"service.name": "exporter-test",
"service.version": "0.1.0",
Expand Down

0 comments on commit 3bc7edc

Please sign in to comment.