@@ -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" ;
@@ -72,6 +78,7 @@ public static class RabbitMQActivitySource
7278 {
7379 return null ;
7480 }
81+
7582 Activity ? connectionActivity =
7683 s_connectionSource . StartRabbitMQActivity ( "rabbitmq connect" , ActivityKind . Client ) ;
7784 connectionActivity ?
@@ -165,14 +172,17 @@ public static class RabbitMQActivitySource
165172 return activity ;
166173 }
167174
168- internal static void ReportException ( this Activity ? activity , Exception exception )
175+ internal static void ReportException ( this Activity activity , Exception exception )
169176 {
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 ) ;
177+ ActivityTagsCollection exceptionTags = new ( ) ;
178+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionMessageTag , exception . Message ) ) ;
179+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionStackTraceTag , exception . ToString ( ) ) ) ;
180+ exceptionTags . Add ( new KeyValuePair < string , object ? > ( ExceptionTypeTag , exception . GetType ( ) . ToString ( ) ) ) ;
181+ activity . AddEvent ( new ActivityEvent ( ExceptionEventName , default , exceptionTags ) ) ;
182+
183+ activity . SetStatus ( ActivityStatusCode . Error ) ;
174184 }
175-
185+
176186 private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
177187 ActivityContext parentContext = default )
178188 {
0 commit comments