|
|
@ -2,6 +2,7 @@ package zipkin |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
protogen "github.com/bilibili/kratos/pkg/net/trace/proto" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/bilibili/kratos/pkg/net/trace" |
|
|
|
"github.com/bilibili/kratos/pkg/net/trace" |
|
|
@ -30,7 +31,6 @@ func (r *report) WriteSpan(raw *trace.Span) (err error) { |
|
|
|
spanID := model.ID(ctx.SpanID) |
|
|
|
spanID := model.ID(ctx.SpanID) |
|
|
|
parentID := model.ID(ctx.ParentID) |
|
|
|
parentID := model.ID(ctx.ParentID) |
|
|
|
tags := raw.Tags() |
|
|
|
tags := raw.Tags() |
|
|
|
logs := raw.Logs() |
|
|
|
|
|
|
|
span := model.SpanModel{ |
|
|
|
span := model.SpanModel{ |
|
|
|
SpanContext: model.SpanContext{ |
|
|
|
SpanContext: model.SpanContext{ |
|
|
|
TraceID: traceID, |
|
|
|
TraceID: traceID, |
|
|
@ -40,7 +40,7 @@ func (r *report) WriteSpan(raw *trace.Span) (err error) { |
|
|
|
Name: raw.OperationName(), |
|
|
|
Name: raw.OperationName(), |
|
|
|
Timestamp: raw.StartTime(), |
|
|
|
Timestamp: raw.StartTime(), |
|
|
|
Duration: raw.Duration(), |
|
|
|
Duration: raw.Duration(), |
|
|
|
Tags: make(map[string]string, len(tags)+len(logs)), |
|
|
|
Tags: make(map[string]string, len(tags)), |
|
|
|
} |
|
|
|
} |
|
|
|
span.LocalEndpoint = &model.Endpoint{ServiceName: raw.ServiceName()} |
|
|
|
span.LocalEndpoint = &model.Endpoint{ServiceName: raw.ServiceName()} |
|
|
|
for _, tag := range tags { |
|
|
|
for _, tag := range tags { |
|
|
@ -65,13 +65,32 @@ func (r *report) WriteSpan(raw *trace.Span) (err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for _, lg := range logs { |
|
|
|
//log save to zipkin annotation
|
|
|
|
span.Tags[lg.Key] = string(lg.Value) |
|
|
|
span.Annotations = r.converLogsToAnnotations(raw.Logs()) |
|
|
|
} |
|
|
|
|
|
|
|
r.rpt.Send(span) |
|
|
|
r.rpt.Send(span) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r *report) converLogsToAnnotations(logs []*protogen.Log) (annotations []model.Annotation) { |
|
|
|
|
|
|
|
annotations = make([]model.Annotation, 0, len(annotations)) |
|
|
|
|
|
|
|
for _, lg := range logs { |
|
|
|
|
|
|
|
annotations = append(annotations, r.converLogToAnnotation(lg)...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return annotations |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (r *report) converLogToAnnotation(log *protogen.Log) (annotations []model.Annotation) { |
|
|
|
|
|
|
|
annotations = make([]model.Annotation, 0, len(log.Fields)) |
|
|
|
|
|
|
|
for _, field := range log.Fields { |
|
|
|
|
|
|
|
val := string(field.Value) |
|
|
|
|
|
|
|
annotation := model.Annotation{ |
|
|
|
|
|
|
|
Timestamp: time.Unix(0, log.Timestamp), |
|
|
|
|
|
|
|
Value: field.Key + " : " + val, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
annotations = append(annotations, annotation) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return annotations |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Close close the report.
|
|
|
|
// Close close the report.
|
|
|
|
func (r *report) Close() error { |
|
|
|
func (r *report) Close() error { |
|
|
|
return r.rpt.Close() |
|
|
|
return r.rpt.Close() |
|
|
|