.NET: Update OpenTelemetryAgent to latest spec (#967)

* Update OpenTelemetryAgent to latest spec

It was stale. Rather than try to keep it up-to-date manually, I've changed it to piggy back on OpenTelemetryChatClient, so that it inherits everything OpenTelemetryChatClient does and then augments it just with agent-specific tags.

* Address feedback / merge
This commit is contained in:
Stephen Toub
2025-09-30 09:50:01 -04:00
committed by GitHub
Unverified
parent 4fd61924fc
commit 0502f3ef91
10 changed files with 702 additions and 3243 deletions
@@ -103,7 +103,7 @@ using var instrumentedChatClient = new AzureOpenAIClient(new Uri(endpoint), new
.AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient
.AsBuilder()
.UseFunctionInvocation()
.UseOpenTelemetry(loggerFactory: loggerFactory, sourceName: SourceName, (cfg) => cfg.EnableSensitiveData = true)
.UseOpenTelemetry(sourceName: SourceName, configure: (cfg) => cfg.EnableSensitiveData = true)
.Build();
appLogger.LogInformation("Creating Agent with OpenTelemetry instrumentation");
@@ -112,7 +112,7 @@ using var agent = new ChatClientAgent(instrumentedChatClient,
name: "OpenTelemetryDemoAgent",
instructions: "You are a helpful assistant that provides concise and informative responses.",
tools: [AIFunctionFactory.Create(GetWeatherAsync)])
.WithOpenTelemetry(loggerFactory, SourceName); // Enable telemetry on the agent
.WithOpenTelemetry(SourceName); // Enable telemetry on the agent
var thread = agent.GetNewThread();