From f86da0a2d310ce33699542bb8db314f0201c5e29 Mon Sep 17 00:00:00 2001 From: Jun Guo Date: Wed, 24 Apr 2019 21:12:01 -0400 Subject: [PATCH] Add span format tag for jaeger-collector (#1493) include span format tag for every processed span in the collector Signed-off-by: jung --- cmd/collector/app/span_processor.go | 4 ++++ model/converter/thrift/jaeger/to_domain.go | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go index 0ef20bf3040..e251d059863 100644 --- a/cmd/collector/app/span_processor.go +++ b/cmd/collector/app/span_processor.go @@ -148,6 +148,10 @@ func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat SpanFormat spanCounts.RejectedBySvc.ReportServiceNameForSpan(span) return true // as in "not dropped", because it's actively rejected } + + //add format tag + span.Tags = append(span.Tags, model.String("internal.span.format", string(originalFormat))) + item := &queueItem{ queuedTime: time.Now(), span: span, diff --git a/model/converter/thrift/jaeger/to_domain.go b/model/converter/thrift/jaeger/to_domain.go index a5f0cc9543b..48891c64e53 100644 --- a/model/converter/thrift/jaeger/to_domain.go +++ b/model/converter/thrift/jaeger/to_domain.go @@ -58,7 +58,8 @@ func (td toDomain) ToDomainSpan(jSpan *jaeger.Span, jProcess *jaeger.Process) *m func (td toDomain) transformSpan(jSpan *jaeger.Span, mProcess *model.Process) *model.Span { traceID := model.NewTraceID(uint64(jSpan.TraceIdHigh), uint64(jSpan.TraceIdLow)) - tags := td.getTags(jSpan.Tags) + //allocate extra space for future append operation + tags := td.getTags(jSpan.Tags, 1) refs := td.getReferences(jSpan.References) // We no longer store ParentSpanID in the domain model, but the data in Thrift model // might still have these IDs without representing them in the References, so we @@ -104,18 +105,21 @@ func (td toDomain) getProcess(jProcess *jaeger.Process) *model.Process { if jProcess == nil { return nil } - tags := td.getTags(jProcess.Tags) + tags := td.getTags(jProcess.Tags, 0) return &model.Process{ Tags: tags, ServiceName: jProcess.ServiceName, } } -func (td toDomain) getTags(tags []*jaeger.Tag) model.KeyValues { +//convert the jaeger.Tag slice to domain KeyValue slice +//zipkin/to_domain.go does not give a default slice size since it has to filter annotations, jaeger conversion is more predictable +//thus to avoid future full array copy when using append, pre-allocate extra space as an optimization +func (td toDomain) getTags(tags []*jaeger.Tag, extraSpace int) model.KeyValues { if len(tags) == 0 { return nil } - retMe := make(model.KeyValues, len(tags)) + retMe := make(model.KeyValues, len(tags), len(tags)+extraSpace) for i, tag := range tags { retMe[i] = td.getTag(tag) } @@ -147,7 +151,7 @@ func (td toDomain) getLogs(logs []*jaeger.Log) []model.Log { for i, log := range logs { retMe[i] = model.Log{ Timestamp: model.EpochMicrosecondsAsTime(uint64(log.Timestamp)), - Fields: td.getTags(log.Fields), + Fields: td.getTags(log.Fields, 0), } } return retMe