Skip to content

Commit cab890e

Browse files
committed
feat:create new span if not exit a remote span
1 parent 236bc02 commit cab890e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

handler.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context,
193193
if req.Meta == nil {
194194
return ctx, nil
195195
}
196+
197+
var span *trace.Span
196198
if eSC, ok := req.Meta["SpanContext"]; ok {
197199
bSC := make([]byte, base64.StdEncoding.DecodedLen(len(eSC)))
198200
_, err := base64.StdEncoding.Decode(bSC, []byte(eSC))
@@ -205,11 +207,13 @@ func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context,
205207
log.Errorf("SpanContext: could not create span", "data", bSC)
206208
return ctx, nil
207209
}
208-
ctx, span := trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
209-
span.AddAttributes(trace.StringAttribute("method", req.Method))
210-
return ctx, span
210+
ctx, span = trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
211+
} else {
212+
ctx, span = trace.StartSpan(ctx, "api.handle")
211213
}
212-
return ctx, nil
214+
215+
span.AddAttributes(trace.StringAttribute("method", req.Method))
216+
return ctx, span
213217
}
214218

215219
func (s *RPCServer) createError(err error) *respError {

0 commit comments

Comments
 (0)