monkit
monkit copied to clipboard
reparent orphaned spans to grandparents
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.