Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove asserts of http.route. It is covered by other tests.
  • Loading branch information
alanwest committed Nov 9, 2023
commit 9d32b6672dbde7ffec3b4b3b640d4ec48da04e4d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1078,57 +1074,6 @@ static void ThrowException(IApplicationBuilder app)
await app.DisposeAsync().ConfigureAwait(false);
}

[Fact]
public async Task RouteInformationIsNotAddedToRequestsOutsideOfMVC()
{
var exportedItems = new List<Activity>();

// 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();
Expand Down