@@ -11,6 +11,12 @@ namespace RabbitMQ.Client
1111{
1212 public static class RabbitMQActivitySource
1313 {
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+
1420 // These constants are defined in the OpenTelemetry specification:
1521 // https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes
1622 internal const string MessageId = "messaging.message.id" ;
@@ -67,6 +73,7 @@ public static class RabbitMQActivitySource
6773 {
6874 return null ;
6975 }
76+
7077 Activity ? connectionActivity =
7178 s_connectionSource . StartRabbitMQActivity ( "rabbitmq connect" , ActivityKind . Client ) ;
7279 connectionActivity ?
@@ -170,14 +177,17 @@ public static class RabbitMQActivitySource
170177 return activity ;
171178 }
172179
173- internal static void ReportException ( this Activity ? activity , Exception exception )
180+ internal static void ReportException ( this Activity activity , Exception exception )
174181 {
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 ) ;
179189 }
180-
190+
181191 private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
182192 ActivityContext parentContext = default )
183193 {
0 commit comments