Skip to content

Commit 5c1154f

Browse files
[AspNetCore] Update Blazor test
- Add test for Blazor activities in .NET 10. - Fix typos.
1 parent 7bd48aa commit 5c1154f

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,9 +1212,8 @@ void ConfigureTestServices(IServiceCollection services)
12121212
Assert.Empty(hubActivity);
12131213
}
12141214

1215-
// note: this is always passing on Net9 or lower, because AddAspNetCoreInstrumentation only adds the subscription in Net10 or higher.
12161215
[Fact]
1217-
public async Task RazorComponentsActivitesCanBeDisabled()
1216+
public async Task RazorComponentsActivitiesCanBeDisabled()
12181217
{
12191218
var exportedItems = new List<Activity>();
12201219
void ConfigureTestServices(IServiceCollection services)
@@ -1239,7 +1238,7 @@ void ConfigureTestServices(IServiceCollection services)
12391238
{
12401239
activity.Start();
12411240
activity.SetTag("aspnetcore.components.type", "BasicTests");
1242-
activity.SetTag("aspnetcore.components.method", "BlazorActivitesCanBeDisabled");
1241+
activity.SetTag("aspnetcore.components.method", "BlazorActivitiesCanBeDisabled");
12431242
activity.Stop();
12441243
}
12451244

@@ -1260,6 +1259,57 @@ void ConfigureTestServices(IServiceCollection services)
12601259

12611260
Assert.Empty(blazorActivity);
12621261
}
1262+
1263+
#if NET10_0_OR_GREATER
1264+
[Fact]
1265+
public async Task RazorComponentsActivitiesAreEnabledByDefault()
1266+
{
1267+
var exportedItems = new List<Activity>();
1268+
void ConfigureTestServices(IServiceCollection services)
1269+
{
1270+
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
1271+
.AddAspNetCoreInstrumentation()
1272+
.AddInMemoryExporter(exportedItems)
1273+
.Build();
1274+
}
1275+
1276+
using (var client = this.factory
1277+
.WithWebHostBuilder(builder =>
1278+
{
1279+
builder.ConfigureTestServices(ConfigureTestServices);
1280+
builder.ConfigureLogging(loggingBuilder => loggingBuilder.ClearProviders());
1281+
})
1282+
.CreateClient())
1283+
{
1284+
var fakeActivitySource = new ActivitySource("Microsoft.AspNetCore.Components");
1285+
var activity = fakeActivitySource.CreateActivity("Microsoft.AspNetCore.Components.HandleEvent", ActivityKind.Internal, parentId: null, null, null);
1286+
if (activity != null)
1287+
{
1288+
activity.Start();
1289+
activity.SetTag("aspnetcore.components.type", "BasicTests");
1290+
activity.SetTag("aspnetcore.components.method", "BlazorActivitiesCanBeDisabled");
1291+
activity.Stop();
1292+
}
1293+
1294+
try
1295+
{
1296+
using var response = await client.GetAsync(new Uri("/api/values", UriKind.Relative));
1297+
}
1298+
catch (Exception)
1299+
{
1300+
// ignore errors
1301+
}
1302+
1303+
WaitForActivityExport(exportedItems, 1);
1304+
}
1305+
1306+
var blazorActivity = exportedItems
1307+
.Where(a => a.DisplayName.StartsWith("Microsoft.AspNetCore.Components", StringComparison.InvariantCulture));
1308+
1309+
Assert.NotEmpty(blazorActivity);
1310+
}
1311+
#endif
1312+
12631313
#endif
12641314

12651315
public void Dispose()

0 commit comments

Comments
 (0)