diff --git a/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs b/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs index a358b689d6c..a07c87d4915 100644 --- a/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs +++ b/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs @@ -45,6 +45,14 @@ public static void SetStatus(this Activity activity, Status status) { Debug.Assert(activity != null, "Activity should not be null"); + if (activity.GetStatus().StatusCode == StatusCode.Ok) + { + // If the status is Ok, subsequent calls will be ignored. + // This will travel through the list which hurts the performance. + // The perf issue will be solved once .NET added native support for Activity.SetStatus. + return; + } + activity.SetTag(SpanAttributeConstants.StatusCodeKey, StatusHelper.GetTagValueForStatusCode(status.StatusCode)); activity.SetTag(SpanAttributeConstants.StatusDescriptionKey, status.Description); }