Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jaeger translations #1222

Merged
merged 4 commits into from
Jul 10, 2020
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 consumer/pdata/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ type SpanKind otlptrace.Span_SpanKind

func (sk SpanKind) String() string { return otlptrace.Span_SpanKind(sk).String() }

const (
TraceStateEmpty TraceState = ""
)

const (
SpanKindUNSPECIFIED = SpanKind(0)
SpanKindINTERNAL = SpanKind(otlptrace.Span_INTERNAL)
Expand Down
41 changes: 25 additions & 16 deletions internal/goldendataset/span_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func GenerateSpan(traceID []byte, parentID []byte, spanName string, spanInputs *
Kind: lookupSpanKind(spanInputs.Kind),
StartTimeUnixNano: uint64(endTime.Add(-215 * time.Millisecond).UnixNano()),
EndTimeUnixNano: uint64(endTime.UnixNano()),
Attributes: generateSpanAttributes(spanInputs.Attributes),
Attributes: generateSpanAttributes(spanInputs.Attributes, spanInputs.Status),
DroppedAttributesCount: 0,
Events: generateSpanEvents(spanInputs.Events),
DroppedEventsCount: 0,
Expand Down Expand Up @@ -188,7 +188,8 @@ func lookupSpanKind(kind PICTInputKind) otlptrace.Span_SpanKind {
}
}

func generateSpanAttributes(spanTypeID PICTInputAttributes) []*otlpcommon.KeyValue {
func generateSpanAttributes(spanTypeID PICTInputAttributes, statusStr PICTInputStatus) []*otlpcommon.KeyValue {
includeStatus := SpanStatusNil != statusStr
var attrs map[string]interface{}
switch spanTypeID {
case SpanAttrNil:
Expand All @@ -202,17 +203,17 @@ func generateSpanAttributes(spanTypeID PICTInputAttributes) []*otlpcommon.KeyVal
case SpanAttrFaaSDatasource:
attrs = generateFaaSDatasourceAttributes()
case SpanAttrFaaSHTTP:
attrs = generateFaaSHTTPAttributes()
attrs = generateFaaSHTTPAttributes(includeStatus)
case SpanAttrFaaSPubSub:
attrs = generateFaaSPubSubAttributes()
case SpanAttrFaaSTimer:
attrs = generateFaaSTimerAttributes()
case SpanAttrFaaSOther:
attrs = generateFaaSOtherAttributes()
case SpanAttrHTTPClient:
attrs = generateHTTPClientAttributes()
attrs = generateHTTPClientAttributes(includeStatus)
case SpanAttrHTTPServer:
attrs = generateHTTPServerAttributes()
attrs = generateHTTPServerAttributes(includeStatus)
case SpanAttrMessagingProducer:
attrs = generateMessagingProducerAttributes()
case SpanAttrMessagingConsumer:
Expand All @@ -224,7 +225,7 @@ func generateSpanAttributes(spanTypeID PICTInputAttributes) []*otlpcommon.KeyVal
case SpanAttrInternal:
attrs = generateInternalAttributes()
case SpanAttrMaxCount:
attrs = generateMaxCountAttributes()
attrs = generateMaxCountAttributes(includeStatus)
default:
attrs = generateGRPCClientAttributes()
}
Expand Down Expand Up @@ -279,15 +280,17 @@ func generateFaaSDatasourceAttributes() map[string]interface{} {
return attrMap
}

func generateFaaSHTTPAttributes() map[string]interface{} {
func generateFaaSHTTPAttributes(includeStatus bool) map[string]interface{} {
attrMap := make(map[string]interface{})
attrMap[conventions.AttributeFaaSTrigger] = conventions.FaaSTriggerHTTP
attrMap[conventions.AttributeHTTPMethod] = "POST"
attrMap[conventions.AttributeHTTPScheme] = "https"
attrMap[conventions.AttributeHTTPHost] = "api.opentelemetry.io"
attrMap[conventions.AttributeHTTPTarget] = "/blog/posts"
attrMap[conventions.AttributeHTTPFlavor] = "2"
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
if includeStatus {
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
}
attrMap[conventions.AttributeHTTPUserAgent] =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15"
attrMap[conventions.AttributeEnduserID] = "unittest"
Expand Down Expand Up @@ -324,25 +327,29 @@ func generateFaaSOtherAttributes() map[string]interface{} {
return attrMap
}

func generateHTTPClientAttributes() map[string]interface{} {
func generateHTTPClientAttributes(includeStatus bool) map[string]interface{} {
attrMap := make(map[string]interface{})
attrMap[conventions.AttributeHTTPMethod] = "GET"
attrMap[conventions.AttributeHTTPURL] = "https://opentelemetry.io/registry/"
attrMap[conventions.AttributeHTTPStatusCode] = int64(200)
attrMap[conventions.AttributeHTTPStatusText] = "More Than OK"
if includeStatus {
attrMap[conventions.AttributeHTTPStatusCode] = int64(200)
attrMap[conventions.AttributeHTTPStatusText] = "More Than OK"
}
attrMap[conventions.AttributeEnduserID] = "unittest"
return attrMap
}

func generateHTTPServerAttributes() map[string]interface{} {
func generateHTTPServerAttributes(includeStatus bool) map[string]interface{} {
attrMap := make(map[string]interface{})
attrMap[conventions.AttributeHTTPMethod] = "POST"
attrMap[conventions.AttributeHTTPScheme] = "https"
attrMap[conventions.AttributeHTTPServerName] = "api22.opentelemetry.io"
attrMap[conventions.AttributeNetHostPort] = int64(443)
attrMap[conventions.AttributeHTTPTarget] = "/blog/posts"
attrMap[conventions.AttributeHTTPFlavor] = "2"
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
if includeStatus {
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
}
attrMap[conventions.AttributeHTTPUserAgent] =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
attrMap[conventions.AttributeHTTPRoute] = "/blog/posts"
Expand Down Expand Up @@ -397,7 +404,7 @@ func generateInternalAttributes() map[string]interface{} {
return attrMap
}

func generateMaxCountAttributes() map[string]interface{} {
func generateMaxCountAttributes(includeStatus bool) map[string]interface{} {
attrMap := make(map[string]interface{})
attrMap[conventions.AttributeHTTPMethod] = "POST"
attrMap[conventions.AttributeHTTPScheme] = "https"
Expand All @@ -407,8 +414,10 @@ func generateMaxCountAttributes() map[string]interface{} {
attrMap[conventions.AttributeNetHostPort] = int64(443)
attrMap[conventions.AttributeHTTPTarget] = "/blog/posts"
attrMap[conventions.AttributeHTTPFlavor] = "2"
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
attrMap[conventions.AttributeHTTPStatusText] = "Created"
if includeStatus {
attrMap[conventions.AttributeHTTPStatusCode] = int64(201)
attrMap[conventions.AttributeHTTPStatusText] = "Created"
}
attrMap[conventions.AttributeHTTPUserAgent] =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
attrMap[conventions.AttributeHTTPRoute] = "/blog/posts"
Expand Down
37 changes: 31 additions & 6 deletions translator/trace/jaeger/jaegerproto_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ func protoBatchToResourceSpans(batch model.Batch, dest pdata.ResourceSpans) {
}

func jProcessToInternalResource(process *model.Process, dest pdata.Resource) {
if process == nil {
if process == nil || process.ServiceName == tracetranslator.ResourceNotSet {
return
}

dest.InitEmpty()

serviceName := process.GetServiceName()
if serviceName == tracetranslator.ResourceNoAttrs {
return
}
tags := process.GetTags()
if serviceName == "" && tags == nil {
return
Expand Down Expand Up @@ -176,6 +179,7 @@ func jSpanToInternal(span *model.Span, dest pdata.Span) {
dest.SetKind(jSpanKindToInternal(spanKindAttr.StringVal()))
attrs.Delete(tracetranslator.TagSpanKind)
}
dest.SetTraceState(getTraceStateFromAttrs(attrs))

// drop the attributes slice if all of them were replaced during translation
if attrs.Len() == 0 {
Expand Down Expand Up @@ -206,27 +210,31 @@ func jTagsToInternalAttributes(tags []model.KeyValue, dest pdata.AttributeMap) {
}

func setInternalSpanStatus(attrs pdata.AttributeMap, dest pdata.SpanStatus) {
dest.InitEmpty()

statusCode := pdata.StatusCode(otlptrace.Status_Ok)
statusMessage := ""
statusExists := false

if errorVal, ok := attrs.Get(tracetranslator.TagError); ok {
if errorVal.BoolVal() {
statusCode = pdata.StatusCode(otlptrace.Status_UnknownError)
attrs.Delete(tracetranslator.TagError)
statusExists = true
}
}

if codeAttr, ok := attrs.Get(tracetranslator.TagStatusCode); ok {
statusExists = true
if code, err := getStatusCodeFromAttr(codeAttr); err == nil {
statusCode = code
attrs.Delete(tracetranslator.TagStatusCode)
}
if msgAttr, ok := attrs.Get(tracetranslator.TagStatusMsg); ok {
dest.SetMessage(msgAttr.StringVal())
statusMessage = msgAttr.StringVal()
attrs.Delete(tracetranslator.TagStatusMsg)
}
} else if httpCodeAttr, ok := attrs.Get(tracetranslator.TagHTTPStatusCode); ok {
statusExists = true
if code, err := getStatusCodeFromHTTPStatusAttr(httpCodeAttr); err == nil {

// Do not set status code to OK in case it was set to Unknown based on "error" tag
Expand All @@ -235,12 +243,16 @@ func setInternalSpanStatus(attrs pdata.AttributeMap, dest pdata.SpanStatus) {
}

if msgAttr, ok := attrs.Get(tracetranslator.TagHTTPStatusMsg); ok {
dest.SetMessage(msgAttr.StringVal())
statusMessage = msgAttr.StringVal()
}
}
}

dest.SetCode(statusCode)
if statusExists {
dest.InitEmpty()
dest.SetCode(statusCode)
dest.SetMessage(statusMessage)
}
}

func getStatusCodeFromAttr(attrVal pdata.AttributeValue) (pdata.StatusCode, error) {
Expand Down Expand Up @@ -283,6 +295,8 @@ func jSpanKindToInternal(spanKind string) pdata.SpanKind {
return pdata.SpanKindPRODUCER
case "consumer":
return pdata.SpanKindCONSUMER
case "internal":
return pdata.SpanKindINTERNAL
}
return pdata.SpanKindUNSPECIFIED
}
Expand All @@ -305,8 +319,9 @@ func jLogsToSpanEvents(logs []model.Log, dest pdata.SpanEventSlice) {
attrs := event.Attributes()
attrs.InitEmptyWithCapacity(len(log.Fields))
jTagsToInternalAttributes(log.Fields, attrs)
if name, ok := attrs.Get("message"); ok {
if name, ok := attrs.Get(tracetranslator.TagMessage); ok {
event.SetName(name.StringVal())
attrs.Delete(tracetranslator.TagMessage)
}
}
}
Expand Down Expand Up @@ -335,3 +350,13 @@ func jReferencesToSpanLinks(refs []model.SpanRef, excludeParentID model.SpanID,
dest.Resize(i)
}
}

func getTraceStateFromAttrs(attrs pdata.AttributeMap) pdata.TraceState {
traceState := pdata.TraceStateEmpty
// TODO Bring this inline with solution for jaegertracing/jaeger-client-java #702 once available
if attr, ok := attrs.Get(tracetranslator.TagW3CTraceState); ok {
traceState = pdata.TraceState(attr.StringVal())
attrs.Delete(tracetranslator.TagW3CTraceState)
}
return traceState
}
Loading