You are developing a C# .NET 8 isolated worker Azure Function App. To meet your company's security compliance, the Application Insights connection string must be retrieved at startup from an Azure Key Vault using the Azure Identity library, rather than being stored in plain text in application settings.
In `Program.cs`, you retrieve the connection string value from Key Vault and store it in a variable named `vaultConnectionString`.
Which code segment should you use to register Application Insights telemetry with this connection string in the dependency injection container?
- Acsharp
TelemetryConfiguration.Active.ConnectionString = vaultConnectionString;
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights(); - csharp
services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.ConnectionString = vaultConnectionString;
});
services.ConfigureFunctionsApplicationInsights();
Cevap - Ccsharp
services.ConfigureFunctionsApplicationInsights(options =>
{
options.ConnectionString = vaultConnectionString;
}); - Dcsharp
services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.InstrumentationKey = vaultConnectionString;
});
services.ConfigureFunctionsApplicationInsights();
Cevap
The correct option is the one that sets the `ConnectionString` property of `ApplicationInsightsServiceOptions` inside `AddApplicationInsightsTelemetryWorkerService` and then calls `ConfigureFunctionsApplicationInsights`.
The correct option programmatically sets the connection string via the configuration lambda in `AddApplicationInsightsTelemetryWorkerService`. In .NET isolated worker Azure Functions, the `AddApplicationInsightsTelemetryWorkerService` extension method is used to register the telemetry services, and passing an action configuring `ApplicationInsightsServiceOptions.ConnectionString` is the supported way to provide the connection string programmatically. Calling `ConfigureFunctionsApplicationInsights` afterwards integrates the worker telemetry with the Functions host.
Adım Adım Çözüm
Anahtar Kavram
Programmatic configuration of Application Insights Connection String in Azure Functions Isolated Worker