@@ -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" ;
@@ -36,12 +38,30 @@ internal static class ActivitySourceHelper
3638 return activity ;
3739 }
3840
39- public static void SetSuccess ( this Activity activity ) => activity . SetTag ( StatusCodeTagName , "OK" ) ;
41+ public static void SetSuccess ( this Activity activity )
42+ {
43+ #if NET6_0_OR_GREATER
44+ if ( activity . Status == ActivityStatusCode . Unset )
45+ {
46+ activity . SetStatus ( ActivityStatusCode . Ok ) ;
47+ }
48+ #else
49+ if ( activity . Duration == TimeSpan . Zero )
50+ {
51+ activity . SetTag ( StatusCodeTagName , "OK" ) ;
52+ }
53+ #endif
54+ }
4055
4156 public static void SetException ( this Activity activity , Exception exception )
4257 {
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
4362 activity . SetTag ( StatusCodeTagName , "ERROR" ) ;
44- activity . SetTag ( "otel.status_description" , exception is MySqlException mySqlException ? mySqlException . ErrorCode . ToString ( ) : exception . Message ) ;
63+ activity . SetTag ( "otel.status_description" , description ) ;
64+ #endif
4565 activity . AddEvent ( new ActivityEvent ( "exception" , tags : new ActivityTagsCollection
4666 {
4767 { "exception.type" , exception . GetType ( ) . FullName } ,
0 commit comments