Skip to content

.Net: Bug: ChatCompletionAgent tracing not emitting agent details #12792

@ahusseini

Description

@ahusseini

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETIssue or Pull requests regarding .NET codebugSomething isn't workingtriage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions