Skip to content

.NET: [Bug]: OTel is not emitted when invoking agent through AGUI #4928

@viul-sc

Description

@viul-sc

Description

STR:

  1. Attach Otel
        ResourceBuilder resourceBuilder = ResourceBuilder.CreateDefault()
            .AddService("a2a-poc-service");
        _tracerProvider = Sdk.CreateTracerProviderBuilder()
            .SetResourceBuilder(resourceBuilder)
            .AddSource(SourceName)
            .AddSource("*Microsoft.Extensions.AI") // Listen to the Experimental.Microsoft.Extensions.AI source for chat client telemetry.
            .AddSource("*Microsoft.Extensions.Agents*") // Listen to the Experimental.Microsoft.Extensions.Agents source for agent telemetry.
            .AddConsoleExporter()
            ////.AddAzureMonitorTraceExporter(options => options.ConnectionString = config.GetRequired("APPLICATION_INSIGHTS_CONNECTION_STRING"))
            .Build();
  1. Create AI Agent:
AIAgent agent = _chatClient
            .AsAIAgent(
                name: Name,
                description: Description,
                instructions: Instructions,
                tools: _toolRepository.Tools)
            .AsBuilder()
            .UseOpenTelemetry(sourceName: _otelConfig.SourceName)
            .Build();

app.MapAGUI("/", agent);
  1. Invoke an agent through AGUI:
AGUIChatClient chatClient = new(new(), "http://localhost:5001");
AIAgent aguiAgent = chatClient.AsAIAgent();
await foreach (AgentResponseUpdate update in aguiAgent.RunStreamingAsync("Tell me a joke about a pirate."))
{
    Console.Write(update);
}
Console.WriteLine();

Expected:
OTel Telemetry logged to console.

Actual:
No telemetry logged:

Image

Note:
If calling the same agent directly

await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("Tell me a joke about a pirate."))
{
    Console.Write(update);
}
Console.WriteLine();

Then telemetry logged as expected:

Image

Code Sample

<PackageReference Include="Microsoft.Agents.AI.A2A" Version="1.0.0-preview.260311.1" />
	  <PackageReference Include="Microsoft.Agents.AI.AGUI" Version="1.0.0-preview.260311.1" />
	  <PackageReference Include="Microsoft.Agents.AI.DevUI" Version="1.0.0-preview.260311.1" />
	  <PackageReference Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.0.0-preview.260311.1" />
	  <PackageReference Include="Microsoft.Extensions.AI" Version="10.4.1" />

Error Messages / Stack Traces

Package Versions

1.0.0-preview.260311.1

.NET Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions