Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] Mark ActivityExtensions.RecordException obsolete #5841

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Notes](../../RELEASENOTES.md).

## Unreleased

* Obsoleted the `ActivityExtensions.RecordException`. Users should migrate to the
`System.Diagnostics.Activity.AddException`
[Activity.AddException](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.addexception)
API for adding exception.
([#5841](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5841))

* **Breaking change:** CompositeTextMapPropagator.Fields now returns a
unioned set of fields from all combined propagators. Previously this always
returned an empty set.
Expand Down
22 changes: 5 additions & 17 deletions src/OpenTelemetry.Api/Trace/ActivityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public static Status GetStatus(this Activity? activity)
/// <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>.
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
/// <para>This method is obsolete. Please use <see cref="Activity.AddException"/> instead. The end result will be the same when using this alternative.</para>
/// </remarks>
[Obsolete("Call Activity.AddException instead this method will be removed in a future version.")]
ysolomchenko marked this conversation as resolved.
Show resolved Hide resolved
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RecordException(this Activity? activity, Exception? ex)
=> RecordException(activity, ex, default);
Expand All @@ -109,7 +111,9 @@ public static void RecordException(this Activity? activity, Exception? ex)
/// <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>.
/// "exception.stacktrace" is represented using the value of <a href="https://learn.microsoft.com/dotnet/api/system.exception.tostring">Exception.ToString</a>.
/// <para>This method is obsolete. Please use <see cref="Activity.AddException"/> instead. The end result will be the same when using this alternative.</para>
/// </remarks>
[Obsolete("Call Activity.AddException instead this method will be removed in a future version.")]
Kielek marked this conversation as resolved.
Show resolved Hide resolved
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RecordException(this Activity? activity, Exception? ex, in TagList tags)
{
Expand All @@ -118,22 +122,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, tags);
}
}
Loading