Trace type is now being recorded (#1188)
This commit is contained in:
parent
79ad1e6fe3
commit
d76baf59de
@ -66,15 +66,23 @@ func (d *Debug) Trace(ctx context.Context, req *proto.TraceRequest, rsp *proto.T
|
||||
return err
|
||||
}
|
||||
|
||||
for _, trace := range traces {
|
||||
for _, t := range traces {
|
||||
var typ proto.SpanType
|
||||
switch t.Type {
|
||||
case trace.SpanTypeRequestInbound:
|
||||
typ = proto.SpanType_INBOUND
|
||||
case trace.SpanTypeRequestOutbound:
|
||||
typ = proto.SpanType_OUTBOUND
|
||||
}
|
||||
rsp.Spans = append(rsp.Spans, &proto.Span{
|
||||
Trace: trace.Trace,
|
||||
Id: trace.Id,
|
||||
Parent: trace.Parent,
|
||||
Name: trace.Name,
|
||||
Started: uint64(trace.Started.UnixNano()),
|
||||
Duration: uint64(trace.Duration.Nanoseconds()),
|
||||
Metadata: trace.Metadata,
|
||||
Trace: t.Trace,
|
||||
Id: t.Id,
|
||||
Parent: t.Parent,
|
||||
Name: t.Name,
|
||||
Started: uint64(t.Started.UnixNano()),
|
||||
Duration: uint64(t.Duration.Nanoseconds()),
|
||||
Type: typ,
|
||||
Metadata: t.Metadata,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,31 @@ var _ = math.Inf
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type SpanType int32
|
||||
|
||||
const (
|
||||
SpanType_INBOUND SpanType = 0
|
||||
SpanType_OUTBOUND SpanType = 1
|
||||
)
|
||||
|
||||
var SpanType_name = map[int32]string{
|
||||
0: "INBOUND",
|
||||
1: "OUTBOUND",
|
||||
}
|
||||
|
||||
var SpanType_value = map[string]int32{
|
||||
"INBOUND": 0,
|
||||
"OUTBOUND": 1,
|
||||
}
|
||||
|
||||
func (x SpanType) String() string {
|
||||
return proto.EnumName(SpanType_name, int32(x))
|
||||
}
|
||||
|
||||
func (SpanType) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dea322649cde1ef2, []int{0}
|
||||
}
|
||||
|
||||
type HealthRequest struct {
|
||||
// optional service name
|
||||
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
|
||||
@ -466,6 +491,7 @@ type Span struct {
|
||||
Duration uint64 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration,omitempty"`
|
||||
// associated metadata
|
||||
Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Type SpanType `protobuf:"varint,8,opt,name=type,proto3,enum=SpanType" json:"type,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@ -545,7 +571,15 @@ func (m *Span) GetMetadata() map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Span) GetType() SpanType {
|
||||
if m != nil {
|
||||
return m.Type
|
||||
}
|
||||
return SpanType_INBOUND
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("SpanType", SpanType_name, SpanType_value)
|
||||
proto.RegisterType((*HealthRequest)(nil), "HealthRequest")
|
||||
proto.RegisterType((*HealthResponse)(nil), "HealthResponse")
|
||||
proto.RegisterType((*StatsRequest)(nil), "StatsRequest")
|
||||
@ -564,40 +598,43 @@ func init() {
|
||||
}
|
||||
|
||||
var fileDescriptor_dea322649cde1ef2 = []byte{
|
||||
// 553 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd4, 0x30,
|
||||
0x10, 0xde, 0x24, 0x9b, 0xdd, 0xcd, 0xb4, 0x09, 0xc8, 0xfc, 0x28, 0x0a, 0x08, 0x2a, 0x9f, 0x16,
|
||||
0x01, 0x5e, 0x28, 0x17, 0x04, 0x57, 0x90, 0x38, 0x94, 0x8b, 0xcb, 0x0b, 0xb8, 0x89, 0x95, 0x06,
|
||||
0x9a, 0x38, 0xd8, 0x4e, 0xa5, 0x7d, 0x24, 0x6e, 0xbc, 0x0c, 0x6f, 0xc3, 0x01, 0xf9, 0x27, 0xdb,
|
||||
0x44, 0x08, 0xf5, 0xc0, 0xcd, 0xdf, 0xe7, 0xf1, 0x97, 0x99, 0x6f, 0x66, 0x02, 0xa4, 0x6d, 0x4a,
|
||||
0x29, 0x76, 0xb5, 0x78, 0xe9, 0x0e, 0x15, 0xbf, 0x18, 0xea, 0x9d, 0xe2, 0xf2, 0xba, 0x29, 0xf9,
|
||||
0xae, 0x97, 0x42, 0x7b, 0x8e, 0xd8, 0x33, 0x7e, 0x06, 0xe9, 0x27, 0xce, 0xae, 0xf4, 0x25, 0xe5,
|
||||
0xdf, 0x07, 0xae, 0x34, 0xca, 0x61, 0xed, 0xa3, 0xf3, 0xe0, 0x24, 0xd8, 0x26, 0x74, 0x84, 0x78,
|
||||
0x0b, 0xd9, 0x18, 0xaa, 0x7a, 0xd1, 0x29, 0x8e, 0x1e, 0xc2, 0x4a, 0x69, 0xa6, 0x07, 0xe5, 0x43,
|
||||
0x3d, 0xc2, 0x5b, 0x38, 0x3e, 0xd7, 0x4c, 0xab, 0xdb, 0x35, 0x7f, 0x05, 0x90, 0xfa, 0x50, 0xaf,
|
||||
0xf9, 0x18, 0x12, 0xdd, 0xb4, 0x5c, 0x69, 0xd6, 0xf6, 0x36, 0x7a, 0x49, 0x6f, 0x08, 0xab, 0xa4,
|
||||
0x99, 0xd4, 0xbc, 0xca, 0x43, 0x7b, 0x37, 0x42, 0x93, 0xcb, 0xd0, 0x9b, 0xc0, 0x3c, 0xb2, 0x17,
|
||||
0x1e, 0x19, 0xbe, 0xe5, 0xad, 0x90, 0xfb, 0x7c, 0xe9, 0x78, 0x87, 0x8c, 0x92, 0xbe, 0x94, 0x9c,
|
||||
0x55, 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||||
0x20, 0x56, 0x3d, 0xeb, 0xcc, 0xa0, 0x99, 0xbc, 0x63, 0x72, 0xde, 0xb3, 0x8e, 0x3a, 0x0e, 0xff,
|
||||
0x0e, 0x60, 0x69, 0xb0, 0xf9, 0xa0, 0x36, 0xcf, 0xbc, 0x92, 0x03, 0x5e, 0x3c, 0x1c, 0xc5, 0x8d,
|
||||
0xe7, 0x3d, 0x93, 0xdc, 0x9b, 0x9b, 0x50, 0x8f, 0x10, 0x82, 0x65, 0xc7, 0x5a, 0x67, 0x6e, 0x42,
|
||||
0xed, 0x79, 0x3a, 0x6f, 0xf1, 0x7c, 0xde, 0x0a, 0xd8, 0x54, 0x83, 0x64, 0xba, 0x11, 0x9d, 0x9f,
|
||||
0x95, 0x03, 0x46, 0xbb, 0x89, 0xd1, 0x6b, 0x9b, 0xf0, 0x3d, 0x9b, 0xf0, 0xbf, 0x6c, 0xfe, 0x2f,
|
||||
0x33, 0x4f, 0x7f, 0x04, 0x10, 0x7f, 0x30, 0x2b, 0x8d, 0x9e, 0x42, 0x74, 0x26, 0x6a, 0x74, 0x44,
|
||||
0x6e, 0x66, 0xaf, 0x58, 0xfb, 0x16, 0xe3, 0xc5, 0xab, 0x00, 0x3d, 0x87, 0x95, 0x5b, 0x61, 0x94,
|
||||
0x91, 0xd9, 0xda, 0x17, 0x77, 0xc8, 0x7c, 0xb7, 0xf1, 0x02, 0x6d, 0x21, 0xb6, 0xab, 0x89, 0x52,
|
||||
0x32, 0xdd, 0xe6, 0x22, 0x23, 0xb3, 0x8d, 0x75, 0x91, 0xb6, 0x5d, 0x28, 0x25, 0xd3, 0xb6, 0x16,
|
||||
0x19, 0x99, 0x75, 0x11, 0x2f, 0x2e, 0x56, 0xf6, 0xaf, 0xf3, 0xe6, 0x4f, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0xc7, 0x3f, 0xbe, 0xe3, 0xa7, 0x04, 0x00, 0x00,
|
||||
// 595 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x54, 0x5b, 0x6e, 0xd3, 0x40,
|
||||
0x14, 0x8d, 0x63, 0x3b, 0x71, 0x6e, 0x1e, 0x54, 0xc3, 0x43, 0x56, 0x78, 0xca, 0x12, 0x52, 0x78,
|
||||
0x39, 0x10, 0x7e, 0x10, 0xfc, 0xa1, 0x22, 0x81, 0x04, 0xad, 0x34, 0x4d, 0x17, 0x30, 0xb5, 0x47,
|
||||
0xa9, 0xa1, 0xf6, 0x98, 0x99, 0x71, 0xa5, 0xac, 0x85, 0x15, 0xf0, 0xc7, 0x66, 0xd8, 0x0f, 0xf3,
|
||||
0x72, 0x1a, 0x0b, 0xa1, 0x7e, 0xf0, 0x77, 0xcf, 0xf5, 0x99, 0x33, 0xf7, 0x9e, 0x9c, 0x0c, 0xa4,
|
||||
0x65, 0x91, 0x71, 0xb6, 0xdc, 0xb0, 0x17, 0xb6, 0xc8, 0xe9, 0x59, 0xb3, 0x59, 0x0a, 0xca, 0x2f,
|
||||
0x8b, 0x8c, 0x2e, 0x6b, 0xce, 0xa4, 0xeb, 0xa5, 0xa6, 0x4e, 0x9e, 0xc0, 0xf4, 0x23, 0x25, 0x17,
|
||||
0xf2, 0x1c, 0xd3, 0xef, 0x0d, 0x15, 0x12, 0xc5, 0x30, 0x74, 0xec, 0xd8, 0x7b, 0xe4, 0x2d, 0x46,
|
||||
0xb8, 0x85, 0xc9, 0x02, 0x66, 0x2d, 0x55, 0xd4, 0xac, 0x12, 0x14, 0xdd, 0x81, 0x81, 0x90, 0x44,
|
||||
0x36, 0xc2, 0x51, 0x1d, 0x52, 0xcc, 0xc9, 0x89, 0xaa, 0xc4, 0xf5, 0x9a, 0xbf, 0x3d, 0x98, 0x3a,
|
||||
0xaa, 0xd3, 0xbc, 0x07, 0x23, 0x59, 0x94, 0xea, 0x14, 0x29, 0x6b, 0xc3, 0x0e, 0xf0, 0x55, 0xc3,
|
||||
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, 0x05, 0x25, 0xe9,
|
||||
0xbd, 0xf4, 0xd0, 0x33, 0x18, 0xd8, 0x87, 0x00, 0xcd, 0xd2, 0xce, 0xe3, 0x31, 0xbf, 0x91, 0x76,
|
||||
0x5f, 0x88, 0xa4, 0x87, 0x16, 0x10, 0x9a, 0x3f, 0x38, 0x9a, 0xa6, 0xfb, 0x6f, 0xc2, 0x7c, 0x96,
|
||||
0x76, 0xfe, 0xf7, 0x96, 0x69, 0x7e, 0x74, 0xc5, 0xdc, 0x0f, 0x87, 0x62, 0x76, 0xb2, 0x90, 0xf4,
|
||||
0xce, 0x06, 0xe6, 0xed, 0x7a, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xbc, 0xab, 0x72, 0x03, 0xed,
|
||||
0x04, 0x00, 0x00,
|
||||
}
|
||||
|
@ -57,12 +57,12 @@ message LogRequest {
|
||||
|
||||
// Record is service log record
|
||||
message Record {
|
||||
// timestamp of log record
|
||||
int64 timestamp = 1;
|
||||
// record metadata
|
||||
map<string,string> metadata = 2;
|
||||
// message
|
||||
string message = 3;
|
||||
// timestamp of log record
|
||||
int64 timestamp = 1;
|
||||
// record metadata
|
||||
map<string,string> metadata = 2;
|
||||
// message
|
||||
string message = 3;
|
||||
}
|
||||
|
||||
message TraceRequest {
|
||||
@ -75,6 +75,11 @@ message TraceResponse {
|
||||
}
|
||||
|
||||
|
||||
enum SpanType {
|
||||
INBOUND = 0;
|
||||
OUTBOUND = 1;
|
||||
}
|
||||
|
||||
message Span {
|
||||
// the trace id
|
||||
string trace = 1;
|
||||
@ -90,4 +95,5 @@ message Span {
|
||||
uint64 duration = 6;
|
||||
// associated metadata
|
||||
map<string,string> metadata = 7;
|
||||
SpanType type = 8;
|
||||
}
|
||||
|
@ -3,8 +3,9 @@ package trace
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
)
|
||||
|
||||
// Tracer is an interface for distributed tracing
|
||||
@ -17,6 +18,16 @@ type Tracer interface {
|
||||
Read(...ReadOption) ([]*Span, error)
|
||||
}
|
||||
|
||||
// SpanType describe the nature of the trace span
|
||||
type SpanType int
|
||||
|
||||
const (
|
||||
// SpanTypeRequestInbound is a span created when serving a request
|
||||
SpanTypeRequestInbound SpanType = iota
|
||||
// SpanTypeRequestOutbound is a span created when making a service call
|
||||
SpanTypeRequestOutbound
|
||||
)
|
||||
|
||||
// Span is used to record an entry
|
||||
type Span struct {
|
||||
// Id of the trace
|
||||
@ -33,6 +44,8 @@ type Span struct {
|
||||
Duration time.Duration
|
||||
// associated data
|
||||
Metadata map[string]string
|
||||
// Type
|
||||
Type SpanType
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -63,6 +63,7 @@ func (c *clientWrapper) Publish(ctx context.Context, p client.Message, opts ...c
|
||||
func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
newCtx, s := c.trace.Start(ctx, req.Service()+"."+req.Endpoint())
|
||||
|
||||
s.Type = trace.SpanTypeRequestOutbound
|
||||
err := c.Client.Call(newCtx, req, rsp, opts...)
|
||||
if err != nil {
|
||||
s.Metadata["error"] = err.Error()
|
||||
@ -122,6 +123,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper {
|
||||
|
||||
// get the span
|
||||
newCtx, s := t.Start(ctx, req.Service()+"."+req.Endpoint())
|
||||
s.Type = trace.SpanTypeRequestInbound
|
||||
|
||||
err := h(newCtx, req, rsp)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user