dotnet / dotnet/aspnetcore

Log endpoint details at application startup to aid with issue diagnosis

Open
#34,604 9 comments 0 reactions 1 assignee Claimed by @halter73 View on GitHub
area-minimal feature-minimal-actions Priority:3
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

To aid in situations where one is trying to diagnose issues related to routing, minimal API endpoints, parameter binding sources, etc. it would be beneficial for a log to be emitted containing the endpoint details as they're registered, i.e. one log per endpoint. When the endpoint is a minimal API, it should include details of how the parameters will be bound, and return type details, along with any endpoint metadata associated with the endpoint. It might be interesting to think about how other endpoint-providing sub-systems, e.g. MVC, could augment this log with relevant information too.

The log would target the DEBUG log level and include a message and a single value containing a JSON payload of the details, e.g.:

`Message: Endpoint added at route "/say/{greeting}/{name}/{age?:int}`
``` jsonc
{
"route": {
"pattern": "/say/{greeting}/{name}/{age?:int}",
"verbs": "GET",
"name": null,
"parameters": [
{
"name": "greeting",
"required": true
},
{
"name": "name",
"required": true
},
{
"name": "age",
"required": false
}
]
},
"description": {
"name": "GetGreeting", // Would be null if we determine it was an anonymous delegate (i.e. compiler generated name)
"delegateReturnType": "Task",
"responseProcessing": "string", // Possible values: string, JSON, IResult
"parameters": [
{
"name": "greeting",
"required": true,
"type": "string",
"bindingSource": "RouteData" // Possible values: RouteData, QueryString, ServiceProvider, RequestBody
},
{
"name": "name",
"required": true,
"type": "string",
"bindingSource": "RouteData"
},
{
"name": "age",
"required": false,
"type": "int",
"bindingSource": "RouteData"
},
{
"name": "filter",
"required": false,
"type": "string",
"bindingSource": "QueryString"
},
{
"name": "db",
"required": true,
"type": "MyApplication.TodoDb",
"bindingSource": "ServiceProvider"
}
]
},
"metadata": {
// Keys are type name, value are result of ToString()
"EndpointNameAttribute": "GetGreeting",
"HttpMethodMetadata": "GET",
"MethodInfo": ""
}
}
```

@davidfowl

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.