@@ -43,10 +43,15 @@ public static class RabbitMQActivitySource
43
43
private static readonly ActivitySource s_subscriberSource =
44
44
new ActivitySource ( SubscriberSourceName , AssemblyVersion ) ;
45
45
46
+ private static readonly ActivitySource s_connectionSource =
47
+ new ActivitySource ( ConnectionSourceName , AssemblyVersion ) ;
48
+
46
49
public const string PublisherSourceName = "RabbitMQ.Client.Publisher" ;
47
50
public const string SubscriberSourceName = "RabbitMQ.Client.Subscriber" ;
51
+ public const string ConnectionSourceName = "RabbitMQ.Client.Connection" ;
48
52
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 ;
50
55
51
56
public static Func < IReadOnlyBasicProperties , ActivityContext > ContextExtractor { get ; set ; } =
52
57
DefaultContextExtractor ;
@@ -61,6 +66,19 @@ public static class RabbitMQActivitySource
61
66
new KeyValuePair < string , object ? > ( ProtocolVersion , "0.9.1" )
62
67
} ;
63
68
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
+
64
82
internal static Activity ? BasicPublish ( string routingKey , string exchange , int bodySize ,
65
83
ActivityContext linkedContext = default )
66
84
{
@@ -82,7 +100,6 @@ public static class RabbitMQActivitySource
82
100
}
83
101
84
102
return activity ;
85
-
86
103
}
87
104
88
105
internal static Activity ? BasicGetEmpty ( string queue )
@@ -148,6 +165,14 @@ public static class RabbitMQActivitySource
148
165
return activity ;
149
166
}
150
167
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
+
151
176
private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
152
177
ActivityContext parentContext = default )
153
178
{
0 commit comments