Skip to content

Commit 12a8ab0

Browse files
[api] Mark ActivityExtensions.RecordException obsolete (open-telemetry#5841)
Co-authored-by: Mikel Blanchard <[email protected]>
1 parent 3c38a4b commit 12a8ab0

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/OpenTelemetry.Api/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Notes](../../RELEASENOTES.md).
2929
`9.0.0-rc.1.24431.7`.
3030
([#5853](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5853))
3131

32+
* Obsoleted the `ActivityExtensions.RecordException` extension method. Users
33+
should migrate to the `System.Diagnostics.DiagnosticSource`
34+
[Activity.AddException](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.addexception)
35+
API for adding exceptions on an `Activity` instance.
36+
([#5841](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5841))
37+
3238
## 1.9.0
3339

3440
Released 2024-Jun-14

src/OpenTelemetry.Api/Trace/ActivityExtensions.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ public static Status GetStatus(this Activity? activity)
9494
/// </summary>
9595
/// <param name="activity">Activity instance.</param>
9696
/// <param name="ex">Exception to be recorded.</param>
97-
/// <remarks> The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
97+
/// <remarks>
98+
/// <para>Note: This method is obsolete. Please use <see cref="Activity.AddException"/> instead.</para>
99+
/// The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
98100
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
99101
/// </remarks>
102+
[Obsolete("Call Activity.AddException instead this method will be removed in a future version.")]
100103
[MethodImpl(MethodImplOptions.AggressiveInlining)]
101104
public static void RecordException(this Activity? activity, Exception? ex)
102105
=> RecordException(activity, ex, default);
@@ -107,9 +110,12 @@ public static void RecordException(this Activity? activity, Exception? ex)
107110
/// <param name="activity">Activity instance.</param>
108111
/// <param name="ex">Exception to be recorded.</param>
109112
/// <param name="tags">Additional tags to record on the event.</param>
110-
/// <remarks> The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
113+
/// <remarks>
114+
/// <para>Note: This method is obsolete. Please use <see cref="Activity.AddException"/> instead.</para>
115+
/// The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
111116
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
112117
/// </remarks>
118+
[Obsolete("Call Activity.AddException instead this method will be removed in a future version.")]
113119
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114120
public static void RecordException(this Activity? activity, Exception? ex, in TagList tags)
115121
{
@@ -118,22 +124,6 @@ public static void RecordException(this Activity? activity, Exception? ex, in Ta
118124
return;
119125
}
120126

121-
var tagsCollection = new ActivityTagsCollection
122-
{
123-
{ SemanticConventions.AttributeExceptionType, ex.GetType().FullName },
124-
{ SemanticConventions.AttributeExceptionStacktrace, ex.ToInvariantString() },
125-
};
126-
127-
if (!string.IsNullOrWhiteSpace(ex.Message))
128-
{
129-
tagsCollection.Add(SemanticConventions.AttributeExceptionMessage, ex.Message);
130-
}
131-
132-
foreach (var tag in tags)
133-
{
134-
tagsCollection[tag.Key] = tag.Value;
135-
}
136-
137-
activity.AddEvent(new ActivityEvent(SemanticConventions.AttributeExceptionEventName, default, tagsCollection));
127+
activity.AddException(ex, in tags);
138128
}
139129
}

0 commit comments

Comments
 (0)