-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asserting OpenTelemetry data when using DistributedApplicationTestingBuilder #2897
Comments
I think such a feature would also help a great deal when debugging test failures with complex invocation chains (which we can most of the times host entirely locally using DAPR and a bunch of lightweight containers such as Redis). Having OTLP data to support the visualisation of the invocation chain can be an enormous time saver (compared to attaching the debugger to all the processes and step into all of them). What we're currently trying to do is host the standalone dashboard using the docker image and have the apps send their OTLP data to it via OTLP exporter in the service defaults. we're not yet sure this will work as we're still fighting with it, will update in case we find a working solution, but it would be so useful to have telemetry support during test runs! |
This was a feature area kind of discussed by @lmolkova at OTel community day yesterday - using OTel to collect telemetry as part of a test run to be able to compare it and understand if its good or bad in comparison with previous runs. |
there is also some otel tooling being developed to run validation against collected telemetry. let me find out more. |
It is possible to get traces now by adding Here's the code that works now. You can check out the full PR example dotnet/aspire-samples#361 [Fact]
public async Task EndpointCall_ShouldCaptureDistributedTracesAsASnapshot()
{
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireShop_AppHost>();
appHost.Services.AddDashboardWebApplication();
await using var app = await appHost.BuildAsync();
await app.StartAsync();
var tracesViewModel = app.Services.GetDashboardWebApplication().GetService<TracesViewModel>();
var httpClient = app.CreateHttpClient("frontend");
var tracesTree = await tracesViewModel.CaptureTraces(async () =>
{
var response = await httpClient.GetAsync("/");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
});
await app.StopAsync();
await Verify(tracesTree);
} It would be nice to just get TracesViewModel from services like this [Fact]
public async Task EndpointCall_ShouldGenerateDistributedTraces()
{
// Arrange
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireShop_AppHost>();
await using var app = await appHost.BuildAsync();
await app.StartAsync();
//Getting aspire TracesViewModel service, but tracesViewModel is null?
var tracesViewModel = app.Services.GetService<TracesViewModel>();
//How can I get the aspire TracesViewModel service?
// Act
var httpClient = app.CreateHttpClient("frontend");
var response = await httpClient.GetAsync("/");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotEmpty(tracesViewModel.GetTraces().Items);
await app.StopAsync();
} But there are the problems:
|
I bumped into this issues while searching for a way to assert otel and then I later discovered this: Not sure how to plug this into DistributedApplicationTestingBuilder Yet, but will take a stab at it. |
When using
DistributedApplicationTestingBuilder
in an integration test, because there is no dashboard process running, there is no OTLP endpoint hosted for the running resources to send OTel data to. We should consider havingDistributedApplicationTestingBuilder
host an OTLP endpoint and expose its data to allow assertion against it in a test, so that testing based on observing OTel data could be facilitated.The text was updated successfully, but these errors were encountered: