We are using Copilot SDK for .NET and it seems like the thinking behind RestoreTraceContext (this) is not entirely correct. It creates a new Activity without the ActivitySource, which, indeed, prevents it from being sampled, but it still carries its own id (span id), which is then used as a parent span id for all children activities. So in the trace tree (In Grafana, for example) we see unparented spans from the tool implementations, which I think should be parented under external_tool spans from the Copilot CLI:
the GET span (id d2c10abb001cb97a) has parent span id set to cabcf362cbf15a7a (which is nowhere to be found), where as external_tool span has an id of 2cd84acd8fb4e994. So, I think, the tree is:
external_tool (2cd84acd8fb4e994, from CLI)
\ copilot.tool_handler (cabcf362cbf15a7a, from SDK) <--- "invisible activity"
\ GET (d2c10abb001cb97a, from our tool code)
Why don't we just emit this span properly from ActivitySource (maybe matching SourceName/default github.copilot)?
I also think a similar problem exists in the CLI itself, because transitioning from SDK to CLI also leaves all "top-level" CLI spans unparented. CLI code doesn't seem to be open source, so I can't confirm, but my gut feeling is that a similar approach was used there in CLI, where it creates one span and doesn't attach it to a source that is being sampled/exported, so it never gets collected, leaving all other CLI spans unparented. 😞
We are using Copilot SDK for .NET and it seems like the thinking behind
RestoreTraceContext(this) is not entirely correct. It creates a newActivitywithout theActivitySource, which, indeed, prevents it from being sampled, but it still carries its own id (span id), which is then used as a parent span id for all children activities. So in the trace tree (In Grafana, for example) we see unparented spans from the tool implementations, which I think should be parented underexternal_toolspans from the Copilot CLI:the
GETspan (idd2c10abb001cb97a) has parent span id set tocabcf362cbf15a7a(which is nowhere to be found), where asexternal_toolspan has an id of2cd84acd8fb4e994. So, I think, the tree is:Why don't we just emit this span properly from
ActivitySource(maybe matching SourceName/defaultgithub.copilot)?I also think a similar problem exists in the CLI itself, because transitioning from SDK to CLI also leaves all "top-level" CLI spans unparented. CLI code doesn't seem to be open source, so I can't confirm, but my gut feeling is that a similar approach was used there in CLI, where it creates one span and doesn't attach it to a source that is being sampled/exported, so it never gets collected, leaving all other CLI spans unparented. 😞