Skip to content

Log endpoint details at application startup to aid with issue diagnosis #34604

Open
@DamianEdwards

Description

@DamianEdwards

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}

{
    "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<string>",
        "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

Metadata

Metadata

Assignees

Labels

Priority:3Work that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routing

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions