未验证 提交 3de27ea6 编写于 作者: Z zhang-wei 提交者: GitHub

fix entryEndpointId & parentEndpointId bug (#44)

* fix ParentEndpointID bug

* language
上级 f10048c7
......@@ -29,6 +29,10 @@ type NoopSpan struct {
func (*NoopSpan) SetOperationName(string) {
}
func (*NoopSpan) GetOperationName() string {
return ""
}
func (*NoopSpan) SetPeer(string) {
}
......@@ -49,3 +53,11 @@ func (*NoopSpan) Error(time.Time, ...string) {
func (*NoopSpan) End() {
}
func (*NoopSpan) IsEntry() bool {
return false
}
func (*NoopSpan) IsExit() bool {
return false
}
......@@ -181,7 +181,7 @@ func globalIDConvertString(id []int64) string {
}
func encodeCompressedField(id int32, text string) string {
if id > 0 {
if id != 0 {
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprint(id)))
}
return base64.StdEncoding.EncodeToString([]byte("#" + text))
......
......@@ -162,6 +162,11 @@ func (r *gRPCReporter) registerInstance(name string) error {
props = append(props, kv)
}
}
language := &common.KeyStringValuePair{
Key: "language",
Value: "go",
}
props = append(props, language)
in := &register.ServiceInstances{
Instances: []*register.ServiceInstance{
{
......
......@@ -54,6 +54,7 @@ type SegmentContext struct {
collect chan<- ReportedSpan
refNum *int32
spanIDGenerator *int32
FirstSpan Span `json:"-"`
}
func (ctx SegmentContext) GetReadableGlobalTraceID() string {
......@@ -180,6 +181,9 @@ func (s *segmentSpanImpl) createSegmentContext(parent segmentSpan) {
s.ParentSpanID = s.SpanID
s.SpanID = atomic.AddInt32(s.Context().spanIDGenerator, 1)
}
if s.SegmentContext.FirstSpan == nil {
s.SegmentContext.FirstSpan = s
}
}
type rootSegmentSpan struct {
......
......@@ -42,6 +42,7 @@ const (
// Span interface as common span specification
type Span interface {
SetOperationName(string)
GetOperationName() string
SetPeer(string)
SetSpanLayer(common.SpanLayer)
SetComponent(int32)
......@@ -49,6 +50,8 @@ type Span interface {
Log(time.Time, ...string)
Error(time.Time, ...string)
End()
IsEntry() bool
IsExit() bool
}
func newLocalSpan(t *Tracer) *defaultSpan {
......@@ -80,6 +83,10 @@ func (ds *defaultSpan) SetOperationName(name string) {
ds.OperationName = name
}
func (ds *defaultSpan) GetOperationName() string {
return ds.OperationName
}
func (ds *defaultSpan) SetPeer(peer string) {
ds.Peer = peer
}
......@@ -122,6 +129,14 @@ func (ds *defaultSpan) End() {
ds.EndTime = time.Now()
}
func (ds *defaultSpan) IsEntry() bool {
return ds.SpanType == SpanTypeEntry
}
func (ds *defaultSpan) IsExit() bool {
return ds.SpanType == SpanTypeExit
}
// SpanOption allows for functional options to adjust behaviour
// of a Span to be created by CreateLocalSpan
type SpanOption func(s *defaultSpan)
......
......@@ -34,6 +34,8 @@ const (
errParameter = tool.Error("parameter are nil")
EmptyTraceID = "N/A"
NoopTraceID = "[Ignored Trace]"
// -1 represent the object doesn't exist.
Inexistence = -1
)
// Tracer is go2sky tracer implementation.
......@@ -193,17 +195,37 @@ func (t *Tracer) CreateExitSpan(ctx context.Context, operationName string, peer
spanContext.ParentSegmentID = span.Context().SegmentID
spanContext.NetworkAddress = peer
spanContext.ParentServiceInstanceID = t.instanceID
spanContext.EntryServiceInstanceID = t.instanceID
spanContext.EntryEndpoint = operationName
spanContext.ParentEndpoint = operationName
// Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC), rather than an endpoint.
// EntryEndpoint
firstSpan := span.Context().FirstSpan
firstSpanOperationName := firstSpan.GetOperationName()
ref, ok := ctx.Value(refKeyInstance).(*propagation.SpanContext)
var entryEndpoint = ""
var entryServiceInstanceID int32 = 0
if ok && ref != nil {
spanContext.Sample = ref.Sample
spanContext.ParentEndpoint = ref.ParentEndpoint
spanContext.EntryServiceInstanceID = ref.EntryServiceInstanceID
spanContext.EntryEndpoint = ref.EntryEndpoint
spanContext.EntryEndpointID = ref.EntryEndpointID
entryEndpoint = ref.EntryEndpoint
entryServiceInstanceID = ref.EntryServiceInstanceID
} else {
if firstSpan.IsEntry() {
entryEndpoint = firstSpanOperationName
} else {
spanContext.EntryEndpointID = Inexistence
}
entryServiceInstanceID = t.instanceID
}
spanContext.EntryServiceInstanceID = entryServiceInstanceID
if entryEndpoint != "" {
spanContext.EntryEndpoint = entryEndpoint
}
// ParentEndpoint
if firstSpan.IsEntry() && firstSpanOperationName != "" {
spanContext.ParentEndpoint = firstSpanOperationName
} else {
spanContext.ParentEndpointID = Inexistence
}
err = injector(spanContext.EncodeSW6())
if err != nil {
return nil, err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册