You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support updating SDK key at runtime - ideally using Microsoft.Extensions.Options primitives #182
Is your feature request related to a problem? Please describe.
We share our SDK key for a LD project among many components that are deployed.
We would like to be able to easily rotate the SDK key without having to recycle all of those components (across many teams in our organisation!)
Describe the solution you'd like
We're aware that the Launch Darkly SDK goes to some lengths to ensure low latency when calling code evaluates flags.
So ideally, we'd like to stick with a single LD client registered in the IoC container (singleton, as recommended by LD).
However, we would like the client to automatically notice when the SDK key has been updated and seamlessly start using the new key.
The Microsoft.Extensions.Optionsprimitives - in particular IOptionsMonitor would be a good/natural fit for this.
Describe alternatives you've considered
Trying to coordinate recycling of components across multiple teams. We're aware that when a key is rotated, the old key can be kept functional for up to 30 days.
Thank you for the report. We will consider the request and look into options.
The SDK currently isn't designed to allow for runtime changes of any configuration, and changing configuration will likely be similar in performance to initializing a new client instance. Likely equal to a wrapper around the client that detects changing and then initializes a new internal client for the singleton to use.
I've done a proof-of-concept (complete hack job) for this.
At a high-level, it involved a couple of things:
In the LaunchDarkly.EventSource repository, inside EventSourceService::ConnectToEventSourceApi we set (replace) the authorization header by reading from the SDK key current-value from the OptionsMonitor
In StreamingDataSource, register a callback for OptionsMonitor::OnChange that calls IEventSource::Restart(true) - this is the event source created in the StreamingDataSource constructor
With these changes in place and a test harness program, I can swich between two LD projects at runtime - which is a neat party trick 🥳
// Test harness program to demonstrate switching SDK keys at runtimeusingLaunchDarkly.Sdk;usingLaunchDarkly.Sdk.Server;usingMicrosoft.Extensions.Configuration;usingMicrosoft.Extensions.Options;usingSerilog;Log.Logger=newLoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().CreateLogger();Log.Information("Application starting up...");conststringproject1SdkKey="sdk-9271xxx";conststringproject2SdkKey="sdk-73fexxxx";varconfigData=newDictionary<string,string?>{{"LdSettings:SdkKey",project1SdkKey}};varconfig=newMicrosoft.Extensions.Configuration.ConfigurationBuilder().AddInMemoryCollection(configData).Build();varoptionsFactory=newOptionsFactory<LdSettings>(new[]{newConfigureFromConfigurationOptions<LdSettings>(config.GetSection("LdSettings"))},Enumerable.Empty<IPostConfigureOptions<LdSettings>>());varcache=newOptionsCache<LdSettings>();varchangeSource=newConfigurationChangeTokenSource<LdSettings>(config.GetSection("LdSettings"));varmonitor=newOptionsMonitor<LdSettings>(optionsFactory,new[]{changeSource},cache);varldConfigBuilder=Configuration.Builder("SDK key from constructor not used any more!");varldConfig=ldConfigBuilder.Build();ldConfig.SettingsMonitor=monitor;// Quick hack job to plumb the settings monitor in to the LD SDKvarclient=newLdClient(ldConfig);client.FlagTracker.FlagChanged+=(sender,args)=>{varupdatedFlagValue=client.BoolVariation(args.Key,Context.FromUser(User.WithKey("eddie")));Log.Information("SDK Event: Flag '{FlagName}' changed to {newValue}",args.Key,updatedFlagValue);};varquitEvent=newTaskCompletionSource<bool>();Log.Information("Starting main application loop");_=Task.Run(()=>{Log.Information("Listening for 't' key or 'q' to quit...");while(true){varkey=Console.ReadKey(intercept:true);if(key.KeyChar=='t'){if(config["LdSettings:SdkKey"]==project1SdkKey){Log.Information("Switching to project 2");config["LdSettings:SdkKey"]=project2SdkKey;}else{Log.Information("Switching to project 1");config["LdSettings:SdkKey"]=project1SdkKey;}// Notify the monitor that the source has changedconfig.Reload();}elseif(key.KeyChar=='q'){quitEvent.SetResult(true);break;}}});// Wait until 'q' is pressedawaitquitEvent.Task;Log.Information("Shutting down...");
Activity
kinyoklion commentedon Nov 12, 2025
Hello @flakey-bit,
Thank you for the report. We will consider the request and look into options.
The SDK currently isn't designed to allow for runtime changes of any configuration, and changing configuration will likely be similar in performance to initializing a new client instance. Likely equal to a wrapper around the client that detects changing and then initializes a new internal client for the singleton to use.
Thank you,
Ryan
Filed internally as SDK-1571
flakey-bit commentedon Feb 1, 2026
I've done a proof-of-concept (complete hack job) for this.
At a high-level, it involved a couple of things:
LaunchDarkly.EventSourcerepository, insideEventSourceService::ConnectToEventSourceApiwe set (replace) the authorization header by reading from the SDK key current-value from theOptionsMonitorStreamingDataSource, register a callback forOptionsMonitor::OnChangethat callsIEventSource::Restart(true)- this is the event source created in theStreamingDataSourceconstructorWith these changes in place and a test harness program, I can swich between two LD projects at runtime - which is a neat party trick 🥳