diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index 0d9ac511ee..bf59beac6f 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -97,22 +97,23 @@ static async Task GetWeatherAsync([Description("The location to get the return $"The weather in {location} is cloudy with a high of 15°C."; } -// To ensure chat client's function calling is captured in the open telemetry, the chat client needs to have UseOpenTelemetry after UseFunctionInvocation using var instrumentedChatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) .AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient .AsBuilder() .UseFunctionInvocation() - .UseOpenTelemetry(sourceName: SourceName, configure: (cfg) => cfg.EnableSensitiveData = true) + .UseOpenTelemetry(sourceName: SourceName, configure: (cfg) => cfg.EnableSensitiveData = true) // enable telemetry at the chat client level .Build(); appLogger.LogInformation("Creating Agent with OpenTelemetry instrumentation"); // Create the agent with the instrumented chat client -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(SourceName); // Enable telemetry on the agent +var agent = new ChatClientAgent(instrumentedChatClient, + name: "OpenTelemetryDemoAgent", + instructions: "You are a helpful assistant that provides concise and informative responses.", + tools: [AIFunctionFactory.Create(GetWeatherAsync)]) + .AsBuilder() + .UseOpenTelemetry(SourceName) // enable telemetry at the agent level + .Build(); var thread = agent.GetNewThread(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs index 7b34815cdf..dea7d03599 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs @@ -25,12 +25,12 @@ using var tracerProvider = Sdk.CreateTracerProviderBuilder() .Build(); // Create the agent, and enable OpenTelemetry instrumentation. -AIAgent agent = new AzureOpenAIClient( - new Uri(endpoint), - new AzureCliCredential()) - .GetChatClient(deploymentName) - .CreateAIAgent(JokerInstructions, JokerName) - .WithOpenTelemetry(sourceName: sourceName); +AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) + .GetChatClient(deploymentName) + .CreateAIAgent(JokerInstructions, JokerName) + .AsBuilder() + .UseOpenTelemetry(sourceName: sourceName) + .Build(); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs b/dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs index d1850738a1..bc8c788495 100644 --- a/dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs @@ -13,25 +13,6 @@ namespace Microsoft.Agents.AI; /// public static class AgentExtensions { - /// - /// Wraps the agent with OpenTelemetry instrumentation. - /// - /// The agent to wrap. - /// An optional source name that will be used on the telemetry data. - /// When indicates whether potentially sensitive information should be included in telemetry. Default is - /// An that wraps the original agent with telemetry. - public static OpenTelemetryAgent WithOpenTelemetry(this AIAgent agent, string? sourceName = null, bool? enableSensitiveData = null) - { - OpenTelemetryAgent otel = new(agent, sourceName); - - if (enableSensitiveData is not null) - { - otel.EnableSensitiveData = enableSensitiveData.Value; - } - - return otel; - } - /// /// Creates a that will invoke the provided Agent. ///