From 9d32b6672dbde7ffec3b4b3b640d4ec48da04e4d Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:14:40 -0800 Subject: [PATCH] Remove asserts of http.route. It is covered by other tests. --- .../BasicTests.cs | 63 ++----------------- 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 93ef8753772..8a0d507ecb5 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -189,7 +189,6 @@ public async Task SuccessfulTemplateControllerCallUsesParentContext() var activity = exportedItems[0]; Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", activity.OperationName); - Assert.Equal("api/Values/{id}", activity.DisplayName); Assert.Equal(expectedTraceId, activity.Context.TraceId); Assert.Equal(expectedSpanId, activity.ParentSpanId); @@ -251,7 +250,6 @@ public async Task CustomPropagator(bool addSampler) var activity = exportedItems[0]; Assert.True(activity.Duration != TimeSpan.Zero); - Assert.Equal("api/Values/{id}", activity.DisplayName); Assert.Equal(expectedTraceId, activity.Context.TraceId); Assert.Equal(expectedSpanId, activity.ParentSpanId); @@ -644,10 +642,9 @@ void ConfigureTestServices(IServiceCollection services) Assert.Equal(activityName, middlewareActivity.OperationName); Assert.Equal(activityName, middlewareActivity.DisplayName); - // tag http.route should be added on activity started by asp.net core - Assert.Equal("api/Values/{id}", aspnetcoreframeworkactivity.GetTagValue(SemanticConventions.AttributeHttpRoute) as string); + // tag http.method should be added on activity started by asp.net core + Assert.Equal("GET", aspnetcoreframeworkactivity.GetTagValue(SemanticConventions.AttributeHttpMethod) as string); Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", aspnetcoreframeworkactivity.OperationName); - Assert.Equal("api/Values/{id}", aspnetcoreframeworkactivity.DisplayName); } [Theory] @@ -763,10 +760,9 @@ public async Task ActivitiesStartedInMiddlewareBySettingHostActivityToNullShould Assert.Equal(activityName, middlewareActivity.OperationName); Assert.Equal(activityName, middlewareActivity.DisplayName); - // tag http.route should not be added on activity started by asp.net core as it will not be found during OnEventWritten event - Assert.DoesNotContain(aspnetcoreframeworkactivity.TagObjects, t => t.Key == SemanticConventions.AttributeHttpRoute); + // tag http.method should be added on activity started by asp.net core + Assert.Equal("GET", aspnetcoreframeworkactivity.GetTagValue(SemanticConventions.AttributeHttpMethod) as string); Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", aspnetcoreframeworkactivity.OperationName); - Assert.Equal("/api/values/2", aspnetcoreframeworkactivity.DisplayName); } #if NET7_0_OR_GREATER @@ -1078,57 +1074,6 @@ static void ThrowException(IApplicationBuilder app) await app.DisposeAsync().ConfigureAwait(false); } - [Fact] - public async Task RouteInformationIsNotAddedToRequestsOutsideOfMVC() - { - var exportedItems = new List(); - - // configure SDK - using var tracerprovider = Sdk.CreateTracerProviderBuilder() - .AddAspNetCoreInstrumentation() - .AddInMemoryExporter(exportedItems) - .Build(); - - var builder = WebApplication.CreateBuilder(); - builder.Logging.ClearProviders(); - var app = builder.Build(); - - app.MapGet("/custom/{name:alpha}", () => "Hello"); - - _ = app.RunAsync(); - - using var client = new HttpClient(); - var res = await client.GetStringAsync("http://localhost:5000/custom/abc").ConfigureAwait(false); - Assert.NotNull(res); - - tracerprovider.ForceFlush(); - for (var i = 0; i < 10; i++) - { - if (exportedItems.Count > 0) - { - break; - } - - // We need to let End callback execute as it is executed AFTER response was returned. - // In unit tests environment there may be a lot of parallel unit tests executed, so - // giving some breezing room for the End callback to complete - await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); - } - - var activity = exportedItems[0]; - - Assert.NotNull(activity); - - // After fix update to Contains http.route - Assert.DoesNotContain(activity.TagObjects, t => t.Key == SemanticConventions.AttributeHttpRoute); - Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", activity.OperationName); - - // After fix this should be /custom/{name:alpha} - Assert.Equal("/custom/abc", activity.DisplayName); - - await app.DisposeAsync().ConfigureAwait(false); - } - public void Dispose() { this.tracerProvider?.Dispose();