1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-24 22:26:54 +02:00

add trace to handler

This commit is contained in:
Asim Aslam
2020-01-24 21:29:29 +00:00
parent 8d2dc8a822
commit 49cc022ca2
4 changed files with 282 additions and 28 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/micro/go-micro/debug/log"
proto "github.com/micro/go-micro/debug/service/proto"
"github.com/micro/go-micro/debug/stats"
"github.com/micro/go-micro/debug/trace"
"github.com/micro/go-micro/server"
)
@ -23,6 +24,8 @@ type Debug struct {
log log.Log
// the stats collector
stats stats.Stats
// the tracer
trace trace.Trace
}
func newDebug() *Debug {
@ -60,6 +63,27 @@ func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.S
return nil
}
func (d *Debug) Trace(ctx context.Context, req *proto.TraceRequest, rsp *proto.TraceResponse) error {
traces, err := d.trace.Read(trace.ReadTrace(req.Id))
if err != nil {
return err
}
for _, trace := range traces {
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,
})
}
return nil
}
func (d *Debug) Log(ctx context.Context, stream server.Stream) error {
req := new(proto.LogRequest)
if err := stream.Recv(req); err != nil {