Skip to content

Commit

Permalink
Update logging around GetWorkItem (#1760)
Browse files Browse the repository at this point in the history
* Update logging around GetWorkItem
* Added exception for no ID
  • Loading branch information
MrHinsh authored Nov 28, 2023
1 parent 6a99c83 commit fe76296
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using MigrationTools._EngineV1.DataContracts;
using MigrationTools.DataContracts;
using Serilog;
using static Microsoft.TeamFoundation.Client.CommandLine.Options;

namespace MigrationTools._EngineV1.Clients
{
Expand Down Expand Up @@ -150,28 +151,36 @@ public override WorkItemData GetWorkItem(string id)

public override WorkItemData GetWorkItem(int id)
{
if (id == 0)
{
throw new ArgumentOutOfRangeException("id", id, "id cant be empty.");
}
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();
WorkItem y;
try
{
Log.Debug("TfsWorkItemMigrationClient::GetWorkItem({id})", id);
y = Store.GetWorkItem(id);
timer.Stop();
Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItem", null, startTime, timer.Elapsed, "200", true));
}
catch (Exception ex)
{
timer.Stop();
Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItem", null, startTime, timer.Elapsed, "500", false));
Telemetry.TrackException(ex,
new Dictionary<string, string> {
{ "CollectionUrl", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString() }
},
new Dictionary<string, double> {
{ "Time",timer.ElapsedMilliseconds }
});
Log.Error(ex, "Unable to configure store");
Log.Error(ex, "Unable to GetWorkItem with id[{id}]", id);
throw;
} finally
{
timer.Stop();
Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItem", null, startTime, timer.Elapsed, "500", false));

}
return y?.AsWorkItemData();
}
Expand Down Expand Up @@ -273,6 +282,7 @@ private WorkItemStore GetWorkItemStore()
WorkItemStore store;
try
{
Log.Debug("TfsWorkItemMigrationClient::GetWorkItemStore({InternalCollection}, {bypassRules})", _config.AsTeamProjectConfig().Collection, _bypassRules);
store = new WorkItemStore((TfsTeamProjectCollection)MigrationClient.InternalCollection, _bypassRules);
timer.Stop();
Telemetry.TrackDependency(new DependencyTelemetry("TfsObjectModel", MigrationClient.Config.AsTeamProjectConfig().Collection.ToString(), "GetWorkItemStore", null, startTime, timer.Elapsed, "200", true));
Expand Down

0 comments on commit fe76296

Please sign in to comment.