Skip to content

Commit

Permalink
When converting to/from Jaeger set error tag if status is not ok (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#833)

* When converting to/from Jaeger set error tag if status is not ok

Signed-off-by: Bogdan Drutu <[email protected]>

* Do not set error=false

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Apr 14, 2020
1 parent 380a0e7 commit 75ae919
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
9 changes: 9 additions & 0 deletions translator/trace/jaeger/jaegerproto_to_protospan.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"
"go.opencensus.io/trace"

"github.com/open-telemetry/opentelemetry-collector/consumer/consumerdata"
"github.com/open-telemetry/opentelemetry-collector/internal"
Expand Down Expand Up @@ -203,6 +204,14 @@ func jProtoTagsToAttributes(tags []model.KeyValue) (string, tracepb.Span_SpanKin
sKind = tracepb.Span_SERVER
}

case tracetranslator.TagError:
if statusCodePtr == nil {
// Only set this if tracetranslator.TagStatusCode does not exists.
// The tracetranslator.TagStatusCode branch will overwrite the value if exists.
code := int32(trace.StatusCodeUnknown)
statusCodePtr = &code
}

case tracetranslator.TagStatusCode:
statusCodePtr = statusCodeFromProtoTag(tag)
continue
Expand Down
36 changes: 35 additions & 1 deletion translator/trace/jaeger/jaegerproto_to_protospan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ func expectedTraceData(t1, t2, t3 time.Time) consumerdata.TraceData {
},
},
},
{
TraceId: traceID,
SpanId: parentSpanID,
Name: &tracepb.TruncatableString{Value: "ProxyFetch"},
StartTime: internal.TimeToTimestamp(t2),
EndTime: internal.TimeToTimestamp(t3),
Kind: tracepb.Span_CLIENT,
Status: &tracepb.Status{
Code: trace.StatusCodeUnknown,
},
Attributes: &tracepb.Span_Attributes{
AttributeMap: map[string]*tracepb.AttributeValue{
"error": {
Value: &tracepb.AttributeValue_BoolValue{BoolValue: true},
},
"span.kind": {
Value: &tracepb.AttributeValue_StringValue{
StringValue: &tracepb.TruncatableString{Value: "client"},
},
},
},
},
},
},
}

Expand Down Expand Up @@ -226,7 +249,18 @@ func grpcFixture(t1 time.Time, d1, d2 time.Duration) model.Batch {
model.String(tracetranslator.TagStatusMsg, "Frontend crash"),
model.Int64(tracetranslator.TagStatusCode, trace.StatusCodeInternal),
model.String(tracetranslator.TagHTTPStatusMsg, "Internal server error"),
model.Int64("http.status_code", 500),
model.Int64(tracetranslator.TagHTTPStatusCode, 500),
model.Bool("error", true),
model.String("span.kind", "client"),
},
},
{
TraceID: traceID,
SpanID: parentSpanID,
OperationName: "ProxyFetch",
StartTime: t1.Add(d1),
Duration: d2,
Tags: []model.KeyValue{
model.Bool("error", true),
model.String("span.kind", "client"),
},
Expand Down
8 changes: 8 additions & 0 deletions translator/trace/jaeger/protospan_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ func appendJaegerTagFromOCStatusProto(jTags []jaeger.KeyValue, ocStatus *tracepb
VType: jaeger.ValueType_INT64,
})

if ocStatus.Code != 0 {
jTags = append(jTags, jaeger.KeyValue{
Key: tracetranslator.TagError,
VBool: ocStatus.Code != 0,
VType: jaeger.ValueType_BOOL,
})
}

if ocStatus.Message != "" {
jTags = append(jTags, jaeger.KeyValue{
Key: tracetranslator.TagStatusMsg,
Expand Down
28 changes: 28 additions & 0 deletions translator/trace/jaeger/protospan_to_jaegerproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
VInt64: int64(10),
VType: jaeger.ValueType_INT64,
},
{
Key: tracetranslator.TagError,
VBool: true,
VType: jaeger.ValueType_BOOL,
},
},
},
// only status.message
Expand Down Expand Up @@ -173,6 +178,11 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
VStr: "Forbidden",
VType: jaeger.ValueType_STRING,
},
{
Key: tracetranslator.TagError,
VBool: true,
VType: jaeger.ValueType_BOOL,
},
},
},

Expand All @@ -194,6 +204,11 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
StringValue: &tracepb.TruncatableString{Value: "Error"},
},
},
"error": {
Value: &tracepb.AttributeValue_BoolValue{
BoolValue: true,
},
},
},
},
wantTags: []jaeger.KeyValue{
Expand All @@ -207,6 +222,11 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
VStr: "Error",
VType: jaeger.ValueType_STRING,
},
{
Key: tracetranslator.TagError,
VBool: true,
VType: jaeger.ValueType_BOOL,
},
},
},

Expand Down Expand Up @@ -298,6 +318,11 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
VStr: "Forbidden",
VType: jaeger.ValueType_STRING,
},
{
Key: tracetranslator.TagError,
VBool: true,
VType: jaeger.ValueType_BOOL,
},
},
},
}
Expand All @@ -322,6 +347,9 @@ func TestOCStatusToJaegerProtoTags(t *testing.T) {
sort.Slice(gs.Tags, func(i, j int) bool {
return gs.Tags[i].Key < gs.Tags[j].Key
})
sort.Slice(c.wantTags, func(i, j int) bool {
return c.wantTags[i].Key < c.wantTags[j].Key
})
if !reflect.DeepEqual(c.wantTags, gs.Tags) {
t.Fatalf("%d: Unsuccessful conversion\nGot:\n\t%v\nWant:\n\t%v", i, gs.Tags, c.wantTags)
}
Expand Down
1 change: 1 addition & 0 deletions translator/trace/protospan_translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (

TagStatusCode = "status.code"
TagStatusMsg = "status.message"
TagError = "error"
TagHTTPStatusCode = "http.status_code"
TagHTTPStatusMsg = "http.status_message"
TagZipkinCensusCode = "census.status_code"
Expand Down

0 comments on commit 75ae919

Please sign in to comment.