@@ -17,7 +17,9 @@ internal static class ActivitySourceHelper
17
17
public const string NetPeerNameTagName = "net.peer.name" ;
18
18
public const string NetPeerPortTagName = "net.peer.port" ;
19
19
public const string NetTransportTagName = "net.transport" ;
20
+ #if ! NET6_0_OR_GREATER
20
21
public const string StatusCodeTagName = "otel.status_code" ;
22
+ #endif
21
23
public const string ThreadIdTagName = "thread.id" ;
22
24
23
25
public const string DatabaseSystemValue = "mysql" ;
@@ -36,12 +38,30 @@ internal static class ActivitySourceHelper
36
38
return activity ;
37
39
}
38
40
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
+ }
40
55
41
56
public static void SetException ( this Activity activity , Exception exception )
42
57
{
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
43
62
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
45
65
activity . AddEvent ( new ActivityEvent ( "exception" , tags : new ActivityTagsCollection
46
66
{
47
67
{ "exception.type" , exception . GetType ( ) . FullName } ,
0 commit comments