Skip to content

Commit 28c59fd

Browse files
authored
Merge pull request #77 from ipfs-force-community/feat/create_new_span_if_not_exit
feat:create new span if not exit a remote span
2 parents 5a1b7aa + cab890e commit 28c59fd

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
@@ -198,6 +198,8 @@ func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context,
198198
if req.Meta == nil {
199199
return ctx, nil
200200
}
201+
202+
var span *trace.Span
201203
if eSC, ok := req.Meta["SpanContext"]; ok {
202204
bSC := make([]byte, base64.StdEncoding.DecodedLen(len(eSC)))
203205
_, err := base64.StdEncoding.Decode(bSC, []byte(eSC))
@@ -210,11 +212,13 @@ func (s *RPCServer) getSpan(ctx context.Context, req request) (context.Context,
210212
log.Errorf("SpanContext: could not create span", "data", bSC)
211213
return ctx, nil
212214
}
213-
ctx, span := trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
214-
span.AddAttributes(trace.StringAttribute("method", req.Method))
215-
return ctx, span
215+
ctx, span = trace.StartSpanWithRemoteParent(ctx, "api.handle", sc)
216+
} else {
217+
ctx, span = trace.StartSpan(ctx, "api.handle")
216218
}
217-
return ctx, nil
219+
220+
span.AddAttributes(trace.StringAttribute("method", req.Method))
221+
return ctx, span
218222
}
219223

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

0 commit comments

Comments
 (0)