Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,13 @@ internal void InitializeDefaultServices()
Services.AddSingleton<AntiforgeryStateProvider, DefaultAntiforgeryStateProvider>();
RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<AntiforgeryStateProvider>(Services, RenderMode.InteractiveWebAssembly);
Services.AddSupplyValueFromQueryProvider();

// Register metrics and tracing by default (opt-out via feature switch for trimming)
var isTelemetryDisabled = AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out var switchValue) && switchValue == false;
if (!isTelemetryDisabled)
{
ComponentsMetricsServiceCollectionExtensions.AddComponentsMetrics(Services);
ComponentsMetricsServiceCollectionExtensions.AddComponentsTracing(Services);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Reference Include="Microsoft.Extensions.Configuration.Json" />
<Reference Include="Microsoft.Extensions.Configuration.Binder" />
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Diagnostics" />
<Reference Include="Microsoft.JSInterop.WebAssembly" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.Metrics;
using System.Text;
using System.Text.Json;
using Microsoft.AspNetCore.Components.Routing;
Expand Down Expand Up @@ -341,4 +342,21 @@ public void Configuration_IncludesEnvironmentVariables_WhenAddedExplicitly()
Environment.SetEnvironmentVariable(testEnvVarKey, null);
}
}

[Fact]
public void Constructor_RegistersMetricsAndTracingServices()
{
// Arrange & Act
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods());
var host = builder.Build();

// Assert - Verify that IMeterFactory is registered (required for ComponentsMetrics)
// and that the service collection was configured for both metrics and tracing
var meterFactory = host.Services.GetService<IMeterFactory>();
Assert.NotNull(meterFactory);

// Note: ComponentsActivitySource is scoped and internal, so we can't directly
// test for it here, but both AddComponentsMetrics and AddComponentsTracing
// are called together, ensuring both telemetry services are registered.
}
}
Loading