semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Bug: ChatCompletionAgent tracing not emitting agent details

Open ahusseini opened this issue 5 months ago • 2 comments

Describe the bug The ChatCompletionAgent is not emitting agent telemetry details, it is only emitting tracing for the chat_completion operation.

To Reproduce Steps to reproduce the behavior:

  1. Setup OpenTelemetry Console sample: https://learn.microsoft.com/en-us/semantic-kernel/concepts/enterprise-readiness/observability/telemetry-with-console?tabs=Powershell-CreateFile,EnvironmentFile&pivots=programming-language-csharp
  2. Replace kernel invocation with:
var agent = new ChatCompletionAgent
{
    Name = "Conference Room Agent",
    Kernel = kernel,
    Arguments = new KernelArguments(
        new OpenAIPromptExecutionSettings {
            ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
        }
    )
};

ChatHistoryAgentThread agentThread = new();

var message = new ChatMessageContent(AuthorRole.User, "Reserve a conference room for me today.");
await foreach (ChatMessageContent response in agent.InvokeAsync(message, agentThread))
{
    Console.WriteLine("Answer: " + response.Content);
}
  1. Observe gen_ai.operation.name is chat.completions and no gen_ai.agent.name is output.

Expected behavior ChatCompletionAgent should be calling ModelDiagnostics.StartAgentInvocationActivity similar to AzureAIAgent and OpenAIAssistantAgent

Platform

  • Language: C#
  • Source: NuGet 1.61.0
  • AI model: All models (using Azure OpenAI GPT 4.1)
  • IDE: Rider
  • OS: Mac

Additional context

  • seems this isn't called: https://github.com/microsoft/semantic-kernel/blob/d5ee6aa1c176a4b860aba72edaa961570874661b/dotnet/src/Agents/Core/ChatCompletionAgent.cs#L162

  • telemetry console exporter output

Activity.TraceId:            a9789e291cd884d3043831adea2acf59
Activity.SpanId:             fe8a508e0c09b1cc
Activity.TraceFlags:         Recorded
Activity.DisplayName:        chat.completions mq-develop-gpt-4o-mini
Activity.Kind:               Client
Activity.StartTime:          2025-07-24T19:53:28.4987000Z
Activity.Duration:           00:00:01.4005670
Activity.Tags:
    gen_ai.operation.name: chat.completions
    gen_ai.system: openai
    gen_ai.request.model: mq-develop-gpt-4o-mini
    gen_ai.usage.input_tokens: 72
    gen_ai.usage.output_tokens: 16
    gen_ai.response.finish_reason: ["ToolCalls"]
    gen_ai.response.id: chatcmpl-BwwILU8JG0wqSTF7vk6rZDF7BNihv

ahusseini avatar Jul 24 '25 20:07 ahusseini

@dmytrostruk - I believe you are familiar with tracing expectations for agents. Could you please respond to this ask?

crickman avatar Jul 29 '25 15:07 crickman

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Oct 28 '25 02:10 github-actions[bot]