swarm/tracing: Add context key constants

This commit is contained in:
lash 2019-02-11 18:14:11 +01:00
parent d7ab444aec
commit bfd3346532
2 changed files with 11 additions and 6 deletions

View file

@ -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,

View file

@ -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
@ -117,7 +121,8 @@ 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
@ -125,11 +130,11 @@ func StartSaveSpan(ctx context.Context) context.Context {
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
}