// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Diagnostics; namespace Microsoft.Teams.Core.Diagnostics; /// /// Helpers for setting standardized tags and recording exceptions on instances /// emitted by the Teams SDK's bot pipeline. /// public static class ActivityExtensions { /// /// Records an exception on the span: sets status to and /// adds an exception event with type/message/stacktrace tags. Mirrors the shape that /// uses on .NET 9+ but works on net8.0 as well. /// public static void RecordException(this Activity? activity, Exception exception) { if (activity is null || exception is null) { return; } ActivityTagsCollection tags = new() { { "exception.type", exception.GetType().FullName }, { "exception.message", exception.Message }, { "exception.stacktrace", exception.ToString() }, }; activity.AddEvent(new ActivityEvent("exception", tags: tags)); activity.SetStatus(ActivityStatusCode.Error, exception.Message); } }