Skip to content

Missing parent trace activities (spans) when switching context between SDK and CLI #2803

Description

@alexander-ivanov-ds

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:

Image

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. 😞

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions