@@ -17,7 +17,9 @@ internal static class ActivitySourceHelper
1717 public const string NetPeerNameTagName = "net.peer.name" ;
1818 public const string NetPeerPortTagName = "net.peer.port" ;
1919 public const string NetTransportTagName = "net.transport" ;
20+ #if ! NET6_0_OR_GREATER
2021 public const string StatusCodeTagName = "otel.status_code" ;
22+ #endif
2123 public const string ThreadIdTagName = "thread.id" ;
2224
2325 public const string DatabaseSystemValue = "mysql" ;
@@ -38,16 +40,28 @@ internal static class ActivitySourceHelper
3840
3941 public static void SetSuccess ( this Activity activity )
4042 {
43+ #if NET6_0_OR_GREATER
44+ if ( activity . Status == ActivityStatusCode . Unset )
45+ {
46+ activity . SetStatus ( ActivityStatusCode . Ok ) ;
47+ }
48+ #else
4149 if ( activity . Duration == TimeSpan . Zero )
4250 {
4351 activity . SetTag ( StatusCodeTagName , "OK" ) ;
4452 }
53+ #endif
4554 }
4655
4756 public static void SetException ( this Activity activity , Exception exception )
4857 {
58+ var description = exception is MySqlException mySqlException ? mySqlException . ErrorCode . ToString ( ) : exception . Message ;
59+ #if NET6_0_OR_GREATER
60+ activity . SetStatus ( ActivityStatusCode . Error , description ) ;
61+ #else
4962 activity . SetTag ( StatusCodeTagName , "ERROR" ) ;
50- activity . SetTag ( "otel.status_description" , exception is MySqlException mySqlException ? mySqlException . ErrorCode . ToString ( ) : exception . Message ) ;
63+ activity . SetTag ( "otel.status_description" , description ) ;
64+ #endif
5165 activity . AddEvent ( new ActivityEvent ( "exception" , tags : new ActivityTagsCollection
5266 {
5367 { "exception.type" , exception . GetType ( ) . FullName } ,
0 commit comments