Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swarm/tracing: Add context key constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nolash committed Feb 11, 2019
1 parent a1bee28 commit 46525b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions swarm/network/stream/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (

// setting this value in the context creates a new span that can persist across the sendpriority queue and the network roundtrip
// this span will finish only when delivery is handled (or times out)
ctx = context.WithValue(ctx, "stream_send_tag", "stream.send.request")
ctx = context.WithValue(ctx, "stream_send_meta", fmt.Sprintf("%v.%v", sp.ID(), req.Addr))
ctx = context.WithValue(ctx, tracing.StoreLabelId, "stream.send.request")
ctx = context.WithValue(ctx, tracing.StoreLabelMeta, fmt.Sprintf("%v.%v", sp.ID(), req.Addr))
err := sp.SendPriority(ctx, &RetrieveRequestMsg{
Addr: req.Addr,
SkipCheck: req.SkipCheck,
Expand Down
13 changes: 9 additions & 4 deletions swarm/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var (
)

// TracingEnabledFlag is the CLI flag name to use to enable trace collections.
const TracingEnabledFlag = "tracing"
const (
TracingEnabledFlag = "tracing"
StoreLabelId = "span_save_id"
StoreLabelMeta = "span_save_meta"
)

var (
Closer io.Closer
Expand Down Expand Up @@ -117,19 +121,20 @@ func StartSaveSpan(ctx context.Context) context.Context {
if !Enabled {
return ctx
}
traceId := ctx.Value("span_save_id")
traceId := ctx.Value(StoreLabelId)

if traceId != nil {
traceStr := traceId.(string)
var sp opentracing.Span
ctx, sp = spancontext.StartSpan(
ctx,
traceStr,
)
traceMeta := ctx.Value("span_save_meta")
traceMeta := ctx.Value(StoreLabelMeta)
if traceMeta != nil {
traceStr = traceStr + "." + traceMeta.(string)
}
store.spans.Store(traceId, sp)
store.spans.Store(traceStr, sp)
}
return ctx
}
Expand Down

0 comments on commit 46525b3

Please sign in to comment.