Go Context tree represented as a directed graph


A simple context tree (containing some common values that might be request scoped and included in a context) built from Go code like the following:

// Pseudo-Go
ctx := context.WithValue(
        context.WithValue(context.Background(), sidKey, sid),
        time.Now().Add(30 * time.Minute),
    ridKey, rid,
trCtx := trace.NewContext(ctx, tr)
logCtx := myRequestLogging.NewContext(ctx, myRequestLogging.NewLogger())

Is a tree that can be represented as a directed graph that looks like this:

Context represented as a directed graph

Each child context has access to the values of its parent contexts, so the data access flows upwards in the tree (represented by black edges). Cancelation signals on the other hand travel down the tree (if a context is canceled, all of its children are also canceled). The cancelation signal flow is represented by the grey edges.