Skip to content

Commit

Permalink
[api] Mark ActivityExtensions.RecordException obsolete (#5841)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikel Blanchard <[email protected]>
  • Loading branch information
ysolomchenko and CodeBlanch authored Sep 24, 2024
1 parent 3c38a4b commit 12a8ab0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 9 additions & 19 deletions src/OpenTelemetry.Api/Trace/ActivityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ public static Status GetStatus(this Activity? activity)
/// </summary>
/// <param name="activity">Activity instance.</param>
/// <param name="ex">Exception to be recorded.</param>
/// <remarks> The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
/// <remarks>
/// <para>Note: This method is obsolete. Please use <see cref="Activity.AddException"/> instead.</para>
/// The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
/// </remarks>
[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);
Expand All @@ -107,9 +110,12 @@ public static void RecordException(this Activity? activity, Exception? ex)
/// <param name="activity">Activity instance.</param>
/// <param name="ex">Exception to be recorded.</param>
/// <param name="tags">Additional tags to record on the event.</param>
/// <remarks> The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
/// <remarks>
/// <para>Note: This method is obsolete. Please use <see cref="Activity.AddException"/> instead.</para>
/// The exception is recorded as per <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/exceptions.md">specification</a>.
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
/// </remarks>
[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)
{
Expand All @@ -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);
}
}

0 comments on commit 12a8ab0

Please sign in to comment.