Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 🛑 Breaking changes 🛑

- Remove OpenCensus status constants and transformation (#3110)

## v0.26.0 Beta

## 🛑 Breaking changes 🛑
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,54 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package tracetranslator
package zipkin

// https://github.com/googleapis/googleapis/blob/bee79fbe03254a35db125dc6d2f1e9b752b390fe/google/rpc/code.proto#L33-L186
const (
OCOK = 0
OCCancelled = 1
OCUnknown = 2
OCInvalidArgument = 3
OCDeadlineExceeded = 4
OCNotFound = 5
OCAlreadyExists = 6
OCPermissionDenied = 7
OCResourceExhausted = 8
OCFailedPrecondition = 9
OCAborted = 10
OCOutOfRange = 11
OCUnimplemented = 12
OCInternal = 13
OCUnavailable = 14
OCDataLoss = 15
OCUnauthenticated = 16
ocOK = 0
ocCancelled = 1
ocUnknown = 2
ocInvalidArgument = 3
ocDeadlineExceeded = 4
ocNotFound = 5
// ocAlreadyExists = 6
ocPermissionDenied = 7
ocResourceExhausted = 8
// ocFailedPrecondition = 9
// ocAborted = 10
// ocOutOfRange = 11
ocUnimplemented = 12
ocInternal = 13
ocUnavailable = 14
// ocDataLoss = 15
ocUnauthenticated = 16
)

var httpToOCCodeMap = map[int32]int32{
401: OCUnauthenticated,
403: OCPermissionDenied,
404: OCNotFound,
429: OCResourceExhausted,
499: OCCancelled,
501: OCUnimplemented,
503: OCUnavailable,
504: OCDeadlineExceeded,
401: ocUnauthenticated,
403: ocPermissionDenied,
404: ocNotFound,
429: ocResourceExhausted,
499: ocCancelled,
501: ocUnimplemented,
503: ocUnavailable,
504: ocDeadlineExceeded,
}

// OCStatusCodeFromHTTP takes an HTTP status code and return the appropriate OpenTelemetry status code
// ocStatusCodeFromHTTP takes an HTTP status code and return the appropriate OpenTelemetry status code
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-http.md
func OCStatusCodeFromHTTP(code int32) int32 {
func ocStatusCodeFromHTTP(code int32) int32 {
if code >= 100 && code < 400 {
return OCOK
return ocOK
}
if c, ok := httpToOCCodeMap[code]; ok {
return c
}
if code >= 400 && code < 500 {
return OCInvalidArgument
return ocInvalidArgument
}
if code >= 500 && code < 600 {
return OCInternal
return ocInternal
}
return OCUnknown
return ocUnknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package tracetranslator
package zipkin

import (
"testing"
Expand All @@ -22,7 +22,7 @@ import (

func TestOTStatusFromHTTPStatus(t *testing.T) {
for httpStatus := int32(100); httpStatus <= 604; httpStatus++ {
otelStatus := OCStatusCodeFromHTTP(httpStatus)
assert.True(t, otelStatus >= OCOK && otelStatus <= OCUnauthenticated)
otelStatus := ocStatusCodeFromHTTP(httpStatus)
assert.True(t, otelStatus >= ocOK && otelStatus <= ocUnauthenticated)
}
}
2 changes: 1 addition & 1 deletion translator/trace/zipkin/status_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (m *statusMapper) fromAttribute(key string, attrib *tracepb.AttributeValue)
case tracetranslator.TagHTTPStatusCode:
httpCode, err := attribToStatusCode(attrib)
if err == nil {
code := tracetranslator.OCStatusCodeFromHTTP(httpCode)
code := ocStatusCodeFromHTTP(httpCode)
m.fromHTTP.codePtr = &code
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) {

func TestThriftHTTPToGRPCStatusCode(t *testing.T) {
for i := int32(100); i <= 600; i++ {
wantStatus := tracetranslator.OCStatusCodeFromHTTP(i)
wantStatus := ocStatusCodeFromHTTP(i)
gb, err := v1ThriftBatchToOCProto([]*zipkincore.Span{{
ID: 1,
TraceID: 1,
Expand Down
2 changes: 1 addition & 1 deletion translator/trace/zipkin/zipkinv1_to_protospan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestJSONHTTPToGRPCStatusCode(t *testing.T) {
fakeTraceID := "00000000000000010000000000000002"
fakeSpanID := "0000000000000001"
for i := int32(100); i <= 600; i++ {
wantStatus := tracetranslator.OCStatusCodeFromHTTP(i)
wantStatus := ocStatusCodeFromHTTP(i)
zBytes, err := json.Marshal([]*zipkinV1Span{{
ID: fakeSpanID,
TraceID: fakeTraceID,
Expand Down