monkit icon indicating copy to clipboard operation
monkit copied to clipboard

reparent orphaned spans to grandparents

Open zeebo opened this issue 3 years ago • 0 comments

Consider code like

func Foo(ctx context.Context) (err error) {
    defer mon.Task()(&ctx)(&err)
    stream := Bar(ctx)
    stream.RPC()
    stream.RPC()
    return nil
}

func Bar(ctx context.Context) (Stream) {
    defer mon.Task()(&ctx)(nil)
    return newStream(ctx)
}

where the Stream type internally stores the context passed to it for the RPC invocations. Arguably, this code doesn't use contexts correctly because the RPCs should be passed the ctx, but this is how gRPC works.

Because the Stream context is a child of the Bar context that is exited, the RPC invocations, if monitored, will be considered orphaned. Instead, this change makes it so that they are parented by Foo.

The tree of spans will become something closer to a DAG, but it should be the case that there is only one reachable path to a child at a time through non-done spans.

zeebo avatar Dec 15 '20 17:12 zeebo