Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/kiota/Extension/KiotaHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@

internal static class KiotaHostExtensions
{
private const string TelemetryOptOutKey = "KIOTA_CLI_TELEMETRY_OPTOUT";

internal static IHostBuilder ConfigureKiotaTelemetryServices(this IHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices(ConfigureServiceContainer);

static void ConfigureServiceContainer(HostBuilderContext context, IServiceCollection services)

Check warning on line 22 in src/kiota/Extension/KiotaHostExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this static local function to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 22 in src/kiota/Extension/KiotaHostExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this static local function to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 22 in src/kiota/Extension/KiotaHostExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this static local function to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 22 in src/kiota/Extension/KiotaHostExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this static local function to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
TelemetryConfig cfg = new();
var section = context.Configuration.GetSection(TelemetryConfig.ConfigSectionKey);
section.Bind(cfg);
if (!cfg.Disabled)
// Spec mandates using an environment variable for opt-out
// cfg.Disabled acts as a feature flag, the env var is an option.
var disabled = Environment.GetEnvironmentVariable(TelemetryOptOutKey)?.ToLowerInvariant();
if (!cfg.Disabled && disabled is not ("1" or "true"))
{
// Only register if telemetry is enabled.
var openTelemetryBuilder = services.AddOpenTelemetry()
Expand Down
Loading