diff --git a/semconv/v1.4.0/http.go b/semconv/v1.4.0/http.go index 869b3152925..9cc3c8f883e 100644 --- a/semconv/v1.4.0/http.go +++ b/semconv/v1.4.0/http.go @@ -263,21 +263,22 @@ var validRangesPerCategory = map[int][]codeRange{ // SpanStatusFromHTTPStatusCode generates a status code and a message // as specified by the OpenTelemetry specification for a span. func SpanStatusFromHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, string) { - spanCode, valid := validateHTTPStatusCode(code, spanKind) + spanCode, valid := validateHTTPStatusCode(code) if !valid { return spanCode, fmt.Sprintf("Invalid HTTP status code %d", code) } + category := code / 100 + if spanKind == trace.SpanKindServer && category == 4 { + return codes.Unset, "" + } return spanCode, "" } // Validates the HTTP status code and returns corresponding span status code. // If the `code` is not a valid HTTP status code, returns span status Error // and false. -func validateHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, bool) { +func validateHTTPStatusCode(code int) (codes.Code, bool) { category := code / 100 - if spanKind == trace.SpanKindServer && category == 4 { - return codes.Unset, false - } ranges, ok := validRangesPerCategory[category] if !ok { return codes.Error, false diff --git a/semconv/v1.4.0/http_test.go b/semconv/v1.4.0/http_test.go index 58d05edd739..828f9ea6951 100644 --- a/semconv/v1.4.0/http_test.go +++ b/semconv/v1.4.0/http_test.go @@ -860,14 +860,14 @@ func TestSpanStatusFromHTTPStatusCode(t *testing.T) { got, msg := SpanStatusFromHTTPStatusCode(code, trace.SpanKindClient) assert.Equalf(t, expected, got, "%s vs %s", expected, got) - _, valid := validateHTTPStatusCode(code, trace.SpanKindClient) + _, valid := validateHTTPStatusCode(code) if !valid { assert.NotEmpty(t, msg, "message should be set if error cannot be inferred from code") } else { assert.Empty(t, msg, "message should not be set if error can be inferred from code") } } - code, valid := validateHTTPStatusCode(400, trace.SpanKindServer) + code, valid := validateHTTPStatusCode(400) if !valid { assert.Equalf(t, codes.Unset, code, "message should be set if error cannot be inferred from code") } diff --git a/semconv/v1.5.0/http.go b/semconv/v1.5.0/http.go index 4475470e577..5875a29a1dd 100644 --- a/semconv/v1.5.0/http.go +++ b/semconv/v1.5.0/http.go @@ -263,21 +263,22 @@ var validRangesPerCategory = map[int][]codeRange{ // SpanStatusFromHTTPStatusCode generates a status code and a message // as specified by the OpenTelemetry specification for a span. func SpanStatusFromHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, string) { - spanCode, valid := validateHTTPStatusCode(code, spanKind) + spanCode, valid := validateHTTPStatusCode(code) if !valid { return spanCode, fmt.Sprintf("Invalid HTTP status code %d", code) } + category := code / 100 + if spanKind == trace.SpanKindServer && category == 4 { + return codes.Unset, "" + } return spanCode, "" } // Validates the HTTP status code and returns corresponding span status code. // If the `code` is not a valid HTTP status code, returns span status Error // and false. -func validateHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, bool) { +func validateHTTPStatusCode(code int) (codes.Code, bool) { category := code / 100 - if spanKind == trace.SpanKindServer && category == 4 { - return codes.Unset, false - } ranges, ok := validRangesPerCategory[category] if !ok { return codes.Error, false diff --git a/semconv/v1.5.0/http_test.go b/semconv/v1.5.0/http_test.go index 364688353c2..1abafb2ba30 100644 --- a/semconv/v1.5.0/http_test.go +++ b/semconv/v1.5.0/http_test.go @@ -860,14 +860,14 @@ func TestSpanStatusFromHTTPStatusCode(t *testing.T) { got, msg := SpanStatusFromHTTPStatusCode(code, trace.SpanKindClient) assert.Equalf(t, expected, got, "%s vs %s", expected, got) - _, valid := validateHTTPStatusCode(code, trace.SpanKindClient) + _, valid := validateHTTPStatusCode(code) if !valid { assert.NotEmpty(t, msg, "message should be set if error cannot be inferred from code") } else { assert.Empty(t, msg, "message should not be set if error can be inferred from code") } } - code, valid := validateHTTPStatusCode(400, trace.SpanKindServer) + code, valid := validateHTTPStatusCode(400) if !valid { assert.Equalf(t, codes.Unset, code, "message should be set if error cannot be inferred from code") } diff --git a/semconv/v1.6.1/http.go b/semconv/v1.6.1/http.go index 624af8f3889..2defe5d71cc 100644 --- a/semconv/v1.6.1/http.go +++ b/semconv/v1.6.1/http.go @@ -263,21 +263,22 @@ var validRangesPerCategory = map[int][]codeRange{ // SpanStatusFromHTTPStatusCode generates a status code and a message // as specified by the OpenTelemetry specification for a span. func SpanStatusFromHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, string) { - spanCode, valid := validateHTTPStatusCode(code, spanKind) + spanCode, valid := validateHTTPStatusCode(code) if !valid { return spanCode, fmt.Sprintf("Invalid HTTP status code %d", code) } + category := code / 100 + if spanKind == trace.SpanKindServer && category == 4 { + return codes.Unset, "" + } return spanCode, "" } // Validates the HTTP status code and returns corresponding span status code. // If the `code` is not a valid HTTP status code, returns span status Error // and false. -func validateHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, bool) { +func validateHTTPStatusCode(code int) (codes.Code, bool) { category := code / 100 - if spanKind == trace.SpanKindServer && category == 4 { - return codes.Unset, false - } ranges, ok := validRangesPerCategory[category] if !ok { return codes.Error, false diff --git a/semconv/v1.6.1/http_test.go b/semconv/v1.6.1/http_test.go index fc3f3632a5b..258aba685e3 100644 --- a/semconv/v1.6.1/http_test.go +++ b/semconv/v1.6.1/http_test.go @@ -859,14 +859,14 @@ func TestSpanStatusFromHTTPStatusCode(t *testing.T) { got, msg := SpanStatusFromHTTPStatusCode(code, trace.SpanKindClient) assert.Equalf(t, expected, got, "%s vs %s", expected, got) - _, valid := validateHTTPStatusCode(code, trace.SpanKindClient) + _, valid := validateHTTPStatusCode(code) if !valid { assert.NotEmpty(t, msg, "message should be set if error cannot be inferred from code") } else { assert.Empty(t, msg, "message should not be set if error can be inferred from code") } } - code, valid := validateHTTPStatusCode(400, trace.SpanKindServer) + code, valid := validateHTTPStatusCode(400) if !valid { assert.Equalf(t, codes.Unset, code, "message should be set if error cannot be inferred from code") } diff --git a/semconv/v1.7.0/http.go b/semconv/v1.7.0/http.go index 8e82f38113f..35761e47674 100644 --- a/semconv/v1.7.0/http.go +++ b/semconv/v1.7.0/http.go @@ -264,21 +264,22 @@ var validRangesPerCategory = map[int][]codeRange{ // SpanStatusFromHTTPStatusCode generates a status code and a message // as specified by the OpenTelemetry specification for a span. func SpanStatusFromHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, string) { - spanCode, valid := validateHTTPStatusCode(code, spanKind) + spanCode, valid := validateHTTPStatusCode(code) if !valid { return spanCode, fmt.Sprintf("Invalid HTTP status code %d", code) } + category := code / 100 + if spanKind == trace.SpanKindServer && category == 4 { + return codes.Unset, "" + } return spanCode, "" } // Validates the HTTP status code and returns corresponding span status code. // If the `code` is not a valid HTTP status code, returns span status Error // and false. -func validateHTTPStatusCode(code int, spanKind trace.SpanKind) (codes.Code, bool) { +func validateHTTPStatusCode(code int) (codes.Code, bool) { category := code / 100 - if spanKind == trace.SpanKindServer && category == 4 { - return codes.Unset, false - } ranges, ok := validRangesPerCategory[category] if !ok { return codes.Error, false diff --git a/semconv/v1.7.0/http_test.go b/semconv/v1.7.0/http_test.go index 7c369b6af48..003cb509975 100644 --- a/semconv/v1.7.0/http_test.go +++ b/semconv/v1.7.0/http_test.go @@ -860,14 +860,14 @@ func TestSpanStatusFromHTTPStatusCode(t *testing.T) { got, msg := SpanStatusFromHTTPStatusCode(code, trace.SpanKindClient) assert.Equalf(t, expected, got, "%s vs %s", expected, got) - _, valid := validateHTTPStatusCode(code, trace.SpanKindClient) + _, valid := validateHTTPStatusCode(code) if !valid { assert.NotEmpty(t, msg, "message should be set if error cannot be inferred from code") } else { assert.Empty(t, msg, "message should not be set if error can be inferred from code") } } - code, valid := validateHTTPStatusCode(400, trace.SpanKindServer) + code, valid := validateHTTPStatusCode(400) if !valid { assert.Equalf(t, codes.Unset, code, "message should be set if error cannot be inferred from code") }