Skip to content

Commit 2901146

Browse files
committed
Set Activity tags in addition to calling the new API.
We need to retain the tags for backwards compatibility with older consumers that haven't been updated to read the Status and StatusDescription properties.
1 parent 0d533e0 commit 2901146

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/MySqlConnector/Utilities/ActivitySourceHelper.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ 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
2120
public const string StatusCodeTagName = "otel.status_code";
22-
#endif
2321
public const string ThreadIdTagName = "thread.id";
2422

2523
public const string DatabaseSystemValue = "mysql";
@@ -42,20 +40,18 @@ public static void SetSuccess(this Activity activity)
4240
{
4341
#if NET6_0_OR_GREATER
4442
activity.SetStatus(ActivityStatusCode.Ok);
45-
#else
46-
activity.SetTag(StatusCodeTagName, "OK");
4743
#endif
44+
activity.SetTag(StatusCodeTagName, "OK");
4845
}
4946

5047
public static void SetException(this Activity activity, Exception exception)
5148
{
5249
var description = exception is MySqlException mySqlException ? mySqlException.ErrorCode.ToString() : exception.Message;
5350
#if NET6_0_OR_GREATER
5451
activity.SetStatus(ActivityStatusCode.Error, description);
55-
#else
52+
#endif
5653
activity.SetTag(StatusCodeTagName, "ERROR");
5754
activity.SetTag("otel.status_description", description);
58-
#endif
5955
activity.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection
6056
{
6157
{ "exception.type", exception.GetType().FullName },

0 commit comments

Comments
 (0)