@@ -990,6 +990,57 @@ static void ThrowException(IApplicationBuilder app)
990990 await app . DisposeAsync ( ) . ConfigureAwait ( false ) ;
991991 }
992992
993+ [ Fact ]
994+ public async Task RouteInformationIsNotAddedToRequestsOutsideOfMVC ( )
995+ {
996+ var exportedItems = new List < Activity > ( ) ;
997+
998+ // configure SDK
999+ using var tracerprovider = Sdk . CreateTracerProviderBuilder ( )
1000+ . AddAspNetCoreInstrumentation ( )
1001+ . AddInMemoryExporter ( exportedItems )
1002+ . Build ( ) ;
1003+
1004+ var builder = WebApplication . CreateBuilder ( ) ;
1005+ builder . Logging . ClearProviders ( ) ;
1006+ var app = builder . Build ( ) ;
1007+
1008+ app . MapGet ( "/custom/{name:alpha}" , ( ) => "Hello" ) ;
1009+
1010+ _ = app . RunAsync ( ) ;
1011+
1012+ using var client = new HttpClient ( ) ;
1013+ var res = await client . GetStringAsync ( "http://localhost:5000/custom/abc" ) . ConfigureAwait ( false ) ;
1014+ Assert . NotNull ( res ) ;
1015+
1016+ tracerprovider . ForceFlush ( ) ;
1017+ for ( var i = 0 ; i < 10 ; i ++ )
1018+ {
1019+ if ( exportedItems . Count > 0 )
1020+ {
1021+ break ;
1022+ }
1023+
1024+ // We need to let End callback execute as it is executed AFTER response was returned.
1025+ // In unit tests environment there may be a lot of parallel unit tests executed, so
1026+ // giving some breezing room for the End callback to complete
1027+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) . ConfigureAwait ( false ) ;
1028+ }
1029+
1030+ var activity = exportedItems [ 0 ] ;
1031+
1032+ Assert . NotNull ( activity ) ;
1033+
1034+ // After fix update to Contains http.route
1035+ Assert . DoesNotContain ( activity . TagObjects , t => t . Key == SemanticConventions . AttributeHttpRoute ) ;
1036+ Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , activity . OperationName ) ;
1037+
1038+ // After fix this should be /custom/{name:alpha}
1039+ Assert . Equal ( "/custom/abc" , activity . DisplayName ) ;
1040+
1041+ await app . DisposeAsync ( ) . ConfigureAwait ( false ) ;
1042+ }
1043+
9931044 public void Dispose ( )
9941045 {
9951046 this . tracerProvider ? . Dispose ( ) ;
0 commit comments