@@ -43,10 +43,15 @@ public static class RabbitMQActivitySource
4343 private static readonly ActivitySource s_subscriberSource =
4444 new ActivitySource ( SubscriberSourceName , AssemblyVersion ) ;
4545
46+ private static readonly ActivitySource s_connectionSource =
47+ new ActivitySource ( ConnectionSourceName , AssemblyVersion ) ;
48+
4649 public const string PublisherSourceName = "RabbitMQ.Client.Publisher" ;
4750 public const string SubscriberSourceName = "RabbitMQ.Client.Subscriber" ;
51+ public const string ConnectionSourceName = "RabbitMQ.Client.Connection" ;
4852
49- public static Action < Activity , IDictionary < string , object ? > > ContextInjector { get ; set ; } = DefaultContextInjector ;
53+ public static Action < Activity , IDictionary < string , object ? > > ContextInjector { get ; set ; } =
54+ DefaultContextInjector ;
5055
5156 public static Func < IReadOnlyBasicProperties , ActivityContext > ContextExtractor { get ; set ; } =
5257 DefaultContextExtractor ;
@@ -61,6 +66,19 @@ public static class RabbitMQActivitySource
6166 new KeyValuePair < string , object ? > ( ProtocolVersion , "0.9.1" )
6267 } ;
6368
69+ internal static Activity ? OpenConnection ( IFrameHandler frameHandler )
70+ {
71+ if ( ! s_connectionSource . HasListeners ( ) )
72+ {
73+ return null ;
74+ }
75+ Activity ? connectionActivity =
76+ s_connectionSource . StartRabbitMQActivity ( "rabbitmq connect" , ActivityKind . Client ) ;
77+ connectionActivity ?
78+ . SetNetworkTags ( frameHandler ) ;
79+ return connectionActivity ;
80+ }
81+
6482 internal static Activity ? BasicPublish ( string routingKey , string exchange , int bodySize ,
6583 ActivityContext linkedContext = default )
6684 {
@@ -82,7 +100,6 @@ public static class RabbitMQActivitySource
82100 }
83101
84102 return activity ;
85-
86103 }
87104
88105 internal static Activity ? BasicGetEmpty ( string queue )
@@ -148,6 +165,14 @@ public static class RabbitMQActivitySource
148165 return activity ;
149166 }
150167
168+ internal static void ReportException ( this Activity ? activity , Exception exception )
169+ {
170+ activity ? . AddTag ( "exception.message" , exception . Message ) ;
171+ activity ? . AddTag ( "exception.stacktrace" , exception . ToString ( ) ) ;
172+ activity ? . AddTag ( "exception.type" , exception . GetType ( ) . FullName ) ;
173+ activity ? . SetStatus ( ActivityStatusCode . Error ) ;
174+ }
175+
151176 private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
152177 ActivityContext parentContext = default )
153178 {
0 commit comments