Skip to content

SignalR Per-hub-method middleware #21722

@Jon-Murray

Description

@Jon-Murray

Hi,

I apologise if this has been covered before, but i did google a lot and the best i could find was #7139 which somewhat touches on the issue. I've been using signalr 2.2 in production for a while now. Originally, we modified the "Invoke" function within DefaultHubDispatcher (Microsoft.AspNetCore.SignalR.Core) and added in a custom function to record the hub endpoint, user, arguments, a kick off a timer. Then wrapped the "ExecuteHubMethod" code in a try/catch, and recorded the eventual time taken. This allowed us to pipe the results (status code), which user executed what, how long it took, etc. etc. into our logging system. It worked great and eventually allowed for some funky stats such as the below:

image

I hope this kind of gives enough background information about the use-case. Now you can see the "GET" and "WS" prefixes. The GET was from a typical controller method which was using the standard http request middleware. However, i genuinely can't find a way to have something similar in signalr.

Ideally i'd want exactly the same functionality, a hub method is executed, before execution i am passed the name, arguments, or just the context itself, i can then pass this back, and get either a response object, or just a task success/failure. The issue i linked way back before this wall of text also asked about something similar. Without changing the source again, the only semi-solutions i have found at the moment are that the authorization middleware passes the method/args over (but obviously doesnt not record the outcome or time of the execution) and then i can comb through logging with debug logs enabled. Are there any plans to integrate a "traditional" middleware into signalr? Thanks again for all the awesome work to date.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions