From 12a8ab0f45d810f40c7f7dd6340fa3acf9d26153 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Tue, 24 Sep 2024 19:44:10 +0200 Subject: [PATCH] [api] Mark ActivityExtensions.RecordException obsolete (#5841) Co-authored-by: Mikel Blanchard --- src/OpenTelemetry.Api/CHANGELOG.md | 6 ++++ .../Trace/ActivityExtensions.cs | 28 ++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index f4d70e46949..5f2c9925eb3 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -29,6 +29,12 @@ Notes](../../RELEASENOTES.md). `9.0.0-rc.1.24431.7`. ([#5853](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5853)) +* Obsoleted the `ActivityExtensions.RecordException` extension method. Users + should migrate to the `System.Diagnostics.DiagnosticSource` + [Activity.AddException](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.addexception) + API for adding exceptions on an `Activity` instance. + ([#5841](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5841)) + ## 1.9.0 Released 2024-Jun-14 diff --git a/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs b/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs index a94a635055b..7c2a0854419 100644 --- a/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs +++ b/src/OpenTelemetry.Api/Trace/ActivityExtensions.cs @@ -94,9 +94,12 @@ public static Status GetStatus(this Activity? activity) /// /// Activity instance. /// Exception to be recorded. - /// The exception is recorded as per specification. + /// + /// Note: This method is obsolete. Please use instead. + /// The exception is recorded as per specification. /// "exception.stacktrace" is represented using the value of Exception.ToString. /// + [Obsolete("Call Activity.AddException instead this method will be removed in a future version.")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void RecordException(this Activity? activity, Exception? ex) => RecordException(activity, ex, default); @@ -107,9 +110,12 @@ public static void RecordException(this Activity? activity, Exception? ex) /// Activity instance. /// Exception to be recorded. /// Additional tags to record on the event. - /// The exception is recorded as per specification. + /// + /// Note: This method is obsolete. Please use instead. + /// The exception is recorded as per specification. /// "exception.stacktrace" is represented using the value of Exception.ToString. /// + [Obsolete("Call Activity.AddException instead this method will be removed in a future version.")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void RecordException(this Activity? activity, Exception? ex, in TagList tags) { @@ -118,22 +124,6 @@ public static void RecordException(this Activity? activity, Exception? ex, in Ta return; } - var tagsCollection = new ActivityTagsCollection - { - { SemanticConventions.AttributeExceptionType, ex.GetType().FullName }, - { SemanticConventions.AttributeExceptionStacktrace, ex.ToInvariantString() }, - }; - - if (!string.IsNullOrWhiteSpace(ex.Message)) - { - tagsCollection.Add(SemanticConventions.AttributeExceptionMessage, ex.Message); - } - - foreach (var tag in tags) - { - tagsCollection[tag.Key] = tag.Value; - } - - activity.AddEvent(new ActivityEvent(SemanticConventions.AttributeExceptionEventName, default, tagsCollection)); + activity.AddException(ex, in tags); } }