KEMBAR78
Improve WebApplication debugging by JamesNK · Pull Request #48827 · dotnet/aspnetcore · GitHub
Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jun 15, 2023

This PR adds various debugging improvements around WebApplication.

Notable improvements:

  • Add an IsRunning property calculated from lifetime events to quickly understand state of the app
  • Made it easier to see app name and environment (i.e. development or release)
  • Mapped endpoints are available in a collection
  • Configured middleware descriptions are available in a collection.
    • This was hard. The app builder sees middleware as a list of delegates, and delegates don't provide a nice debugging experience. Mapping middleware delegates back to middleware types required some creative problem-solving. I'd like to know whether people think the hacks here are worth it.
    • Note that the collection doesn't include middleware automatically added by WebApplication. Good or bad? Middleware automatically added when the web app starts is included.
    • More testing is needed to ensure it hangs together when branching the app pipeline. Done
  • Improve ApplicationLifetime. It lives in dotnet/runtime. Will improve it later. Add DebuggerDisplay to some hosting types runtime#87599

Before:

image

After:

image

App endpoints:

image

App middleware:

image

More complex example:

image

@Tratcher
Copy link
Member

Tratcher commented Jun 15, 2023

Note that the collection doesn't include middleware automatically added by WebApplication. Good or bad?

Bad, they should at least show after build/run is called.

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Showing middleware would be nice
  • This is a very hacky way to do it, and not very representative when there are pipeline forks involved.
  • I think you're missing several other ways that middleware are defined like with the Map or Use extensions.
  • I'm not sure there's a better way
  • Is it worth it? Depends, what does the list look like for a real application? At least one of the more complex templates with auth and such.

@JamesNK
Copy link
Member Author

JamesNK commented Jun 16, 2023

Bad, they should at least show after build/run is called.

Done. More hacking was required though to merge the app pipelines nicely 😬

Here you can see UseRouting/UseEndpoints/UseAuthN/UseAuthZ are automatically added because the app has an endpoint and authn/authz configured:

image

I think you're missing several other ways that middleware are defined like with the Map or Use extensions.

The delegate method name is added to the list. It's a bit ugly, but the information is there.

One thing that is missing is middleware from branched pipelines (MapWhen, UseWhen). I think displaying that kind of complexity would be very tough, require some public API to build up the graph, and generally involve substantial changes

This is what it looks like:

image

@JamesNK JamesNK force-pushed the jamesnk/webapplication-debugging branch from 2fed5b6 to 8d5625a Compare June 16, 2023 04:22
@davidfowl
Copy link
Member

@JamesNK make this a draft 😄

@JamesNK
Copy link
Member Author

JamesNK commented Jun 17, 2023

All the work-in-progress points identified at the top are done. Draft isn't necessary. It's ready for review.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@JamesNK JamesNK enabled auto-merge (squash) June 21, 2023 03:37
@JamesNK JamesNK force-pushed the jamesnk/webapplication-debugging branch from 5b1131f to 56760c2 Compare June 21, 2023 07:13
@JamesNK JamesNK merged commit 14a4f45 into main Jun 21, 2023
@JamesNK JamesNK deleted the jamesnk/webapplication-debugging branch June 21, 2023 09:00
@ghost ghost added this to the 8.0-preview6 milestone Jun 21, 2023
// IDebugger service can optionally be added by tests to simulate the debugger being attached.
_debugger = (IDebugger?)serviceProvider?.GetService(typeof(IDebugger)) ?? DebuggerWrapper.Instance;

if (_debugger.IsAttached)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾

return descriptions;
}

throw new NotSupportedException("Unable to get configured middleware.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/get/resolve

@davidfowl
Copy link
Member

This is really nice! Great work @JamesNK

// This type exists so the place where the source pipeline is wired into the destination pipeline can be identified.
private sealed class WireSourcePipeline(IApplicationBuilder builtApplication)
{
private readonly IApplicationBuilder _builtApplication = builtApplication;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you declare a field?

@adityamandaleeka adityamandaleeka added the blog-candidate Consider mentioning this in the release blog post label Jun 28, 2023
@ghost
Copy link

ghost commented Jun 28, 2023

@JamesNK, this change will be considered for inclusion in the blog post for the release it'll ship in. Nice work!

Please ensure that the original comment in this thread contains a clear explanation of what the change does, why it's important (what problem does it solve?), and, if relevant, include things like code samples and/or performance numbers.

This content may not be exactly what goes into the blog post, but it will help the team putting together the announcement.

Thanks!

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions blog-candidate Consider mentioning this in the release blog post

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants