| File: Telemetry\DiagnosticActivity.cs | Web Access |
| Project: src\msbuild\src\Framework\Microsoft.Build.Framework.csproj (Microsoft.Build.Framework) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #if !NETFRAMEWORK using System.Collections.Generic; using System.Diagnostics; namespace Microsoft.Build.Framework.Telemetry { /// <summary> /// Wraps a <see cref="Activity"/> and implements <see cref="IActivity"/>. /// </summary> internal class DiagnosticActivity : IActivity { private readonly Activity _activity; private bool _disposed; public DiagnosticActivity(Activity activity) { _activity = activity; } public IActivity SetTags(IActivityTelemetryDataHolder? dataHolder) { Dictionary<string, object>? tags = dataHolder?.GetActivityProperties(); if (tags != null) { foreach (KeyValuePair<string, object> tag in tags) { _ = SetTag(tag.Key, tag.Value); } } return this; } public IActivity SetTag(string key, object? value) { if (value != null) { _ = _activity.SetTag($"{TelemetryConstants.PropertyPrefix}{key}", value); } return this; } public void Dispose() { if (_disposed) { return; } _activity.Dispose(); _disposed = true; } } } #endif