Microsoft.Extensions.AI Integration
Updated on Aug 14, 2026
Use this integration when your app is implemented in .NET.
Setup
- Install SDK
bash
dotnet add package Progress.Observability.Instrumentation
- Instrument your app
cs
try
{
chatClient = chatClient.AddObservability((options) =>
{
options.AppName = Environment.GetEnvironmentVariable("OBSERVABILITY_APP_NAME")!;
options.ApiKey = Environment.GetEnvironmentVariable("OBSERVABILITY_API_KEY")!;
});
// Your code here.
}
finally
{
// Call the Shutdown() method before exiting your agent to flush any remaining data.
ObservabilityTracer.Shutdown();
}
- Complete example
cs
using Microsoft.Extensions.AI;
using OpenAI;
using System.ComponentModel;
using Progress.Observability.Extensions.AI;
using DotNetEnv;
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
=> $"The weather in {location} is cloudy with a high of 15°C.";
try {
Env.Load(".env");
IChatClient chatClient = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!)
.GetChatClient("gpt-4o-mini")
.AsIChatClient()
// LLM INSTRUMENTATION
.AddObservability((options) =>
{
options.AppName = "Microsoft Extensions AI";
options.ApiKey = Environment.GetEnvironmentVariable("OBSERVABILITY_API_KEY")!;
})
.AsBuilder()
.UseFunctionInvocation()
.Build();
ChatOptions options = new() { Tools = [AIFunctionFactory.Create(GetWeather)] };
// Optional: with UseFunctionInvocation in the chain, tool spans are already
// captured. AddToolObservability() is for tools you dispatch yourself.
// options.AddToolObservability();
Console.WriteLine(await chatClient.GetResponseAsync("What is the weather like in Amsterdam?", options));
}
finally
{
ObservabilityTracer.Shutdown();
}