@@ -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" ;
@@ -72,6 +78,7 @@ public static class RabbitMQActivitySource
72
78
{
73
79
return null ;
74
80
}
81
+
75
82
Activity ? connectionActivity =
76
83
s_connectionSource . StartRabbitMQActivity ( "rabbitmq connect" , ActivityKind . Client ) ;
77
84
connectionActivity ?
@@ -165,14 +172,17 @@ public static class RabbitMQActivitySource
165
172
return activity ;
166
173
}
167
174
168
- internal static void ReportException ( this Activity ? activity , Exception exception )
175
+ internal static void ReportException ( this Activity activity , Exception exception )
169
176
{
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 ) ;
174
184
}
175
-
185
+
176
186
private static Activity ? StartRabbitMQActivity ( this ActivitySource source , string name , ActivityKind kind ,
177
187
ActivityContext parentContext = default )
178
188
{
0 commit comments