Azure App Configuration key values not getting refreshed at runtime
Hi,
I have built a simple Microsoft custom engine copilot using Teams AI library in C#
I tried to integrate with Azure App Configuration into this app with below code snippet in my Program.cs
//More about sentinel configuration key -
//https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-aspnet-core#add-a-sentinel-key
builder.Configuration.AddAzureAppConfiguration(options =>
options
.Connect(new Uri(appConfiguration.AzureAppConfiguration.Url), tokenCredential)
.Select(KeyFilter.Any, appConfiguration.AzureAppConfiguration.EnvironmentLabel)
.ConfigureRefresh(refreshOptions =>
refreshOptions
.Register("TestApp:SentinelKey", appConfiguration.AzureAppConfiguration.EnvironmentLabel, refreshAll: true)
.SetRefreshInterval(TimeSpan.FromSeconds(5))));
builder.Services.AddAzureAppConfiguration();
builder.Services.Configure<AzureADApplication>(builder.Configuration.GetSection(Constants.AppConfigurationPrefix.AzureADApplication));
And then later in the same Program.cs file -
WebApplication app = builder.Build();
app.UseAzureAppConfiguration();
Class definition of AzureADApplication -
public class AzureADApplication
{
public string Type { get; set; }
}
Using it like below in the Bot Action code -
public CustomCopilotBotActions(
IOptionsSnapshot<AzureADApplication> appConfiguration,
IServiceProvider serviceProvider)
{
this.appConfiguration = appConfiguration.Value;
}
Created App Configuration resource in Azure which has a sample configuration like
- Key: "AzureADApplication:Type", Value: "abc", Label: "DEV"
- Key: "TestApp:SentinelKey", Value: "1", Label: "DEV"
Everything works fine when application starts-up (Bot side loaded in Teams), I could see the values loaded into "appConfiguration" in the constructor above. However, if I change the value in "AzureADApplication:Type" on Azure and then update the sentinel key as well, the next request to the application (even after 5, 10 etc. seconds) doesn't get this reflected value in "Type" property of appConfiguration in the constructor above (the constructor gets called of-course for every request).
It works fine with the sample application with console/webapp provided as part of Azure App Configuration documentation but not in this. Not sure what I'm missing here. Could this be specifically related to Bot and/or Teams AI Library SDK? Doesn't think so. Thoughts?
Hi @virtual-deepak, just wanted to clarify something. When you said the "next request" doesn't get the updated value, do you mean just a singular request, or did you try refreshing a couple of times like it mentions in the App Configuration sample app instructions?
I haven't tried to repro with the entire Teams AI example but when I try to copy your code locally in a sample ASP.NET app I see things working as expected, like you mentioned. If the value in IOptionsSnapshot still isn't changing after 2-3 requests, I can keep looking into it.
Hi @amerjusupovic - Thanks for your response. By "next request", you can consider as next HTTP request. I didn't quite get what you mean by "refreshing couple of times" - could you point me to the sample app instructions which you are alluding to?
As mentioned, it's working for sample ASP.Net core standalone app as well but for some reason not in the Teams AI Bot one. Not sure if it has something related to Bot. You can give it a try with a sample Teams AI Library Bot with steps mentioned in docs.
Let me know if you need further info on this.
Thanks!
I've been getting an error message while trying to "Prepare Teams App Dependencies" for some reason, sorry for the delay. I can try to troubleshoot this again later since I can't tell what the issue is just by looking at the project at the moment.