diff --git a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsMigrationClient.cs b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsMigrationClient.cs index 24efc558e..91afb77c1 100644 --- a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsMigrationClient.cs +++ b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsMigrationClient.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Net; using Microsoft.ApplicationInsights.DataContracts; +using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; @@ -155,6 +156,13 @@ private TfsTeamProjectCollection GetDependantTfsCollection(NetworkCredential cre Log.Information("Access granted to {CollectionUrl} for {Name} ({Account})", TfsConfig.Collection, y.AuthorizedIdentity.DisplayName, y.AuthorizedIdentity.UniqueName); _Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", TfsConfig.Collection.ToString(), "GetWorkItem", null, startTime, timer.Elapsed, "200", true)); } + catch (TeamFoundationServerUnauthorizedException ex) + { + timer.Stop(); + _Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", TfsConfig.Collection.ToString(), "GetWorkItem", null, startTime, timer.Elapsed, "401", false)); + Log.Error(ex, "Unable to configure store: Check persmissions and credentials for {AuthenticationMode}!", _config.AuthenticationMode); + Environment.Exit(-1); + } catch (Exception ex) { timer.Stop(); diff --git a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemMigrationClient.cs b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemMigrationClient.cs index 8c84a40aa..64201db69 100644 --- a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemMigrationClient.cs +++ b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemMigrationClient.cs @@ -155,7 +155,7 @@ public override WorkItemData GetWorkItem(int id) } var startTime = DateTime.UtcNow; var timer = System.Diagnostics.Stopwatch.StartNew(); - WorkItem y; + WorkItem y = null ; try { Log.Debug("TfsWorkItemMigrationClient::GetWorkItem({id})", id); @@ -167,13 +167,15 @@ public override WorkItemData GetWorkItem(int id) { Telemetry.TrackException(ex, new Dictionary { - { "CollectionUrl", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString() } + { "CollectionUrl", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString() }, + { "Project", MigrationClient.Config.AsTeamProjectConfig().Project.ToString() }, + { "WorkItem", id.ToString() } }, new Dictionary { { "Time",timer.ElapsedMilliseconds } }); Log.Error(ex, "Unable to GetWorkItem with id[{id}]", id); - throw; + Environment.Exit(-1); } finally { timer.Stop(); diff --git a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemQuery.cs b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemQuery.cs index cd4188993..6e82f5ef2 100644 --- a/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemQuery.cs +++ b/src/MigrationTools.Clients.AzureDevops.ObjectModel/_Enginev1/Clients/TfsWorkItemQuery.cs @@ -82,6 +82,13 @@ private IList GetWorkItemsFromQuery(TfsWorkItemMigrationClient wiClien timer.Stop(); Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItemsFromQuery", null, startTime, timer.Elapsed, "200", true)); } + catch (ValidationException ex) + { + timer.Stop(); + Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItemsFromQuery", null, startTime, timer.Elapsed, "500", false)); + Log.Error(ex, " Error running query"); + Environment.Exit(-1); + } catch (Exception ex) { timer.Stop(); diff --git a/src/MigrationTools/Services/TelemetryClientAdapter.cs b/src/MigrationTools/Services/TelemetryClientAdapter.cs index 6c78ad784..e714660aa 100644 --- a/src/MigrationTools/Services/TelemetryClientAdapter.cs +++ b/src/MigrationTools/Services/TelemetryClientAdapter.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; using System.Security.Principal; +using System.Text.RegularExpressions; using Elmah.Io.Client; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; @@ -19,7 +22,7 @@ public TelemetryClientAdapter(TelemetryClient telemetryClient) telemetryClient.Context.Device.OperatingSystem = Environment.OSVersion.ToString(); if (!(System.Reflection.Assembly.GetEntryAssembly() is null)) { - telemetryClient.Context.Component.Version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString(); + telemetryClient.Context.Component.Version = GetRunningVersion().versionString; } _telemetryClient = telemetryClient; @@ -28,7 +31,7 @@ public TelemetryClientAdapter(TelemetryClient telemetryClient) Timeout = TimeSpan.FromSeconds(30), UserAgent = "Azure-DevOps-Migration-Tools", }); - elmahIoClient.Messages.OnMessage += (sender, args) => args.Message.Version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString(); + elmahIoClient.Messages.OnMessage += (sender, args) => args.Message.Version = GetRunningVersion().versionString; } @@ -84,18 +87,27 @@ public void TrackException(Exception ex, IDictionary properties, Application = "Azure-DevOps-Migration-Tools", ServerVariables = new List { - new Item("User-Agent", $"X-ELMAHIO-APPLICATION; OS={Environment.OSVersion.Platform}; OSVERSION={Environment.OSVersion.Version}; ENGINE=Azure-DevOps-Migration-Tools"), + new Item("User-Agent", $"X-ELMAHIO-APPLICATION; OS={Environment.OSVersion.Platform}; OSVERSION={Environment.OSVersion.Version}; ENGINEVERSION={GetRunningVersion().versionString}; ENGINE=Azure-DevOps-Migration-Tools"), } }; - foreach (var property in properties) + createMessage.Data.Add(new Item("SessionId", SessionId)); + createMessage.Data.Add(new Item("Version", GetRunningVersion().versionString)); + + if (properties != null) { - createMessage.Data.Add(new Item(property.Key, property.Value)); + foreach (var property in properties) + { + createMessage.Data.Add(new Item(property.Key, property.Value)); + } + } - foreach (var measurement in measurements) + if (measurements != null) { - createMessage.Data.Add(new Item(measurement.Key, measurement.Value.ToString())); + foreach (var measurement in measurements) + { + createMessage.Data.Add(new Item(measurement.Key, measurement.Value.ToString())); + } } - var result = elmahIoClient.Messages.CreateAndNotify(new Guid("24086b6d-4f58-47f4-8ac7-68d8bc05ca9e"), createMessage); Console.WriteLine($"Error logged to Elmah.io"); } @@ -104,5 +116,14 @@ public void TrackRequest(string name, DateTimeOffset startTime, TimeSpan duratio { _telemetryClient.TrackRequest(name, startTime, duration, responseCode, success); } + + public static (Version version, string PreReleaseLabel, string versionString) GetRunningVersion() + { + FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()?.Location); + var matches = Regex.Matches(myFileVersionInfo.ProductVersion, @"^(?0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?0|[1-9]\d*)(?:-((?