Open iinuwa opened 2 years ago
Triage: related issue: https://github.com/dotnet/aspnetcore/issues/29846
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
cc @BrennanConroy min bar is that we should document this.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I am trying to add W3C Trace Context to our client's SignalR calls over WebSockets.
Our client generates a root trace ID when the page loads, and we are able to use interceptors on our REST calls to add the trace context to HTTP requests very easily, and ASP.NET Core automatically handles mapping the trace context to
System.Diagnostics.Activity.Current
. This allows us to do distributed tracing and track requests initiated by a single user's page load across all of our services.I would like the same thing for SignalR: automatic sending (for clients) and parsing (for servers/hubs) of W3C trace context, as well as handling
Activity.Current
. This may only be applicable to the browser-based WebSocket clients, since you should be able to set arbitrary HTTP headers, includingtraceparent
andtracestate
, using other clients/transports, and I assume those would still be parsed by ASP.NET Core.I found a workaround to do this in the browser, but it passes the trace context using a query string parameter in the connection URL, which I am not sure is supported or not. It also requires you to manually reset the current for each hub method call, which is easy to miss.
Describe the solution you'd like
I would like it if there was a way to specify a trace context in the client libraries and send it to the hub somehow, and for the
HubContext
to automatically parse the context and setActivity.Current
accordingly. (This would require some trickery for JS/browser clients since browsers don't allow extra headers in WebSocket connections.)For example:
In my example, the hub methods' parent activity is a "StartSession" activity created on connection, but I would probably be fine if the parent was set to the client's trace context directly.
Another option is to have another property in
HubContext
or a magic key inHubContext.Items
:magic_wand: (e.g.Context.Items["traceparent"]
) that is automatically parsed by the hub. That way, the user could decide how they want to get the trace context to the hub on the initial connection and parse it inOnConnectedAsync
. From there, theHubContext
could automatically pick up the trace context from thatHubContext
property orItem
.Additional context
I have found a way to add this, but it feels a little hacky:
In the client:
On the server: