@@ -92,7 +92,7 @@ public override async Task OnConnectedAsync(HubConnectionContext connection)
9292 // OnConnectedAsync won't work with client results (ISingleClientProxy.InvokeAsync)
9393 InitializeHub ( hub , connection , invokeAllowed : false ) ;
9494
95- activity = StartActivity ( SignalRServerActivitySource . OnConnected , ActivityKind . Internal , linkedActivity : null , scope . ServiceProvider , nameof ( hub . OnConnectedAsync ) , headers : null , _logger ) ;
95+ activity = StartActivity ( SignalRServerActivitySource . OnConnected , ActivityKind . Internal , linkedActivity : null , scope . ServiceProvider , nameof ( hub . OnConnectedAsync ) , headers : null , _logger , connection ) ;
9696
9797 if ( _onConnectedMiddleware != null )
9898 {
@@ -127,7 +127,7 @@ public override async Task OnDisconnectedAsync(HubConnectionContext connection,
127127 {
128128 InitializeHub ( hub , connection ) ;
129129
130- activity = StartActivity ( SignalRServerActivitySource . OnDisconnected , ActivityKind . Internal , linkedActivity : null , scope . ServiceProvider , nameof ( hub . OnDisconnectedAsync ) , headers : null , _logger ) ;
130+ activity = StartActivity ( SignalRServerActivitySource . OnDisconnected , ActivityKind . Internal , linkedActivity : null , scope . ServiceProvider , nameof ( hub . OnDisconnectedAsync ) , headers : null , _logger , connection ) ;
131131
132132 if ( _onDisconnectedMiddleware != null )
133133 {
@@ -404,7 +404,7 @@ static async Task ExecuteInvocation(DefaultHubDispatcher<THub> dispatcher,
404404
405405 // Use hubMethodInvocationMessage.Target instead of methodExecutor.MethodInfo.Name
406406 // We want to take HubMethodNameAttribute into account which will be the same as what the invocation target is
407- var activity = StartActivity ( SignalRServerActivitySource . InvocationIn , ActivityKind . Server , connection . OriginalActivity , scope . ServiceProvider , hubMethodInvocationMessage . Target , hubMethodInvocationMessage . Headers , logger ) ;
407+ var activity = StartActivity ( SignalRServerActivitySource . InvocationIn , ActivityKind . Server , connection . OriginalActivity , scope . ServiceProvider , hubMethodInvocationMessage . Target , hubMethodInvocationMessage . Headers , logger , connection ) ;
408408
409409 object ? result ;
410410 try
@@ -522,7 +522,7 @@ private async Task StreamAsync(string invocationId, HubConnectionContext connect
522522 Activity . Current = null ;
523523 }
524524
525- var activity = StartActivity ( SignalRServerActivitySource . InvocationIn , ActivityKind . Server , connection . OriginalActivity , scope . ServiceProvider , hubMethodInvocationMessage . Target , hubMethodInvocationMessage . Headers , _logger ) ;
525+ var activity = StartActivity ( SignalRServerActivitySource . InvocationIn , ActivityKind . Server , connection . OriginalActivity , scope . ServiceProvider , hubMethodInvocationMessage . Target , hubMethodInvocationMessage . Headers , _logger , connection ) ;
526526
527527 try
528528 {
@@ -829,7 +829,7 @@ public override IReadOnlyList<Type> GetParameterTypes(string methodName)
829829
830830 // Starts an Activity for a Hub method invocation and sets up all the tags and other state.
831831 // Make sure to call Activity.Stop() once the Hub method completes, and consider calling SetActivityError on exception.
832- private static Activity ? StartActivity ( string operationName , ActivityKind kind , Activity ? linkedActivity , IServiceProvider serviceProvider , string methodName , IDictionary < string , string > ? headers , ILogger logger )
832+ private static Activity ? StartActivity ( string operationName , ActivityKind kind , Activity ? linkedActivity , IServiceProvider serviceProvider , string methodName , IDictionary < string , string > ? headers , ILogger logger , HubConnectionContext ? connection = null )
833833 {
834834 var activitySource = serviceProvider . GetService < SignalRServerActivitySource > ( ) ? . ActivitySource ;
835835 if ( activitySource is null )
@@ -843,15 +843,20 @@ public override IReadOnlyList<Type> GetParameterTypes(string methodName)
843843 return null ;
844844 }
845845
846- IEnumerable < KeyValuePair < string , object ? > > tags =
847- [
848- new ( "rpc.method" , methodName ) ,
849- new ( "rpc.system" , "signalr" ) ,
850- new ( "rpc.service" , _fullHubName ) ,
851- // See https://github.com/dotnet/aspnetcore/blob/027c60168383421750f01e427e4f749d0684bc02/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelMetrics.cs#L308
852- // And https://github.com/dotnet/aspnetcore/issues/43786
853- //new("server.address", ...),
854- ] ;
846+ var tagList = new TagList
847+ {
848+ { "rpc.method" , methodName } ,
849+ { "rpc.system" , "signalr" } ,
850+ { "rpc.service" , _fullHubName }
851+ } ;
852+
853+ // Add connection endpoint tags if connection is available
854+ if ( connection is not null )
855+ {
856+ ConnectionEndpointTags . AddConnectionEndpointTags ( ref tagList , connection . Features ) ;
857+ }
858+
859+ IEnumerable < KeyValuePair < string , object ? > > tags = tagList ;
855860 IEnumerable < ActivityLink > ? links = ( linkedActivity is not null ) ? [ new ActivityLink ( linkedActivity . Context ) ] : null ;
856861
857862 Activity ? activity ;
0 commit comments