Skip to content
Closed
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
21 changes: 16 additions & 5 deletions translator/trace/jaeger/traces_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
tracetranslator "github.com/open-telemetry/opentelemetry-collector/translator/trace"
)

var (
resourceSkipKeys = map[string]struct{}{
conventions.AttributeServiceName: {},
}

noSkipKeys = map[string]struct{}{}
)

// InternalTracesToJaegerProto translates internal trace data into the Jaeger Proto for GRPC.
// Returns slice of translated Jaeger batches and error if translation failed.
func InternalTracesToJaegerProto(td pdata.Traces) ([]*model.Batch, error) {
Expand Down Expand Up @@ -117,20 +125,23 @@ func resourceToJaegerProtoProcess(resource pdata.Resource) *model.Process {
process := model.Process{}
if serviceName, ok := attrs.Get(conventions.AttributeServiceName); ok {
process.ServiceName = serviceName.StringVal()
attrs.Delete(conventions.AttributeServiceName)
}
process.Tags = attributesToJaegerProtoTags(attrs)
process.Tags = attributesToJaegerProtoTags(attrs, resourceSkipKeys)
return &process

}

func attributesToJaegerProtoTags(attrs pdata.AttributeMap) []model.KeyValue {
func attributesToJaegerProtoTags(attrs pdata.AttributeMap, skipKeys map[string]struct{}) []model.KeyValue {
if attrs.Cap() == 0 {
return nil
}

tags := make([]model.KeyValue, 0, attrs.Cap())
attrs.ForEach(func(key string, attr pdata.AttributeValue) {
if _, skip := skipKeys[key]; skip {
return
}
Copy link
Member

@dmitryax dmitryax Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing it!

The only concern I have is that now we scatter handling of conventions.AttributeServiceName across many functions, it doesn't seem right especially having attributesToJaegerProtoTags function being called in other places. Probably we could add another argument to attributesToJaegerProtoTags like skipKeys map[string]bool that can be used to filter particular keys out. What do you think?

cc @tigrannajaryan

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attributesToJaegerProtoTags is used in several places, so it makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this. Map lookup is going to have cost. Translation functions need to be fast, and this one loop is the most frequently called one. I would like to see performance profile before accepting this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think map lookups should be pretty fast. map initialization is the most expensive, but here it's handled perfectly, only two initializations. Otherwise we can just duplicate the function and create resourceAttributesToJaegerProtoTags for now in order to not block the fix. @tigrannajaryan what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want a quick fix let's pass a single bool parameter that controls AttributeServiceName specifically.

If we want the map I can be easily convinced by a CPU profile that shows it is not significant. :-)


tag := model.KeyValue{Key: key}
switch attr.Type() {
case pdata.AttributeValueSTRING:
Expand Down Expand Up @@ -173,7 +184,7 @@ func spanToJaegerProto(span pdata.Span) (*model.Span, error) {
return nil, fmt.Errorf("error converting span links to Jaeger references: %w", err)
}

tags := attributesToJaegerProtoTags(span.Attributes())
tags := attributesToJaegerProtoTags(span.Attributes(), noSkipKeys)
tags = appendTagFromSpanKind(tags, span.Kind())
tags = appendTagFromSpanStatus(tags, span.Status())
startTime := internal.UnixNanoToTime(span.StartTime())
Expand Down Expand Up @@ -292,7 +303,7 @@ func spanEventsToJaegerProtoLogs(events pdata.SpanEventSlice) []model.Log {

logs = append(logs, model.Log{
Timestamp: internal.UnixNanoToTime(event.Timestamp()),
Fields: attributesToJaegerProtoTags(event.Attributes()),
Fields: attributesToJaegerProtoTags(event.Attributes(), noSkipKeys),
})
}

Expand Down
6 changes: 5 additions & 1 deletion translator/trace/jaeger/traces_to_jaegerproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {
attributes.InsertInt("int-val", 123)
attributes.InsertString("string-val", "abc")
attributes.InsertDouble("double-val", 1.23)
attributes.InsertString("skip", "must be skipped")

expected := []model.KeyValue{
{
Expand All @@ -212,7 +213,10 @@ func TestAttributesToJaegerProtoTags(t *testing.T) {
},
}

require.EqualValues(t, expected, attributesToJaegerProtoTags(attributes))
skipKeys := map[string]struct{}{
"skip": {},
}
require.EqualValues(t, expected, attributesToJaegerProtoTags(attributes, skipKeys))
}

func TestInternalTracesToJaegerProto(t *testing.T) {
Expand Down