Skip to content

Commit

Permalink
Merge pull request filecoin-project#6 from ipfs-force-community/feat/…
Browse files Browse the repository at this point in the history
…jeager-trace

fix:returns nil span
  • Loading branch information
hunjixin authored Jul 21, 2021
2 parents e4697ca + d77b489 commit 4ad25df
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,19 @@ func doCall(methodName string, f reflect.Value, params []reflect.Value) (out []r
return out, nil
}

func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context, *trace.Span) {
func (s *RPCServer) getSpan(ctx context.Context, req request) (spCtx context.Context, span *trace.Span) {
defer func() {
if span == nil {
spCtx, span = trace.StartSpan(ctx, "api.handle")
}
span.AddAttributes(trace.StringAttribute("method", req.Method))
fmt.Printf("spanid:%s\n", span.SpanContext().SpanID)
}()

if req.Meta == nil {
return ctx, nil
return
}
var spanCtx context.Context
var span *trace.Span

if eSC, ok := req.Meta["SpanContext"]; ok {
bSC := make([]byte, base64.StdEncoding.DecodedLen(len(eSC)))
_, err := base64.StdEncoding.Decode(bSC, []byte(eSC))
Expand All @@ -238,14 +245,9 @@ func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context,
log.Errorf("SpanContext: could not create span", "data", bSC)
return ctx, nil
}
spanCtx, span = trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
} else {
spanCtx, span = trace.StartSpan(ctx, "api.handle")
spCtx, span = trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
}

span.AddAttributes(trace.StringAttribute("method", req.Method))

return spanCtx, span
return
}

func (s *RPCServer) handle(ctx context.Context, req request, w func(func(io.Writer)), rpcError rpcErrFunc, done func(keepCtx bool), chOut chanOut) {
Expand Down

0 comments on commit 4ad25df

Please sign in to comment.