@@ -11,6 +11,12 @@ namespace RabbitMQ.Client
11
11
{
12
12
public static class RabbitMQActivitySource
13
13
{
14
+ private const string ExceptionEventName = "exception" ;
15
+ private const string ExceptionMessageTag = "exception.message" ;
16
+ private const string ExceptionStackTraceTag = "exception.stacktrace" ;
17
+
18
+ private const string ExceptionTypeTag = "exception.type" ;
19
+
14
20
// These constants are defined in the OpenTelemetry specification:
15
21
// https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes
16
22
internal const string MessageId = "messaging.message.id" ;
@@ -67,6 +73,7 @@ public static class RabbitMQActivitySource
67
73
{
68
74
return null ;
69
75
}
76
+
70
77
Activity ? connectionActivity =
71
78
s_connectionSource . StartRabbitMQActivity ( "rabbitmq connect" , ActivityKind . Client ) ;
72
79
connectionActivity ?
@@ -170,14 +177,17 @@ public static class RabbitMQActivitySource
170
177
return activity ;
171
178
}
172
179
173
- internal static void ReportException ( this Activity ? activity , Exception exception )
180
+ internal static void ReportException ( this Activity activity , Exception exception )
174
181
{
175
- activity ? . AddTag ( "exception.message" , exception . Message ) ;
176
- activity ? . AddTag ( "exception.stacktrace" , exception . ToString ( ) ) ;
177
- activity ? . AddTag ( "exception.type" , exception . GetType ( ) . FullName ) ;
178
- activity ? . SetStatus ( ActivityStatusCode . Error ) ;
182
+ ActivityTagsCollection exceptionTags = new ( ) ;
183
+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionMessageTag , exception . Message ) ) ;
184
+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionStackTraceTag , exception . ToString ( ) ) ) ;
185
+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionTypeTag , exception . GetType ( ) . ToString ( ) ) ) ;
186
+ activity . AddEvent ( new ActivityEvent ( ExceptionEventName , default , exceptionTags ) ) ;
187
+
188
+ activity . SetStatus ( ActivityStatusCode . Error ) ;
179
189
}
180
-
190
+
181
191
private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
182
192
ActivityContext parentContext = default )
183
193
{
0 commit comments